def Trash(filename,called): cfg = Config() logger = logging.getLogger('Media_Manager.builtin') tmp_path,tmp_filename = os.path.split(filename); watched_dirs = cfg.read_config('Watch_dirs'); try: trash_dir = cfg.get_config_value('Trash','trash_dir') except: logger.error("Trash Dir not set please check config"); return(); for all in watched_dirs: # Resolve Items Dir Structure if it has one if tmp_path[:len(watched_dirs[all])] == watched_dirs[all]: trash_dest = trash_dir + (tmp_path[len(watched_dirs[all]):]) + '/'; if os.path.exists(trash_dest): shutil.move(filename,trash_dest); logger.info("%s moved to Trash" %filename); else: os.makedirs(trash_dest); shutil.move(filename,trash_dest); logger.info("%s moved to Trash" %filename);
def __init__(self): self.logger = logging.getLogger('Media_Manager.plugin') self.logger.debug ("Init Plugin Sub System"); cfg = Config() try: self.path = cfg.get_config_value('Default','plugin_path') except: self.logger.warn("No Plugin path found"); self.path = None; if self.path == None: self.pluglist = None else: sys.path.append(self.path); self.pluglist = self.find_plugins(self.path);
class Main(): def __init__(self): opts = self.cmdline(); # Parse command line options self.configure(opts); # parse config self.setup_logging(); self.watch_media(); def cmdline(self): parser = argparse.ArgumentParser(description='Automatily Manage Media items'); parser.add_argument('-c','--config',help="Specify a config file to use",required=False) parser.add_argument('-l','--log file',help='Specify the Log file to use if blank stdout is used',required=False) parser.add_argument('-p','--plugin_dir',help='Path to plugins',required=False); #TODO fix Debug parser.add_argument('-d','--debug',help='Debug Mode lots of junk in the logfile',required=False); args = vars(parser.parse_args()); return (args) def configure(self,args): # Load Config file if args['config'] == None: print ("Please point me at a config file") sys.exit(); else: Config.config_file = (args['config']) self.cfg = Config(); #Configure log file if args['log file'] == None: self.log_filename = self.cfg.get_config_value('logging','logfile'); # check for logfile in the config else: self.log_filename = args['log file']; def setup_logging(self): #Log Format formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') #Create Logger self.logger = logging.getLogger('Media_Manager'); self.logger.setLevel(logging.DEBUG); if self.log_filename == None: self.logger.info("No Logfile found"); else: #Create File handler self.logger.info("Logging to %s" % self.log_filename); fh = logging.FileHandler(self.log_filename) fh.setLevel(logging.DEBUG); fh.setFormatter(formatter) self.logger.addHandler(fh) #ch = logging.StreamHandler(); #ch.setLevel(logging.INFO); #ch.setFormatter(formatter) #self.logger.addHandler(ch) def watch_media(self): wd = self.cfg.read_config('Watch_dirs') if wd == None: self.logger.warn("No directorys to watch nothing for me todo"); sys.exit(); else: Mm = Media() for all in wd: Mm.add_dir(wd[all]); Mm.start_watching();