def test_file(): p = '/tmp/scruffy_test_file' f = File(p) safe_unlink(p) assert not os.path.exists(p) f.create() assert os.path.exists(p)
def test_prepare_cleanup(): p = '/tmp/scruffy_test_file' f = File(p, create=True, cleanup=True) safe_unlink(p) assert not os.path.exists(p) f.prepare() assert os.path.exists(p) f.cleanup() assert not os.path.exists(p)
def snapshot(self): self.wd.remove() self.wd.create() manifest = {} for filepath in idiot.config.watch_files: f = File(filepath) try: newf = self.wd.add(File(uuid.uuid4().hex)) newf.write(f.content) manifest[filepath] = newf.name except: log.exception("Exception copying file for snapshot") self.wd.write('manifest', yaml.dump(manifest))
def setup_env(): global env, config env = Environment(setup_logging=False, voltron_dir=Directory('~/.voltron', create=True, config=ConfigFile('config', defaults=File('config/default.cfg', parent=PackageDirectory())), sock=File('sock'), history=File('history'), user_plugins=PluginDirectory('plugins') ), pkg_plugins=PluginDirectory('plugins', parent=PackageDirectory()) ) config = env.config # create shared instance of plugin manager voltron.plugin.pm = voltron.plugin.PluginManager()
def test_lock_file(): p = '/tmp/scruffy_test_file' safe_unlink(p) assert not os.path.exists(p) with LockFile(p): assert os.path.exists(p) assert not os.path.exists(p) f = File(p) f.create() try: with LockFile(p): assert False except: assert True f.remove() assert not os.path.exists(p)
def setup_env(): global env, config env = Environment(setup_logging=False, voltron_dir=Directory( '~/.voltron', create=True, config=ConfigFile('config', defaults=File( 'config/default.cfg', parent=PackageDirectory()), apply_env=True), sock=File('{config:server.listen.domain}'), history=File('history'), user_plugins=PluginDirectory('plugins')), pkg_plugins=PluginDirectory('plugins', parent=PackageDirectory())) config = env.config voltron.plugin.pm.register_plugins()
def run(self): try: manifest = yaml.safe_load(self.wd.read('manifest')) except: log.error("No snapshot found") return (False, "no snapshot found") fails = [] for filepath in manifest: f = File(filepath) s = File(manifest[filepath], parent=self.wd) diff = list( difflib.unified_diff(f.content.splitlines(), s.content.splitlines())) if len(diff): fails.append(filepath) log.info("Check for {} failed with diff:") log.info("\n".join(diff)) if len(fails): return (False, "the following files have changed: {}".format( ', '.join(fails))) else: return (True, "no files have changed")