def write_script(scriptdir, rev_id, content, encoding='ascii', sourceless=False): old = scriptdir._revision_map[rev_id] path = old.path content = textwrap.dedent(content) if encoding: content = content.encode(encoding) with open(path, 'wb') as fp: fp.write(content) pyc_path = util.pyc_file_from_path(path) if os.access(pyc_path, os.F_OK): os.unlink(pyc_path) script = Script._from_path(scriptdir, path) old = scriptdir._revision_map[script.revision] if old.down_revision != script.down_revision: raise Exception("Can't change down_revision " "on a refresh operation.") scriptdir._revision_map[script.revision] = script script.nextrev = old.nextrev if sourceless: make_sourceless(path)
def test_is_ignored_filename(self): script = ScriptDirectory.from_config(self.cfg) cases = [ '__init__.py', u'__init__.py', u'__init__.pyc', u'__init__.pyx', u'__init__.pyo', ] for case in cases: assert Script._from_filename( script, script.versions, case) is None
def write_script(scriptdir, rev_id, content): old = scriptdir._revision_map[rev_id] path = old.path with open(path, 'w') as fp: fp.write(textwrap.dedent(content)) pyc_path = util.pyc_file_from_path(path) if os.access(pyc_path, os.F_OK): os.unlink(pyc_path) script = Script._from_path(path) old = scriptdir._revision_map[script.revision] if old.down_revision != script.down_revision: raise Exception("Can't change down_revision " "on a refresh operation.") scriptdir._revision_map[script.revision] = script script.nextrev = old.nextrev
def write_script(scriptdir, rev_id, content, encoding="ascii", sourceless=False): old = scriptdir.revision_map.get_revision(rev_id) path = old.path content = textwrap.dedent(content) if encoding: content = content.encode(encoding) with open(path, "wb") as fp: fp.write(content) pyc_path = util.pyc_file_from_path(path) if os.access(pyc_path, os.F_OK): os.unlink(pyc_path) script = Script._from_path(scriptdir, path) old = scriptdir.revision_map.get_revision(script.revision) if old.down_revision != script.down_revision: raise Exception("Can't change down_revision " "on a refresh operation.") scriptdir.revision_map.add_revision(script, _replace=True) if sourceless: make_sourceless(path)