def handle_state_change(context, event): """ Handle a release being modified """ visible = _release_visible(context) # getting the folder util = _get_mirror_config() if util is None or util.path is None: # not installed or not configured return None root = util.path if not os.path.exists(root): raise IOError('%s does not exists' % root) if not os.path.isdir(root): raise IOError('%s should be a directory' % root) index = join(root, util.index) files = [(os.path.realpath(os.path.join(root, id_)), ob) for id_, ob in context.objectItems()] if visible: # need to show the files for path, file in files: _write_file(file, path, index) else: # need to remove them for path, file in files: if os.path.exists(path): try: remove_file(path) except AlreadyLocked: raise ConflictError('%s is locked' % path)
def handle_file_removed(context, event): """removes file only if release is published handle_state_change takes care of removing file when a release change of state. """ release = context.getParentNode() if not _release_visible(release): return util = _get_mirror_config() if util is None or util.path is None: # not installed or not configured return root = util.path filepath = os.path.join(root, context.getId()) try: remove_file(filepath) except AlreadyLocked: raise ConflictError('%s is locked' % filepath) except OSError: # might be gone somehow # XXX need logging here pass
def test_deletion(self): def my(f): f.write('wwww') locker.with_lock(self.my_file, 'w', my, self.index) content = open(self.index).read().split('#') self.assertEquals(content[-1].strip(), 'e34a8899ef6468b74f8a1048419ccc8b') # let's remove a file locker.remove_file(self.my_file, self.index) # should be gone assert not os.path.exists(self.my_file) # should be gone from index content = open(self.index).read() self.assertEquals(content, '')