def __normalise(): for pathSource in Config.get('normaliser.path.sources').split(','): try: Normaliser(pathSource, 'Pictures').run() Normaliser(pathSource, 'Videos').run() except Exception as err: logging.error(str(err))
def __rename(): for pathSource in Config.get('renamer.path.sources').split(','): try: Renamer(pathSource, 'Pictures').run() Renamer(pathSource, 'Videos').run() except Exception as err: logging.error(str(err))
def __shrink(): for pathSource in Config.get('shrinker.path.sources').split(','): try: Shrinker(pathSource, 'Pictures').run() Shrinker(pathSource, 'Videos').run() except Exception as err: logging.error(str(err))
def __classify(): for pathSource in Config.get('classifier.path.sources').split(','): try: Classifier(pathSource, 'Pictures').run() Classifier(pathSource, 'Videos').run() except Exception as err: logging.error(str(err))
def __buildDestinationFilename(self, filename, destinationPath): media = MediaBuilder.build(filename) partialPath = FileUtils.getDestinationSubdirectory(media) filePath = os.path.join(destinationPath, partialPath, media.getNextNewFileName()) filePathWithoutExtension = os.path.splitext(filePath)[0] newExtension = '.' + Config.get('handbrake.destination.extension') return filePathWithoutExtension + newExtension
def __handleError(self, filename): self.numberOfErrors = self.numberOfErrors + 1 logging.error("Error normalising %s. Error number %s.", filename, str(self.numberOfErrors), exc_info=True) if self.numberOfErrors == int( Config.get('normaliser.max.number.of.errors')): raise ValueError( 'Too many errors. Something is wrong. Aborting execution.')
def __buildCommand(inputFile, outputFile): command = [] command.append('HandBrakeCLI') command.append('-i') command.append(inputFile) command.append('-o') command.append(outputFile) command.append('-x') command.append(Config.get('handbrake.profile')) return command
def __init__(self, config: Config): super().__init__(config.get('port'), config.get('host'), config.get('private_key'), config.get('id'), config.get('log_level')) self.dispatcher = Dispatcher.get_peer_dispatcher(config) self.bootstrap_nodes_addresses = config.get('bn_nodes') self.bar_connection = {}
def __init__(self, sourcePath, mediaType): self.numberOfErrors = 0 self.sourcePath = sourcePath self.destinationPath = Config.get('normaliser.path.destination') self.mediaType = mediaType
def __init__(self, config: Config): super().__init__(config.get('port'), config.get('host'), config.get('private_key'), config.get('id'), config.get('log_level')) self.dispatcher = Dispatcher.get_bn_dispatcher(config)
def check(): logFileLocations = Config.get('log.file.locations').split(',') for logFileLocation in logFileLocations: LogMonitor.__checkLogFile(logFileLocation)
def sendMail(body): message = Mail.__buildMessage(body) server = Mail.__configureServer() server.sendmail(Config.get('mail.sender'), Config.get('mail.receiver'), message) server.quit()
def __buildMessage(body): template = 'From: {0}\nTo: {1}\nSubject: Something went wrong!\n{2}' return template.format(Config.get('mail.sender'), Config.get('mail.receiver'), body)
def __configureServer(): mailserver = smtplib.SMTP(Config.get('mail.smtp.host')) mailserver.starttls() mailserver.login(Config.get('mail.smtp.username'), Config.get('mail.smtp.password')) return mailserver
import logging import sys sys.path.append('../config') from config.Config import Config logging.basicConfig(filename=Config.get('log.file.location'), \ format='[%(asctime)s][%(levelname)s] %(message)s', \ datefmt='%d/%m/%Y %H:%M:%S')