def lock_for(self, name): check_name(name) name, version = split_name(name) path = self.dir + name dir = os.path.dirname(path) mkdir(dir) return self.FcntlLock(path)
def __init__(self, dir): self.dir = dir mkdir(dir) # All mkdirs, opens, rmdirs and unlinks must be guarded by this lock self.tree_lock_fd = os.open(os.path.join(dir, 'tree.lock'), os.O_WRONLY | os.O_CREAT, 0o600)
def __init__(self, manager, filename): self.manager = manager self.filename = filename dir = os.path.dirname(filename) fcntl.flock(manager.tree_lock_fd, fcntl.LOCK_EX) try: mkdir(dir) self.fd = os.open(filename, os.O_WRONLY | os.O_CREAT, 0o600) finally: fcntl.flock(manager.tree_lock_fd, fcntl.LOCK_UN) # Set mtime so that any future cleanup script may remove lock files # not used for some specified time. os.utime(filename, None)
def db_init(db_dir): logger.info('Attempting to create and/or initialize database.') mkdir(db_dir) db_env = bsddb3.db.DBEnv() db_env.open( db_dir, bsddb3.db.DB_CREATE | bsddb3.db.DB_INIT_LOCK | bsddb3.db.DB_INIT_LOG | bsddb3.db.DB_INIT_MPOOL | bsddb3.db.DB_INIT_TXN | bsddb3.db.DB_REGISTER | bsddb3.db.DB_RECOVER) db_env.close() logger.info('Successfully created and/or initialized database.')
def get_file(self, name, filename): """Saves the content of file named ``name`` to ``filename``. Works like :meth:`get_stream`, but ``filename`` is the name of a file which will be created (or overwritten). Returns the full versioned name of the retrieved file. """ stream, vname = self.get_stream(name) path, version = split_name(vname) dir_path = os.path.dirname(filename) if dir_path: mkdir(dir_path) with open(filename, 'wb') as f: shutil.copyfileobj(stream, f) return vname
def _save_stream(path, stream, version=None): dir = os.path.dirname(path) if dir: mkdir(dir) if os.path.exists(path) and version is not None \ and _file_version(path) >= version: return version if hasattr(stream, 'name') and os.path.exists(stream.name): try: if not os.path.samefile(stream.name, path): if os.path.exists(path): os.unlink(path) os.link(stream.name, path) return _file_version(path) except OSError: pass dest = open(path, 'wb') shutil.copyfileobj(stream, dest) dest.close() if version is not None: os.utime(path, (version, version)) return _file_version(path)
def __init__(self, dir): self.dir = os.path.join(dir, 'files') mkdir(self.dir)
def __init__(self, dir): self.dir = dir mkdir(dir)