def touch_file(filename): """ Like mkdir -p && touch """ sysutils.mkdirp_writable(os.path.dirname(filename)) if not os.path.exists(filename): open(filename, 'a').close()
def save(self, newdata=None): " Write the contents of the data cache to the file. " if newdata is not None: assert isinstance(newdata, dict) self.data = newdata fpath = os.path.split(self._filename)[0] if len(fpath): sysutils.mkdirp_writable(fpath) open(self._filename, 'w').write(yaml.dump(self.data, default_flow_style=False))
def save(self, newdata=None): " Write the contents of the data cache to the file. " if newdata is not None: assert isinstance(newdata, dict) self.data = newdata fpath = os.path.split(self._filename)[0] if len(fpath): sysutils.mkdirp_writable(fpath) with open(self._filename, 'w') as fn: self.yaml.dump(self.data, fn)