MCPcopy Index your code
hub / github.com/saltstack/salt / update_pyfile

Method update_pyfile

tests/unit/test_loader.py:1067–1080  ·  view source on GitHub ↗
(self, pyfile, contents)

Source from the content-addressed store, hash-verified

1065 del cls.proxy
1066
1067 def update_pyfile(self, pyfile, contents):
1068 dirname = os.path.dirname(pyfile)
1069 if not os.path.exists(dirname):
1070 os.makedirs(dirname)
1071 with salt.utils.files.fopen(pyfile, "wb") as fh:
1072 fh.write(salt.utils.stringutils.to_bytes(contents))
1073 fh.flush()
1074 os.fsync(fh.fileno()) # flush to disk
1075
1076 # pyc files don't like it when we change the original quickly
1077 # since the header bytes only contain the timestamp (granularity of seconds)
1078 # TODO: don't write them? Is *much* slower on re-load (~3x)
1079 # https://docs.python.org/2/library/sys.html#sys.dont_write_bytecode
1080 remove_bytecode(pyfile)
1081
1082 def rm_pyfile(self, pyfile):
1083 os.unlink(pyfile)

Callers 1

update_moduleMethod · 0.95

Calls 5

remove_bytecodeFunction · 0.85
existsMethod · 0.45
writeMethod · 0.45
flushMethod · 0.45
filenoMethod · 0.45

Tested by

no test coverage detected