def main(): copier = Copier() keyboard = Keyboard() scanner = Scanner() printer = Printer() database = Database() copier.copy(scanner, database)
def main(): utils.print_header("MUSIC BACKUP PROGRAM") configs = Configs.from_json("config.json") analyzer = Analyzer(configs) dst_files = analyzer.get_backup_files() src_files = analyzer.get_source_files() analyzer.compare_directories() summary = "" if analyzer.files_to_backup > 0 and configs.backup_enabled: utils.print_header("COPYING TO BACKUP") print("Starting copying process...\n") copier = Copier(configs.source_path, configs.backup_path, src_files, dst_files, analyzer.files_to_backup) backed_up_count = copier.copy() summary += "Backed up a total of {} files!".format(backed_up_count) if analyzer.files_to_backcopy > 0 and configs.backcopy_enabled: utils.print_header("COPYING TO LOCAL") print("Starting copying process...") copier = Copier(configs.backup_path, configs.backcopy_path, dst_files, src_files, analyzer.files_to_backcopy) backcopied_count = copier.copy() summary += "Copied a total of {} files to your local!".format( backcopied_count) if summary and (configs.backcopy_enabled or configs.backup_enabled): utils.print_header("SUMMARY") print(summary) print("\nComplete!") return
def copy_origin(self, origins, destination, link = False): copier = Copier(link=link) for origin in origins: self._logger.info( "Copying media from '%s' to '%s'" % (origin, destination) ) try: components = origin.split(':') mod, directory = components[:2] except ValueError: raise zc.buildout.UserError( "Error in '%s': media_origin must be in the form " "'custom.module:directory'" % self.name ) try: __, ws = self.rws mod = dotted_import(mod, [d.location for d in ws]) except ImportError: raise zc.buildout.UserError( "Error in '%s': media_origin is '%s' " "but we cannot find module '%s'" % (self.name, origin, mod) ) orig_directory = os.path.join( os.path.dirname(mod.__file__), directory ) if not os.path.isdir(orig_directory): raise zc.buildout.UserError( "Error in '%s': media_origin is '%s' " "but '%s' does not seem to be a directory" % ( self.name, origin, directory ) ) if len(components) > 2: target = os.path.join(destination, components[2]) else: target = destination copier.copy(orig_directory, target) try: copier.execute() except OSError, e: raise zc.buildout.UserError( "Failed to copy %s into '%s': %s" % ( ', '.join([ "'%s'" % o for o in origins ]), destination, e ) )
def main(): copier = Copier() keyboard = Keyboard() # scanner = Scanner() copier.copy(keyboard)
class BaseManager: def __init__(self, filesystem, logger=None): self.filesystem = cache_directory(read_only(filesystem)) self.filesystem.desc('/') self.caps_list = {} self.results = [] self.logger = logger self.copier = Copier() def close(self): self.copier.stop() self.filesystem.close() def list_dir(self, top): return [i.name for i in self.filesystem.scandir(top) if i.is_dir] def download(self, src_pth, src_file, dest_pth, dest_file): ff = OSFS(dest_pth) self.copier.copy(self.filesystem, join(src_pth, src_file), ff, join('/', dest_file)) def find_nexts(self, top='/', deep=0, maxdeep=2): if deep == 0: self.results = [] # print(top) if deep > maxdeep: return # if self.logger: # self.logger.emit(top, INFORMATION) dirs, nondirs = [], [] for name in self.filesystem.scandir(top): if name.is_dir: dirs.append(name) elif splitext(name.name)[1].lower() in video_formats: nondirs.append(name) # print(dirs,nondirs) for fil in nondirs: pp = rename(fil.name) if pp.error: pp = parse(j.name) t1 = '' t2 = 0 try: if pp.is_video: if pp.episode: t1 = transform(pp.title) fill = t1 if pp.season: fill += ' - ' + str(pp.season) + \ 'x' + str(pp.episode) else: fill += ' - ' + str(pp.episode) fill += pp.ext else: continue t2 = pp.episode else: continue except KeyError: if self.logger: self.logger.emit("Error procesando: " + fil.name, WARNING) continue bedd = 100 gap = 2 near = '' for j in self.caps_list.keys(): edd = editDistance(t1, j, True) if edd <= gap and edd < bedd: near = j bedd = edd if edd == 0: break if near != '': if isinstance(t2, str): if 'x' in t2: t2 = t2.split('x')[1] if int(t2) > self.caps_list[near]: best = (near, fil.name, top, fill) self.results.append(best) if self.logger: self.logger.emit('Encontrado: ' + str(best), INFORMATION) for name in sorted(dirs, key=skey): path = join(top, name.name) if not self.filesystem.islink(path): try: self.find_nexts(path, deep + 1, maxdeep) except (PermissionError, fs.errors.DirectoryExpected) as e: # print(e) self.logger.emit(str(e), ERROR) def last(self, base): with read_only(OSFS(base)) as ff: proces = [] folds = [] for i in ff.scandir('/'): if i.is_dir: folds.append(i) for i in folds: path = join('/', i.name) try: for j in ff.scandir(path): if j.is_file and splitext( j.name)[1].lower() in video_formats: proces.append((j, i)) except (PermissionError, DirectoryExpected) as e: self.logger.emit("Acceso denegado a" + join(base, i.name), ERROR) folds = {} for filee, fold in proces: fold = fold.name filee = filee.name try: pp = parse2(filee) if pp.error: pp = parse(filee) except Exception as e: self.logger.emit( "Error procesando: " + join(base, fold, filee), WARNING) self.logger.emit(str(e), ERROR) continue t1 = transform(pp.title) if not pp.episode: continue t2 = pp.episode if t1 in folds: if folds[t1] < int(t2): folds[t1] = int(t2) else: tt = best_ed(t1, folds.keys()) if tt in folds: if folds[tt] < int(t2): folds[tt] = int(t2) folds[tt] = int(t2) self.caps_list = folds def find_nexts2(self, top='/', deep=0, maxdeep=2): if deep == 0: self.results = [] # print(top) if deep > maxdeep: return # if self.logger: # self.logger.emit(top, INFORMATION) dirs, nondirs = [], [] for name in self.filesystem.scandir(top): if name.is_dir: dirs.append(name) elif splitext(name.name)[1].lower() in video_formats: nondirs.append(name) # print(dirs,nondirs) for fil in nondirs: pp = parse2(fil.name) if pp.error: pp = parse(fil.name) t1 = '' t2 = 0 try: if pp.is_video: if pp.episode: t1 = transform(pp.title) fill = t1 if pp.season: fill += ' - ' + str(pp.season) + \ 'x' + str(pp.episode) else: fill += ' - ' + str(pp.episode) fill += pp.ext else: continue t2 = pp.episode else: continue except KeyError: if self.logger: self.logger.emit("Error procesando: " + fil.name, WARNING) continue bedd = 100 gap = 2 near = '' for j in self.caps_list.keys(): edd = editDistance(t1, j, True) if edd <= gap and edd < bedd: near = j bedd = edd if edd == 0: break if near != '': if isinstance(t2, str): if 'x' in t2: t2 = t2.split('x')[1] if not (int(t2) in self.caps_list[near]): best = (near, fil.name, top, fill) self.results.append(best) if self.logger: self.logger.emit('Encontrado: ' + str(best), INFORMATION) for name in sorted(dirs, key=skey): path = join(top, name.name) if not self.filesystem.islink(path): self.find_nexts2(path, deep + 1, maxdeep) def last2(self, base): with read_only(OSFS(base)) as ff: proces = [] folds = [] for i in ff.scandir('/'): if i.is_dir: folds.append(i) for i in folds: path = join('/', i.name) try: for j in ff.scandir(path): if j.is_file and splitext( j.name)[1].lower() in video_formats: proces.append((j, i)) except (PermissionError, DirectoryExpected) as e: self.logger.emit("Acceso denegado a" + join(base, i.name), ERROR) folds = {} for filee, fold in proces: fold = fold.name filee = filee.name try: pp = parse2(filee) if pp.error: pp = parse(filee) except Exception as e: self.logger.emit( "Error procesando: " + join(base, fold, filee), WARNING) self.logger.emit(str(e), ERROR) continue t1 = transform(pp.title) if not pp.episode: continue t2 = pp.episode if t1 in folds: folds[t1].add(int(t2)) else: tt = best_ed(t1, folds.keys()) if tt in folds: folds[t1].add(int(t2)) else: folds[t1] = set() folds[t1].add(int(t2)) self.caps_list = folds def __enter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): self.filesystem.close() self.copier.stop() return False
def main(): copier = Copier() copier.copy()