コード例 #1
0
    def __init__(self, *a, **kw):
        super(ImageAction, self).__init__(*a, **kw)

        # Read configuration
        self.store_original = asbool(self.orchestrator.settings.get(
            'img.store_original', True))
        self.quality = int(self.orchestrator.settings.get(
            'img.versions_quality', 90))
        versions = self.orchestrator.settings.get(
            'img.versions').strip().split('\n')
        self.versions = []
        for astring in versions:
            astring = astring.strip()
            parts = astring.split()
            assert len(parts) == 4, \
                'The configuration line "{}" should have 4 parts'.format(
                    astring)
            adict = {
                'format': parts[0].upper(),
                'width': int(parts[1]),
                'height': int(parts[2]),
                'name': parts[3],
                }
            self.versions.append(adict)

        # We want to process from smaller to bigger, so order versions by area:
        self.versions.sort(key=lambda d: d['width'] * d['height'])
コード例 #2
0
    def __init__(self, *a, **kw):
        """Store configuration settings, especially about the versions."""
        super(ImageAction, self).__init__(*a, **kw)

        # TODO: Schema for these configuration settings
        # Read configuration
        self.upload_must_be_img = asbool(self.orchestrator.settings.read("img.upload_must_be_img", default=False))
        self.store_original = asbool(self.orchestrator.settings.read("img.store_original", default=True))
        self.quality = int(self.orchestrator.settings.read("img.versions_quality", default=90))
        versions = self.orchestrator.settings.read("img.versions").strip().split("\n")
        self.versions = []
        for astring in versions:
            astring = astring.strip()
            parts = astring.split()
            assert len(parts) == 4, 'The configuration line "{}" should have 4 parts'.format(astring)
            adict = {"format": parts[0].upper(), "width": int(parts[1]), "height": int(parts[2]), "name": parts[3]}
            self.versions.append(adict)

        # We want to process from smaller to bigger, so order versions by area:
        self.versions.sort(key=lambda d: d["width"] * d["height"])
コード例 #3
0
ファイル: actions.py プロジェクト: pitymaia/keepluggable
 def _allow_storage_of(self, bytes_io, metadata):
     '''Override this method if you wish to abort storing some files.
         To abort, raise FileNotAllowed with a message explaining why.
         '''
     settings = self.orchestrator.settings
     maximum = read_setting(settings, 'fls.max_file_size', default=None)
     if maximum is not None:
         maximum = int(maximum)
         if metadata['length'] > maximum:
             raise FileNotAllowed(
                 'The file is {} KB long and the maximum is {} KB.'.format(
                     int(metadata['length'] / 1024), int(maximum / 1024)))
     allow_empty = asbool(read_setting(
         settings, 'fls.allow_empty_files', default=False))
     if not allow_empty and metadata['length'] == 0:
         raise FileNotAllowed('The file is empty.')
コード例 #4
0
def includeme(config):
    is_production = asbool(config.registry.settings.get('production', 'false'))
    robot = RobotFile()
    robot.add_rule(user_agent='*',
                   disallow='' if is_production else '/')
    init(config, robot)