Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
print "Unable to create a html output folder at " + config[group]['html_dir'] + ". Check permissions or create it first.."
sys.exit(0)
if not os.path.exists(config[group]['db_dir']) or not os.path.isdir(config[group]['db_dir']):
if args.verbose: print ">>> Creating database file directory " + config[group]['db_dir']
try:
os.makedirs(config[group]['db_dir'])
except:
print "Unable to create a database folder at " + config[group]['db_dir'] + ". Check permissions or create it first.."
exit(0)
# SETUP THE DATABASE ENVIRONMENT, OPEN THREADED DATABASE FOR ASYNCHRONOUS READ/WRITES
db_path = os.path.join(os.getcwd(),config[group]['db_dir'],config[group]['db_file'])
html_path = os.path.join(config[group]['html_dir'],'index.html')
dbenv = db.DBEnv()
dbenv.open(config[group]['db_dir'], db.DB_INIT_LOCK | db.DB_INIT_MPOOL | db.DB_CREATE | db.DB_THREAD , 0)
stalkerdb = db.DB(dbenv)
if args.verbose: print ">>> Opening database file " + db_path
db_handle = stalkerdb.open(db_path, None, db.DB_HASH, db.DB_CREATE | db.DB_THREAD )
if db_handle == None:
if args.verbose: print ">>> Database open successful..."
else:
print "Database open failed. (" + str(db_handle) + ") Exiting.."
exit()
thread_count = 0
processed_urls = []
# PROCESS INPUT FILE
if args.infile:
if group == args.group_name:
def open_db(filename, db_dir='', filetype=db.DB_BTREE, writeback=False):
global home_dir
if not db_dir:
db_dir = home_dir
dir = setDBPath(db_dir)
path = os.path.join(dir, filename)
env = db.DBEnv()
# Concurrent Data Store
env.open(dir, db.DB_THREAD|db.DB_INIT_CDB|db.DB_INIT_MPOOL|db.DB_CREATE|db.DB_PRIVATE)
#d = db.DB(env)
#d.open(path, filetype, db.DB_THREAD|db.DB_CREATE)
#_db = BsdDbShelf(d, writeback=writeback)
_db = dbshelve.open(filename, flags=db.DB_THREAD|db.DB_CREATE,
filetype=filetype, dbenv=env)
return _db, dir
def create(dbname, primary_namespace, secondary_namespaces,
formatname = "unknown"):
os.mkdir(dbname)
config_filename = os.path.join(dbname, "config.dat")
BaseDB.write_config(config_filename = config_filename,
index_type = INDEX_TYPE,
primary_namespace = primary_namespace,
secondary_namespaces = secondary_namespaces,
fileid_info = {},
formatname = formatname
)
dbenv = db.DBEnv(0)
envflags = db.DB_THREAD | db.DB_INIT_MPOOL
dbenv.open(dbname, envflags | db.DB_CREATE)
primary_table = db.DB(dbenv)
primary_table.open("key_%s" % (primary_namespace,), None,
db.DB_BTREE, db.DB_CREATE, 0660)
secondary_tables = {}
for namespace in secondary_namespaces:
x = db.DB(dbenv)
x.open("id_%s" % (namespace,), None, db.DB_BTREE, db.DB_CREATE, 0)
secondary_tables[namespace] = x
for x in secondary_tables.values():
x.close()
primary_table.close()
dbenv.close()
os.mkdir(path, 02775)
except OSError, e:
if e.errno <> errno.EEXIST: raise
exists = True
# Create the environment
self._env = env = db.DBEnv()
if exists:
# We must join an existing environment, otherwise we'll get
# DB_RUNRECOVERY errors when the second process to open the
# environment begins a transaction. I don't get it.
env.open(path, db.DB_JOINENV)
else:
env.open(path,
db.DB_CREATE |
db.DB_RECOVER |
db.DB_INIT_MPOOL |
db.DB_INIT_TXN
)
self._txn = None
self._tables = []
self._metainfo = self._setupDB('metainfo')
self._members = self._setupDB('members')
self._status = self._setupDB('status')
self._topics = self._setupDB('topics')
self._bounceinfo = self._setupDB('bounceinfo')
# Check the database version number
version = self._metainfo.get('version')
if version is None:
# Initialize
try:
self.txn_begin()
self._metainfo.put('version', STORAGE_VERSION, txn=self._txn)