def run_watch(self): configService = ConfigService() self.logger.info("Start watching") self._watch_refresh_source(None) observer = Observer() template_handler = CallbackHandler(self._watch_refresh_template) source_handler = CallbackHandler(self._watch_refresh_source) template_path = os.path.dirname( configService.get_template_from_config(self.config)) observer.add_handler(template_path, template_handler) if (self.config["input"]["locations"] is not None): for location in self.config["input"]["locations"]: observer.add_handler(location, source_handler) observer.start() try: while True: time.sleep(1) except KeyboardInterrupt: observer.stop() observer.join()
def main(self): """Run the command """ self.logger = logging.getLogger() configService = ConfigService() self.config = self.get_config() self.logger.info("Start watching") self.refresh_source(None) observer = Observer() template_handler = CallbackHandler(self.refresh_template) source_handler = CallbackHandler(self.refresh_source) template_path = os.path.dirname( configService.get_template_from_config(self.config)) observer.add_handler(template_path, template_handler) if (self.config["input"]["directories"] is not None): for directory in self.config["input"]["directories"]: observer.add_handler(directory, source_handler) if (self.config["input"]["files"] is not None): for file in self.config["input"]["files"]: observer.add_handler(file, source_handler) observer.start() try: while True: time.sleep(1) except KeyboardInterrupt: observer.stop() observer.join()
def create_from_config(self, config): """Create a template object file defined in the config object """ configService = ConfigService() template = TemplateService() template.output = config["output"]["location"] template_file = configService.get_template_from_config(config) template.input = os.path.basename(template_file) template.env = Environment(loader=FileSystemLoader(os.path.dirname(template_file))) return template
def _init_config(self): """return command's configuration from call's arguments """ options = self.parser.parse_args() if options.config is None and options.input is None: self.parser.print_help() sys.exit(2) if options.config is not None: configFactory = ConfigFactory() config = configFactory.load_from_file(options.config) else: config = ConfigObject() if options.input is not None: config["input"]["locations"] = [str(x) for x in options.input] if options.arguments is not None: config["input"]["arguments"] = dict( (x.partition("=")[0], x.partition("=")[2]) for x in options.arguments) if options.output is not None: config["output"]["location"] = options.output if options.no_validate is not None: config["input"]["validate"] = not options.no_validate if options.dry_run is not None: self.dry_run = options.dry_run if options.watch is not None: self.watch = options.watch if options.traceback is not None: self.traceback = options.traceback if options.quiet is not None: self.logger.setLevel(logging.WARNING) if options.silence is not None: logging.disable(logging.CRITICAL) configService = ConfigService() configService.validate(config) self.config = config
def get_config(self): """return command's configuration from call's arguments """ options = self.parser.parse_args() if options.config is None and options.directories is None and options.files is None: self.parser.print_help() sys.exit(2) if options.config is not None: configFactory = ConfigFactory() config = configFactory.load_from_file(options.config) else: config = ConfigObject() if options.directories is not None: config["input"]["directories"] = [ str(x) for x in options.directories ] if options.files is not None: config["input"]["files"] = [str(x) for x in options.files] if options.arguments is not None: config["input"]["arguments"] = dict( (x.partition("=")[0], x.partition("=")[2]) for x in options.arguments) if options.output is not None: config["output"]["location"] = options.output if options.no_validate is not None: config["input"]["validate"] = not options.no_validate configService = ConfigService() configService.validate(config) return config
def setUp(self): self.config = ConfigService()