def testSize_MB(self): sizes_results = {'toy': (0.034979820251464844, 'MB'), 'ferns': (0.039520263671875, 'MB') } for k, fn in self.data.iteritems(): print k size = FilenameHelper.size(fn, "MB") print size self.assertEquals(sizes_results[k], size)
def testSize(self): sizes_results = {'toy': (35.8193359375, 'KB'), 'ferns': (40.46875, 'KB') } for k, fn in self.data.iteritems(): print k size = FilenameHelper.size(fn) print size self.assertEquals(sizes_results[k], size)
def testMd5Checksum(self): md5_results = {'toy': "e91112138e590ea070ed3b22e2e62bdc", 'ferns': "d5ce1efd5e2c36715121341403190a8a" } for k, v in self.data.iteritems(): print k md5 = FilenameHelper.md5Checksum(v) print "%s %s" % (v, md5) self.assertEquals(md5_results[k], md5)
def backupFile(fn, outputPath = None, overwrite = False): new_fn = FilenameHelper.addDateToFilename(fn) if outputPath: today= datetime.datetime.now().strftime('%Y-%m-%d') npath = os.path.join(outputPath, today ) if not os.path.exists(npath): os.makedirs(npath) filename = os.path.split(fn)[1] new_fn = os.path.join(npath, filename) if os.path.exists(new_fn) and not overwrite: raise IOError("File %s already exists function is set to not overwrite" % new_fn) elif os.path.exists(new_fn) and overwrite: new_fn = FilenameHelper.addDateToFilename(new_fn) shutil.copy2(fn, new_fn) if not os.path.exists(new_fn): raise IOError("Could not copy file %s to %s" %( fn, new_fn)) return new_fn
def loadYamlConfig(src_filename, config_filename = None): cfg_filename = None if config_filename: path = os.path.split(src_filename)[0] cfg_filename = os.path.join(path, config_filename) else: cfg_filename = FilenameHelper.changeExtension(src_filename, ".yml") cfg_file = open(cfg_filename, 'r') cfg = yaml.load(cfg_file) cfg_file.close() return cfg
try: print "\rString decode %10s : %s" %(enc, name_unicode.decode(enc)) except: print "\rCannot decode string for %s " % (enc) print "=" *50 word = 'Piráña' letters = list(word) for let in letters: msg = let + " : " for x in let: msg += str(hex(ord(x))) print msg print '-'*60 fn =r'C:\Temp\python\iptcconvert\output\1996-DesignaciónAdministradorPCC.jpg' exists = os.path.exists(fn) print "%s [%d] %s" % (fn, len(fn), exists) print '-'*60 fn = ur'C:\Temp\python\iptcconvert\output\1996-DesignaciónAdministradorPCC.jpg' exists = os.path.exists(fn) print "%s [%d] %s" % (fn, len(fn), exists) nfn = FilenameHelper.addDateToFilename(fn) copy2(fn, nfn) exists = os.path.exists(nfn) print "%s [%d] %s" % (nfn, len(nfn), exists)