def dumpAuth(iPath, iUsername, iPassword): contentYaml = {base64.encodestring('username'): base64.encodestring(iUsername), base64.encodestring('password'): base64.encodestring(iPassword)} try: with open(iPath, 'wb') as f: yaml.dump(contentYaml, f, default_flow_style = False) except IOError as e: print e
def saveSearchResult(self): try: if not self.cfg: self.cfg = dict() with open(self.pathCfg, 'w') as f: self.cfg.update({self.tag: '{}'.format(self.result)}) yaml.dump(self.cfg, f, default_flow_style=False) except (IOError, YAMLError) as exp: alog.error(exp) return
def isModified(content, file): h = hashlib.sha1() h.update(yaml.dump(content, default_flow_style=False)) shaNew = h.hexdigest() h = hashlib.sha1() h.update(open(file).read()) shaOld = h.hexdigest() if shaNew != shaOld: return True
def dump(content, file = buildFilePath): #todo: compare old & new shas in parsed/build_sha path = os.path.abspath(file) _toRelative(content, path) if isModified(content, path): yaml.dump(content, open(path, 'w'), default_flow_style=False)