def main(arguments=None): """Runs thumbor server with the specified arguments.""" server_parameters = get_server_parameters(arguments) logging.basicConfig(level=getattr(logging, server_parameters.log_level.upper())) lookup_paths = [os.curdir, expanduser("~"), "/etc/", dirname(__file__)] config = Config.load(server_parameters.config_path, conf_name="thumbor.conf", lookup_paths=lookup_paths) importer = Importer(config) importer.import_modules() if server_parameters.security_key is None: server_parameters.security_key = config.SECURITY_KEY if not isinstance(server_parameters.security_key, basestring): raise RuntimeError( "No security key was found for this instance of thumbor. Please provide one using the conf file or a security key file." ) context = Context(server=server_parameters, config=config, importer=importer) application = ThumborServiceApp(context) server = HTTPServer(application) server.bind(context.server.port, context.server.ip) server.start(1) try: logging.debug("thumbor running at %s:%d" % (context.server.ip, context.server.port)) tornado.ioloop.IOLoop.instance().start() except KeyboardInterrupt: print print "-- thumbor closed by user interruption --"
def main(arguments=None): '''Runs thumbor server with the specified arguments.''' server_parameters = get_server_parameters(arguments) logging.basicConfig(level=getattr(logging, server_parameters.log_level.upper())) config = Config.load(server_parameters.config_path) importer = Importer(config) importer.import_modules() if server_parameters.security_key is not None: config.SECURITY_KEY = server_parameters.security_key if not isinstance(config.SECURITY_KEY, basestring): raise RuntimeError('No security key was found for this instance of thumbor. Please provide one using the conf file or a security key file.') context = Context(server=server_parameters, config=config, importer=importer) application = ThumborServiceApp(context) server = HTTPServer(application) server.bind(context.server.port, context.server.ip) server.start(1) try: tornado.ioloop.IOLoop.instance().start() except KeyboardInterrupt: print print "-- thumbor closed by user interruption --"
def setUp(self, *args, **kwargs): super(FakeRotateEngineRotateFilterTestCase, self).setUp(*args, **kwargs) conf = Config() imp = Importer(conf) imp.filters = [Filter] self.context = Context(None, conf, imp) self.context.request = RequestParameters()
def get_filter(self, filter_name, params_string="", config_context=None): config = Config( FILTERS=[filter_name], LOADER='thumbor.loaders.file_loader', FILE_LOADER_ROOT_PATH=join(dirname(realpath(__file__)), 'fixtures', 'filters') ) importer = Importer(config) importer.import_modules() req = RequestParameters() context = Context(config=config, importer=importer) context.request = req context.request.engine = context.modules.engine if config_context is not None: config_context(context) self.context = context fltr = importer.filters[0] fltr.pre_compile() context.transformer = Transformer(context) return fltr(params_string, context=context)
def test_import_item_should_be_proper_item(self): importer = Importer(self.get_config()) importer.import_modules() data = { 'ENGINE': pil_engine, 'GIF_ENGINE': gif_engine, 'LOADER': http_loader, 'STORAGE': file_storage, 'UPLOAD_PHOTO_STORAGE': file_storage, 'RESULT_STORAGE': result_file_storage, 'DETECTORS': (face_detector,), 'FILTERS': (rgb_filter,), } for key, value in data.iteritems(): prop, default_value = (None, None) if hasattr(importer, key.lower()): prop, default_value = (getattr(importer, key.lower()), value) if prop is tuple: for index, item in enumerate(prop): expect(item).not_to_be_null() expect(item).to_equal(default_value[index]) else: expect(prop).not_to_be_null() expect(prop).to_equal(default_value)
def get_context(): conf = Config() conf.ENGINE = "thumbor.engines.pil" imp = Importer(conf) imp.import_modules() imp.filters = [Filter] return Context(None, conf, imp)
def get_app(self): cfg = Config.load(fixture_for("encrypted_handler_conf.py")) importer = Importer(cfg) importer.import_modules() ctx = Context(None, cfg, importer) application = ThumborServiceApp(ctx) return application
def get_app(self): storage_path = '/tmp/thumbor-engines-test/' if exists(storage_path): rmtree(storage_path) self.timeout_handle = None cfg = Config(SECURITY_KEY='ACME-SEC', FILE_STORAGE_ROOT_PATH=storage_path) server_params = ServerParameters(None, None, None, None, None, None) cfg.DETECTORS = [ 'thumbor.detectors.face_detector', 'thumbor.detectors.profile_detector', 'thumbor.detectors.glasses_detector', 'thumbor.detectors.feature_detector', ] conf_key = self._testMethodName.split('__')[1] conf = CONFS.get(conf_key, None) if conf: for key, value in conf.items(): setattr(cfg, key, value) importer = Importer(cfg) importer.import_modules() ctx = Context(server_params, cfg, importer) application = ThumborServiceApp(ctx) return application
def get_app(self): cfg = Config(SECURITY_KEY='ACME-SEC') server_params = ServerParameters(None, None, None, None, None, None) server_params.gifsicle_path = which('gifsicle') cfg.DETECTORS = [ 'thumbor.detectors.face_detector', 'thumbor.detectors.profile_detector', 'thumbor.detectors.glasses_detector', 'thumbor.detectors.feature_detector', ] cfg.STORAGE = 'thumbor.storages.no_storage' cfg.LOADER = 'thumbor.loaders.file_loader' cfg.FILE_LOADER_ROOT_PATH = os.path.join(os.path.dirname(__file__), 'imgs') cfg.ENGINE = getattr(self, 'engine', None) cfg.USE_GIFSICLE_ENGINE = True cfg.FFMPEG_PATH = which('ffmpeg') cfg.ENGINE_THREADPOOL_SIZE = 10 cfg.OPTIMIZERS = [ 'thumbor.optimizers.gifv', ] if not cfg.ENGINE: return None importer = Importer(cfg) importer.import_modules() ctx = Context(server_params, cfg, importer) application = ThumborServiceApp(ctx) return application
def topic(self): conf = Config() conf.ENGINE = 'thumbor.engines.pil' imp = Importer(conf) imp.import_modules() imp.filters = [Filter] return Context(None, conf, imp)
def get_importer(config): importer = Importer(config) importer.import_modules() if importer.error_handler_class is not None: importer.error_handler = importer.error_handler_class(config) return importer
def topic(self, test_item): test_data, config = test_item importer = Importer(config) importer.import_modules() if hasattr(importer, test_data[0].lower()): return (getattr(importer, test_data[0].lower()), test_data[1]) return (None, None)
def test_can_create_context_with_importer(self): cfg = Config() importer = Importer(cfg) importer.import_modules() ctx = Context(config=cfg, importer=importer) expect(ctx.modules).not_to_be_null() expect(ctx.modules.importer).to_equal(importer)
def test_single_item_should_equal_file_storage(self): importer = Importer(None) importer.import_item( config_key='file_storage', item_value='thumbor.storages.file_storage', class_name='Storage' ) expect(importer.file_storage).to_equal(file_storage)
def get_context(self): cfg = Config() cfg.HEALTHCHECK_ROUTE = '/' importer = Importer(cfg) importer.import_modules() return Context(None, cfg, importer)
def topic(self): conf = Config() conf.METRICS = 'tc_librato.metrics.librato_metrics' conf.LIBRATO_USER = '******' conf.LIBRATO_TOKEN = 'test' conf.LIBRATO_NAME_PREFIX = 'test' imp = Importer(conf) imp.import_modules() return Context(None, conf, imp)
def get_app(self): cfg = Config.load(fixture_for('encrypted_handler_conf.py')) server_params = ServerParameters(None, None, None, None, None, None) server_params.security_key = 'HandlerVows' importer = Importer(cfg) importer.import_modules() ctx = Context(server_params, cfg, importer) application = ThumborServiceApp(ctx) return application
def get_app(table): cfg = Config(HBASE_STORAGE_TABLE=table, HBASE_STORAGE_SERVER_PORT=9090, STORAGE="thumbor_hbase.storage") importer = Importer(cfg) importer.import_modules() server = ServerParameters(8888, "localhost", "thumbor.conf", None, "info", None) ctx = Context(server, cfg, importer) application = ThumborServiceApp(ctx) return application
def get_context(self): cfg = Config(SECURITY_KEY='ACME-SEC') cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = self.loader_path importer = Importer(cfg) importer.import_modules() server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None) server.security_key = 'ACME-SEC' return Context(server, cfg, importer)
def topic(self): importer = Importer(None) importer.import_item( config_key='detectors', is_multiple=True, item_value=( 'thumbor.detectors.feature_detector', 'thumbor.detectors.feature_detector' ) ) return importer.detectors
def topic(self): conf = Config() imp = Importer(conf) imp.filters = [Filter] ctx = Context(None, conf, imp) ctx.request = RequestParameters() filter_instances = ctx.filters_factory.create_instances(ctx, "format(invalid)") filter_instances[0].run()
def get_app(self): server_params = ServerParameters(None, None, None, None, None, None) cfg = self.get_config() importer = Importer(cfg) importer.import_modules() self.ctx = Context(server_params, cfg, importer) application = App(self.ctx) return application
def topic(self): conf = Config() imp = Importer(conf) imp.filters = [Filter] ctx = Context(None, conf, imp) ctx.request = RequestParameters() runner = ctx.filters_factory.create_instances(ctx, "format(invalid)") filter_instances = runner.filter_instances[thumbor.filters.PHASE_POST_TRANSFORM] filter_instances[0].run()
def get_context(self): cfg = Config(SECURITY_KEY="ACME-SEC") cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = self.loader_path cfg.ENABLE_ETAGS = False importer = Importer(cfg) importer.import_modules() server = ServerParameters(8889, "localhost", "thumbor.conf", None, "info", None) server.security_key = "ACME-SEC" return Context(server, cfg, importer)
def get_app(self): cfg = Config() cfg.ENABLE_ORIGINAL_PHOTO_UPLOAD = True cfg.ORIGINAL_PHOTO_STORAGE = 'thumbor.storages.file_storage' cfg.FILE_STORAGE_ROOT_PATH = storage_path cfg.ALLOW_ORIGINAL_PHOTO_DELETION = False importer = Importer(cfg) importer.import_modules() ctx = Context(None, cfg, importer) application = ThumborServiceApp(ctx) return application
def test_multiple_items_can_be_imported(self): importer = Importer(None) importer.import_item( config_key='detectors', is_multiple=True, item_value=( 'thumbor.detectors.feature_detector', 'thumbor.detectors.feature_detector' ) ) expect(importer.detectors).to_length(2) expect(importer.detectors).to_include(feature_detector)
def get_app(self): cfg = Config() cfg.UPLOAD_ENABLED = True cfg.UPLOAD_PHOTO_STORAGE = 'thumbor.storages.file_storage' cfg.FILE_STORAGE_ROOT_PATH = file_storage_root_path cfg.UPLOAD_DELETE_ALLOWED = False importer = Importer(cfg) importer.import_modules() ctx = Context(None, cfg, importer) application = ThumborServiceApp(ctx) return application
def get_app(self): cfg = Config(SECURITY_KEY='ACME-SEC') cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = storage_path importer = Importer(cfg) importer.import_modules() server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None) server.security_key = 'ACME-SEC' ctx = Context(server, cfg, importer) application = ThumborServiceApp(ctx) return application
def get_context(self): cfg = Config(SECURITY_KEY='ACME-SEC') cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = self.loader_path cfg.AUTO_WEBP = True cfg.USE_GIFSICLE_ENGINE = True importer = Importer(cfg) importer.import_modules() server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None) server.security_key = 'ACME-SEC' ctx = Context(server, cfg, importer) ctx.server.gifsicle_path = which('gifsicle') return ctx
def get_context(self): cfg = Config(SECURITY_KEY='ACME-SEC') cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = self.loader_path cfg.STORAGE = "thumbor.storages.no_storage" cfg.RESPECT_ORIENTATION = True importer = Importer(cfg) importer.import_modules() server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None) server.security_key = 'ACME-SEC' self.context = Context(server, cfg, importer) self.context.server.gifsicle_path = which('gifsicle') return self.context
def main(arguments=None): '''Runs thumbor server with the specified arguments.''' server_parameters = get_server_parameters(arguments) lookup_paths = [os.curdir, expanduser('~'), '/etc/', dirname(__file__)] config = Config.load(server_parameters.config_path, conf_name='thumbor.conf', lookup_paths=lookup_paths) logging.basicConfig(level=getattr(logging, server_parameters.log_level.upper()), format=config.THUMBOR_LOG_FORMAT, datefmt=config.THUMBOR_LOG_DATE_FORMAT) importer = Importer(config) importer.import_modules() if importer.error_handler_class is not None: importer.error_handler = importer.error_handler_class(config) if server_parameters.security_key is None: server_parameters.security_key = config.SECURITY_KEY if not isinstance(server_parameters.security_key, basestring): raise RuntimeError( 'No security key was found for this instance of thumbor. ' + 'Please provide one using the conf file or a security key file.') context = Context(server=server_parameters, config=config, importer=importer) application = importer.import_class(server_parameters.app_class)(context) server = HTTPServer(application) server.bind(context.server.port, context.server.ip) server.start(1) try: logging.debug('thumbor running at %s:%d' % (context.server.ip, context.server.port)) tornado.ioloop.IOLoop.instance().start() except KeyboardInterrupt: print print "-- thumbor closed by user interruption --"
def topic(self): config = Config() server = ServerParameters( 8889, 'localhost', 'thumbor.conf', None, 'info', None ) context = Context(server, config, Importer(config)) context.server.gifsicle_path = which('gifsicle') context.request = RequestParameters() with open("%s/animated_image.gif" % FIXTURES_FOLDER, "rb") as f: buffer = f.read() engine = GifEngine(context=context) engine.load(buffer, '.gif') return engine.read()
def to_context(self): self.engine = MockEngine((self.source_width, self.source_height)) flip_horizontally = self.target_width < 0 flip_vertically = self.target_height < 0 self.target_width = self.target_width == "orig" and "orig" or abs( self.target_width) self.target_height = self.target_height == "orig" and "orig" or abs( self.target_height) importer = Importer(None) ctx = Context(server=None, config=None, importer=importer) ctx.modules.engine = self.engine ctx.request = RequestParameters(buffer=None, debug=False, meta=False, crop={ 'left': self.crop_left, 'top': self.crop_top, 'right': self.crop_right, 'bottom': self.crop_bottom }, adaptive=self.adaptive, fit_in=self.fit_in, horizontal_flip=flip_horizontally, vertical_flip=flip_vertically, width=self.target_width, height=self.target_height, halign=self.halign, valign=self.valign, focal_points=self.focal_points, smart=True, extension="JPEG", filters=[], quality=80, image="some.jpeg") return ctx
class CompatibilityResultStorageTestCase(TestCase): def get_image_path(self, name): return f"./tests/fixtures/images/{name}" def get_image_bytes(self, name): with open(self.get_image_path(name), "rb") as img: return img.read() def get_image_url(self, name): return f"s.glbimg.com/some/{name}" def get_context(self): config = Config( FILE_LOADER_ROOT_PATH=STORAGE_PATH, COMPATIBILITY_LEGACY_RESULT_STORAGE= "tests.compatibility.legacy_file_result_storage", STORES_CRYPTO_KEY_FOR_EACH_IMAGE=True, ) self.importer = Importer(config) self.importer.import_modules() server = ServerParameters(8889, "localhost", "thumbor.conf", None, "info", None) server.security_key = "ACME-SEC" return Context(server, config=config, importer=self.importer) @gen_test async def test_should_raise_for_invalid_compatibility_storage(self): request = RequestParameters(url="/image.jpg", ) config = Config( FILE_LOADER_ROOT_PATH=STORAGE_PATH, STORES_CRYPTO_KEY_FOR_EACH_IMAGE=True, ) importer = Importer(config) importer.import_modules() image_bytes = self.get_image_bytes("image.jpg") ctx = Context(self.context.server, config, importer) ctx.request = request storage = Storage(ctx) with expect.error_to_happen( RuntimeError, message= ("The 'COMPATIBILITY_LEGACY_RESULT_STORAGE' configuration should point " "to a valid result storage when using compatibility result storage." ), ): await storage.get() with expect.error_to_happen( RuntimeError, message= ("The 'COMPATIBILITY_LEGACY_RESULT_STORAGE' configuration should point " "to a valid result storage when using compatibility result storage." ), ): await storage.put(image_bytes) @gen_test async def test_should_put_and_get(self): request = RequestParameters(url="/image.jpg", ) image_bytes = self.get_image_bytes("image.jpg") ctx = Context(self.context.server, self.context.config, self.importer) ctx.request = request storage = Storage(ctx) await storage.put(image_bytes) result = await storage.get() expect(result).not_to_be_null() expect(result).not_to_be_an_error() expect(result.successful).to_be_true() expect(result.buffer).to_equal(image_bytes)
def topic(self): importer = Importer(None) importer.import_item(config_key='detectors', item_value=('thumbor.detectors.feature_detector', 'thumbor.detectors.feature_detector'), is_multiple=True) return importer.detectors
def topic(self): conf = Config() conf.METRICS = 'thumbor.metrics.statsd_metrics' imp = Importer(conf) imp.import_modules() return Context(None, conf, imp)
def topic(self): config = Config() importer = Importer(config) context = Context(None, config, importer) return App(context)
async def load_file(self, context, file_name): Importer.deprecated_monkey_patch_tornado_return_future() from thumbor.compatibility.loader import ( # pylint: disable=import-outside-toplevel load, ) return await load(context, file_name)
def topic(self): conf = Config() conf.METRICS = 'tc_prometheus.metrics.prometheus_metrics' imp = Importer(conf) imp.import_modules() return Context(None, conf, imp)
def get_importer(self, *args, **kwargs): return Importer(self.config)
def main(arguments=None): '''Runs thumbor server with the specified arguments.''' server_parameters = get_server_parameters(arguments) lookup_paths = [os.curdir, expanduser('~'), '/etc/', dirname(__file__)] config = Config.load(server_parameters.config_path, conf_name='thumbor.conf', lookup_paths=lookup_paths) if (config.THUMBOR_LOG_CONFIG and config.THUMBOR_LOG_CONFIG != ''): logging.config.dictConfig(config.THUMBOR_LOG_CONFIG) else: logging.basicConfig(level=getattr(logging, server_parameters.log_level.upper()), format=config.THUMBOR_LOG_FORMAT, datefmt=config.THUMBOR_LOG_DATE_FORMAT, filename=server_parameters.log_file) importer = Importer(config) importer.import_modules() if importer.error_handler_class is not None: importer.error_handler = importer.error_handler_class(config) if server_parameters.security_key is None: server_parameters.security_key = config.SECURITY_KEY if not isinstance(server_parameters.security_key, basestring): raise RuntimeError( 'No security key was found for this instance of thumbor. ' + 'Please provide one using the conf file or a security key file.') if config.USE_GIFSICLE_ENGINE: server_parameters.gifsicle_path = which('gifsicle') if server_parameters.gifsicle_path is None: raise RuntimeError( 'If using USE_GIFSICLE_ENGINE configuration to True, the `gifsicle` binary must be in the PATH and must be an executable.' ) context = Context(server=server_parameters, config=config, importer=importer) application = importer.import_class(server_parameters.app_class)(context) server = HTTPServer(application) if context.server.fd is not None: fd_number = get_as_integer(context.server.fd) if fd_number is None: with open(context.server.fd, 'r') as sock: fd_number = sock.fileno() sock = socket.fromfd(fd_number, socket.AF_INET | socket.AF_INET6, socket.SOCK_STREAM) server.add_socket(sock) else: server.bind(context.server.port, context.server.ip) server.start(1) # Adapted from gist.github.com/mywaiting/4643396. Note: This function is # only ever executed as a callback by the main IO loop. Therefore all # calls to it are guaranteed to be serialized, so it doesn't have to be # either thread-safe or reentrant. global shutting_down shutting_down = False def shutdown(): global shutting_down if shutting_down: return shutting_down = True logging.critical('Stopping server. No longer accepting connections') server.stop() logging.critical('Shutdown in at most %d seconds', config.MAX_WAIT_BEFORE_SHUTDOWN) io_loop = tornado.ioloop.IOLoop.instance() deadline = time.time() + config.MAX_WAIT_BEFORE_SHUTDOWN def stop_loop(): now = time.time() if now < deadline and (io_loop._callbacks or io_loop._timeouts): io_loop.add_timeout(min(now + 1, deadline), stop_loop) else: logging.critical('Stopping IO loop and exiting') io_loop.stop() stop_loop() def sig_handler(sig, frame): # Stdlib Logging functions are not reentrant. # logging.warning('Caught signal: %s', sig) tornado.ioloop.IOLoop.instance().add_callback_from_signal(shutdown) signal.signal(signal.SIGTERM, sig_handler) signal.signal(signal.SIGINT, sig_handler) try: logging.debug('thumbor running at %s:%d' % (context.server.ip, context.server.port)) tornado.ioloop.IOLoop.instance().start() except KeyboardInterrupt: print print "-- thumbor closed by user interruption --" finally: context.thread_pool.cleanup()
def main(arguments=None): '''Runs thumbor server with the specified arguments.''' server_parameters = get_server_parameters(arguments) lookup_paths = [os.curdir, expanduser('~'), '/etc/', dirname(__file__)] config = Config.load(server_parameters.config_path, conf_name='thumbor.conf', lookup_paths=lookup_paths) if (config.THUMBOR_LOG_CONFIG and config.THUMBOR_LOG_CONFIG != ''): logging.config.dictConfig(config.THUMBOR_LOG_CONFIG) else: logging.basicConfig(level=getattr(logging, server_parameters.log_level.upper()), format=config.THUMBOR_LOG_FORMAT, datefmt=config.THUMBOR_LOG_DATE_FORMAT) importer = Importer(config) importer.import_modules() if importer.error_handler_class is not None: importer.error_handler = importer.error_handler_class(config) if server_parameters.security_key is None: server_parameters.security_key = config.SECURITY_KEY if not isinstance(server_parameters.security_key, basestring): raise RuntimeError( 'No security key was found for this instance of thumbor. ' + 'Please provide one using the conf file or a security key file.') if config.USE_GIFSICLE_ENGINE: server_parameters.gifsicle_path = which('gifsicle') if server_parameters.gifsicle_path is None: raise RuntimeError( 'If using USE_GIFSICLE_ENGINE configuration to True, the `gifsicle` binary must be in the PATH and must be an executable.' ) context = Context(server=server_parameters, config=config, importer=importer) application = importer.import_class(server_parameters.app_class)(context) server = HTTPServer(application) if context.server.fd is not None: fd_number = get_as_integer(context.server.fd) if fd_number is None: with open(context.server.fd, 'r') as sock: fd_number = sock.fileno() sock = socket.fromfd(fd_number, socket.AF_INET | socket.AF_INET6, socket.SOCK_STREAM) server.add_socket(sock) else: server.bind(context.server.port, context.server.ip) server.start(1) try: logging.debug('thumbor running at %s:%d' % (context.server.ip, context.server.port)) tornado.ioloop.IOLoop.instance().start() except KeyboardInterrupt: print print "-- thumbor closed by user interruption --" finally: context.thread_pool.cleanup()
def test_single_item_should_equal_file_storage(self): importer = Importer(None) importer.import_item(config_key='file_storage', item_value='thumbor.storages.file_storage', class_name='Storage') expect(importer.file_storage).to_equal(file_storage)
def get_importer(self): return Importer(self.config)
def get_importer(self): importer = Importer(self.config) importer.import_modules() return importer
def get_context(self): conf = Config() conf.METRICS = 'thumbor.metrics.logger_metrics' imp = Importer(conf) imp.import_modules() return Context(None, conf, imp)
def topic(self): importer = Importer(None) importer.import_item(config_key='file_storage', item_value='thumbor.storages.file_storage', class_name='Storage') return importer.file_storage