def check_md5(pkg_md5, src_file): """ MD5 Checksum """ if _meta_.checkmd5 in ["on", "ON"]: print("") md5s = md5(src_file) if pkg_md5 != md5s: Msg().template(78) print("| MD5SUM check for {0} [ {1}FAILED{2} ]".format( src_file.split("/")[-1], _meta_.color["RED"], _meta_.color["ENDC"])) Msg().template(78) print("| Expected: {0}".format(md5s)) print("| Found: {0}".format(pkg_md5)) Msg().template(78) print("") if not Msg().answer() in ["y", "Y"]: sys.exit(0) else: Msg().template(78) print("| MD5SUM check for {0} [ {1}PASSED{2} ]".format( src_file.split("/")[-1], _meta_.color["GREEN"], _meta_.color["ENDC"])) Msg().template(78) print("") # new line after pass checksum
def createMD5SUM(): x = md5sum.grab_files('.') lista = [] for i in x: y = md5sum.md5(i[1]) lista.append((i[0],y)) md5sum.createFile(lista)
def createMD5SUM(self): """ Create md5sum.txt from file path """ x = md5sum.grab_files(FILE_PATH) lista = [] for i in x: y = md5sum.md5(i) lista.append((i,y)) md5sum.createFile(lista)
def write_files_to_db(arg, dirname, names): cursor = connection.cursor() absolute_path = os.path.abspath(dirname) for i in range(0, len(names)): name = names[i] path_and_filename = "%s/%s" % (absolute_path, name) if os.path.isdir(path_and_filename) == False: stat = os.stat(path_and_filename) md5sum_str = md5sum.md5(path_and_filename) # get EXIF datetime, if available f = open(path_and_filename, "rb") try: tags = EXIF.process_file(f) # get all tags anyway finally: f.close() exif_date = "" if "EXIF DateTimeOriginal" in tags.keys(): exif_date_tag = tags["EXIF DateTimeOriginal"] exif_date = str(exif_date_tag) print "[%d/%d] %s %s" % (i + 1, len(names), path_and_filename, exif_date) sql = " INSERT INTO file (directory, filename, md5, atime, mtime, ctime, exif_date) VALUES (?, ?, ?, ?, ?, ?, ?) " cursor.execute(sql, [absolute_path, name, md5sum_str, stat.st_atime, stat.st_mtime, stat.st_ctime, exif_date]) if (i % 100) == 0: print "commit" connection.commit() connection.commit() cursor.close()
def _create_items(dir_name, variant_name, user, workspace, make_copy=True, recursive = True, force_generation = False, link = False): """ """ logger.debug('########## _create_items') def copy_file(original_filename, final_path, link, make_copy): logger.debug('original_filename %s'%original_filename) logger.debug('final_path %s'%final_path) if link: logger.debug('link') #os.symlink(original_filename, final_path) if os.path.exists(final_path): os.remove(final_path) os.link(original_filename, final_path) elif make_copy: shutil.copyfile(original_filename, final_path) else: shutil.move(original_filename, final_path) variant = Variant.objects.get(name = variant_name) for entry in os.walk(dir_name): root_dir, sub_dirs, files = entry files = [os.path.join(root_dir, x) for x in files] for original_filename in files: res_id = new_id() try: media_type = Type.objects.get_or_create_by_filename(original_filename) except MimeError, ex: logger.error(ex) continue final_filename = get_storage_file_name(res_id, workspace.pk, variant.name, media_type.ext) final_path = os.path.join(settings.MEDIADART_STORAGE, final_filename) upload_filename = os.path.basename(original_filename) tmp = upload_filename.split('_') item, created = _create_item(user, workspace, res_id, media_type, original_filename) logger.debug('created %s'%created) logger.debug('+++++++++++++ force_generation %s'%force_generation) if created: logger.debug('file created') if len(tmp) > 1: upload_filename = '_'.join(tmp[1:]) _create_variant(upload_filename, final_filename, media_type, item, workspace, variant) logger.debug('yielding item %s'%item) copy_file(original_filename, final_path, link, make_copy) yield item elif force_generation: logger.debug('force_generation') component = variant.get_component(workspace, item) dam_hash = md5(component.get_file_path()) dir_hash = md5(original_filename) #if force_generation or dir_hash != dam_hash: logger.debug('component.get_file_path() %s'%component.get_file_path()) logger.debug('original_filename %s'%original_filename) logger.debug('dir_hash != dam_hash %s'%(dir_hash != dam_hash)) if dir_hash != dam_hash: copy_file(original_filename, component.get_file_path(), link, make_copy) yield item if not recursive: break
def _create_items(dir_name, variant_name, user, workspace, make_copy=True, recursive = True, force_generation = False, link = False): """ """ logger.debug('########## _create_items') def copy_file(original_filename, final_path, link, make_copy): logger.debug('original_filename %s'%original_filename) logger.debug('final_path %s'%final_path) if link: logger.debug('link') #os.symlink(original_filename, final_path) if os.path.exists(final_path): os.remove(final_path) os.link(original_filename, final_path) elif make_copy: shutil.copyfile(original_filename, final_path) else: shutil.move(original_filename, final_path) variant = Variant.objects.get(name = variant_name) for entry in os.walk(dir_name): root_dir, sub_dirs, files = entry files = [os.path.join(root_dir, x) for x in files] for original_filename in files: res_id = new_id() try: media_type = Type.objects.get_or_create_by_filename(original_filename) except MimeError, ex: logger.error(ex) continue final_filename = get_storage_file_name(res_id, workspace.pk, variant.name, media_type.ext) final_path = os.path.join(settings.MPROCESSOR_STORAGE, final_filename) upload_filename = os.path.basename(original_filename) tmp = upload_filename.split('_') item, created = _create_item(user, workspace, res_id, media_type, original_filename) logger.debug('created %s'%created) logger.debug('+++++++++++++ force_generation %s'%force_generation) if created: logger.debug('file created') if len(tmp) > 1: upload_filename = '_'.join(tmp[1:]) _create_variant(upload_filename, final_filename, media_type, item, workspace, variant) logger.debug('yielding item %s'%item) copy_file(original_filename, final_path, link, make_copy) yield item elif force_generation: logger.debug('force_generation') component = variant.get_component(workspace, item) dam_hash = md5(component.get_file_path()) dir_hash = md5(original_filename) #if force_generation or dir_hash != dam_hash: logger.debug('component.get_file_path() %s'%component.get_file_path()) logger.debug('original_filename %s'%original_filename) logger.debug('dir_hash != dam_hash %s'%(dir_hash != dam_hash)) if dir_hash != dam_hash: copy_file(original_filename, component.get_file_path(), link, make_copy) yield item if not recursive: break