コード例 #1
0
ファイル: help.py プロジェクト: nicLucian/pytis
 def __init__(self):
     self._menu_help_data = pd.dbtable('e_pytis_help_menu', ('fullname', 'content', 'changed', 'removed'),
                                       config.dbconnection)
     self._spec_help_data = pd.dbtable('e_pytis_help_spec', ('spec_name', 'description', 'help', 'changed', 'removed'),
                                       config.dbconnection)
     self._spec_help_items_data = pd.dbtable('e_pytis_help_spec_items',
                                             ('item_id', 'spec_name', 'kind', 'identifier',
                                              'content', 'changed', 'removed'), config.dbconnection)
     self._done = {}
コード例 #2
0
 def __init__(self):
     self._menu_help_data = pd.dbtable('e_pytis_help_menu', ('fullname', 'content',
                                                             'changed', 'removed'))
     self._spec_help_data = pd.dbtable('e_pytis_help_spec', ('spec_name', 'description',
                                                             'help', 'changed', 'removed'))
     self._spec_help_items_data = pd.dbtable('e_pytis_help_spec_items',
                                             ('item_id', 'spec_name', 'kind',
                                              'identifier', 'content', 'changed', 'removed'))
     self._done = {}
コード例 #3
0
ファイル: salt-passwords.py プロジェクト: cerha/wiking
def run():
    if '--help' in sys.argv:
        usage()
    try:
        pytis.config.add_command_line_options(sys.argv)
        if len(sys.argv) > 1:
            usage()
    except getopt.GetoptError as e:
        usage(e.msg)
    wiking.cfg.user_config_file = pytis.config.config_file
    wiking.cms.cfg.user_config_file = pytis.config.config_file
    pytis.config.dblisten = False
    pytis.config.log_exclude = [pytis.util.ACTION, pytis.util.EVENT,
                                pytis.util.DEBUG, pytis.util.OPERATIONAL]
    while True:
        try:
            data = pd.dbtable('users', ('uid', 'login', 'password'), pytis.config.dbconnection)
        except pd.DBLoginException as e:
            if pytis.config.dbconnection.password() is None:
                import getpass
                login = pytis.config.dbuser
                password = getpass.getpass("Enter database password for %s: " % login)
                pytis.config.dbconnection.update_login_data(user=login, password=password)
        else:
            break
    storage = wiking.Pbkdf2PasswordStorage()
    transaction = pd.transaction()
    data.select(transaction=transaction)
    n = 0
    plain = 0
    try:
        while True:
            row = data.fetchone()
            if row is None:
                break
            orig_prefix, orig_password = row['password'].value().split(':', 1)
            if orig_prefix == 'md5u':
                prefix = 'pbkdf2/md5'
            elif orig_prefix == 'plain':
                prefix = 'pbkdf2'
                plain += 1
            else:
                continue
            password = prefix + ':' + storage.stored_password(orig_password)
            data.update(row['uid'], pd.Row([('password', pd.sval(password))]),
                        transaction=transaction)
            n += 1
    except Exception:
        try:
            transaction.rollback()
        except Exception:
            pass
        sys.stderr.write("Transaction rolled back.\n")
        raise
    else:
        print("Total %d passwords updated (%d from plain text, %d from md5)." % \
            (n, plain, n - plain))
        transaction.commit()
    transaction.close()
コード例 #4
0
ファイル: salt-passwords.py プロジェクト: brailcom/wiking
def run():
    if "--help" in sys.argv:
        usage()
    try:
        config.add_command_line_options(sys.argv)
        if len(sys.argv) > 1:
            usage()
    except getopt.GetoptError as e:
        usage(e.msg)
    wiking.cfg.user_config_file = config.config_file
    wiking.cms.cfg.user_config_file = config.config_file
    config.dblisten = False
    config.log_exclude = [pytis.util.ACTION, pytis.util.EVENT, pytis.util.DEBUG, pytis.util.OPERATIONAL]
    while True:
        try:
            data = pd.dbtable("users", ("uid", "login", "password"), config.dbconnection)
        except pd.DBLoginException as e:
            if config.dbconnection.password() is None:
                import getpass

                login = config.dbuser
                password = getpass.getpass("Enter database password for %s: " % login)
                config.dbconnection.update_login_data(user=login, password=password)
        else:
            break
    storage = wiking.Pbkdf2PasswordStorage()
    transaction = pd.DBTransactionDefault(config.dbconnection)
    data.select(transaction=transaction)
    n = 0
    plain = 0
    try:
        while True:
            row = data.fetchone()
            if row is None:
                break
            orig_prefix, orig_password = row["password"].value().split(":", 1)
            if orig_prefix == "md5u":
                prefix = "pbkdf2/md5"
            elif orig_prefix == "plain":
                prefix = "pbkdf2"
                plain += 1
            else:
                continue
            password = prefix + ":" + storage.stored_password(orig_password)
            data.update(row["uid"], pd.Row([("password", pd.sval(password))]), transaction=transaction)
            n += 1
    except:
        try:
            transaction.rollback()
        except:
            pass
        sys.stderr.write("Transaction rolled back.\n")
        raise
    else:
        print "Total %d passwords updated (%d from plain text, %d from md5)." % (n, plain, n - plain)
        transaction.commit()
    transaction.close()
コード例 #5
0
 def update(self):
     """(Re)generate help for all menu items."""
     data = pd.dbtable('ev_pytis_help', ('help_id', 'fullname', 'spec_name', 'position'))
     data.select(sort=(('position', pd.ASCENDENT),))
     while True:
         row = data.fetchone()
         if row is None:
             break
         if row['fullname'].value():
             self._update_menu_item_help(row['fullname'].value(), row['spec_name'].value())
コード例 #6
0
ファイル: help.py プロジェクト: nicLucian/pytis
 def update(self):
     """(Re)generate help for all menu items."""
     data = pd.dbtable('ev_pytis_help', ('help_id', 'fullname', 'spec_name', 'position'),
                       config.dbconnection)
     data.select(sort=(('position', pd.ASCENDENT),))
     while True:
         row = data.fetchone()
         if row is None:
             break
         if row['fullname'].value():
             self._update_menu_item_help(row['fullname'].value(), row['spec_name'].value())
コード例 #7
0
ファイル: defs.py プロジェクト: cerha/pytis
def get_menu_forms():
    """Return sequence of all forms present in application menu as tuples (form_class, specname).
    """
    import pytis.form

    def flatten_menus(queue, found, level=0):
        if queue:
            head, tail = queue[0], queue[1:]
            found.append(head)
            if isinstance(head, pytis.form.Menu):
                flatten_menus(list(head.items()), found, level=level + 1)
            result = flatten_menus(tail, found, level=level)
        else:
            result = found
        return result

    try:
        data = pd.dbtable('ev_pytis_menu', ('shortname', 'fullname'))
    except Exception:
        data = None
    if data is None:
        try:
            appl = pytis.config.resolver.specification('Application')
        except ResolverError:
            menus = pytis.config.resolver.get('application', 'menu')
        else:
            menus = appl.menu()
        forms = [
            (item.args()['form_class'], item.args()['name'])
            for item in flatten_menus(menus, [])
            if (isinstance(item, pytis.form.MItem) and item.command() ==
                pytis.form.Application.COMMAND_RUN_FORM and not issubclass(
                    item.args()['form_class'], pytis.form.ConfigForm))
        ]
    else:
        forms = []

        def get_values(row):
            return row['shortname'].value(), row['fullname'].value()

        for shortname, fullname in data.select_map(get_values):
            if ((shortname and shortname[:5] == 'form/'
                 and fullname.startswith('form/pytis.form'))):
                formclass = getattr(pytis.form,
                                    fullname.split('/')[1].split('.')[-1])
                forms.append((formclass, shortname[5:]))
    return forms
コード例 #8
0
ファイル: defs.py プロジェクト: cerha/pytis
    def __init__(self, spec_name_prefix=None):
        """
        Arguments:

          spec_name_prefix -- if not None then only specification with given
            prefix (basestring) are tested

        """
        import pytis.output
        self._output_resolver = pytis.output.OutputResolver(
            pytis.config.print_spec_dir, pytis.config.resolver)
        data = pd.dbtable('e_pytis_roles', ('name', 'purposeid'))
        condition = pd.NE('purposeid', pd.Value(pd.String(), 'user'))
        self._application_roles = [
            row[0].value()
            for row in data.select_map(identity, condition=condition)
        ]
        self._spec_name_prefix = spec_name_prefix
コード例 #9
0
ファイル: cleanup-attachments.py プロジェクト: cerha/wiking
def run():
    if '--help' in sys.argv:
        usage()
    if '--no-act' in sys.argv:
        del sys.argv[sys.argv.index('--no-act')]
        no_act = True
    else:
        no_act = False
    try:
        config.add_command_line_options(sys.argv)
        if len(sys.argv) > 1:
            usage()
    except getopt.GetoptError as e:
        usage(e.msg)
    wiking.cfg.user_config_file = config.config_file
    wiking.cms.cfg.user_config_file = config.config_file
    config.dblisten = False
    config.log_exclude = [pytis.util.ACTION, pytis.util.EVENT, pytis.util.DEBUG,
                          pytis.util.OPERATIONAL]
    while True:
        try:
            data = pd.dbtable('cms_page_attachments', ('attachment_id', 'filename'),
                              config.dbconnection)
        except pd.DBLoginException as e:
            if config.dbconnection.password() is None:
                import getpass
                login = config.dbuser
                password = getpass.getpass("Enter database password for %s: " % login)
                config.dbconnection.update_login_data(user=login, password=password)
        else:
            break
    attachments = []
    directory = os.path.join(wiking.cms.cfg.storage, config.dbname, 'attachments')
    ok = stray = 0

    data.select()
    while True:
        row = data.fetchone()
        if row is None:
            break
        ext = os.path.splitext(row['filename'].value())[1].lower()
        fname = row['attachment_id'].export() + (ext or '.')
        path = os.path.join(directory, fname)
        if not os.path.exists(path):
            sys.stderr.write("Missing file: %s\n" % path)
        attachments.append(fname)

    for fname in os.listdir(directory):
        path = os.path.join(directory, fname)
        if os.path.isfile(path):
            if fname in attachments:
                ok += 1
            else:
                stray += 1
                if no_act:
                    sys.stderr.write("Stray file: %s\n" % path)
                else:
                    sys.stderr.write("Removing file: %s\n" % path)
                    os.unlink(path)
    sys.stderr.write("Total %d of %d files ok, %d %s.\n" %
                     (ok, len(attachments), stray, 'stray' if no_act else 'removed'))
コード例 #10
0
ファイル: web.py プロジェクト: cerha/pytis
 def __init__(self, *args, **kwargs):
     super(HttpAttachmentStorageBackend, self).__init__(*args, **kwargs)
     self._data = pd.dbtable('e_pytis_http_attachment_storage_keys',
                             ('key_id', 'username', 'uri', 'readonly', 'key'))
コード例 #11
0
ファイル: update-thumbnails.py プロジェクト: brailcom/wiking
def run():
    if '--help' in sys.argv:
        usage()
    try:
        config.add_command_line_options(sys.argv)
        if len(sys.argv) > 1:
            usage()
    except getopt.GetoptError as e:
        usage(e.msg)
    wiking.cfg.user_config_file = config.config_file
    wiking.cms.cfg.user_config_file = config.config_file
    config.dblisten = False
    config.log_exclude = [pytis.util.ACTION, pytis.util.EVENT, pytis.util.DEBUG, pytis.util.OPERATIONAL]
    while True:
        try:
            data = pd.dbtable('cms_page_attachments',
                              ('attachment_id', 'filename', 'image', 'thumbnail', 
                               'thumbnail_size', 'thumbnail_width', 'thumbnail_height'),
                              config.dbconnection)
        except pd.DBLoginException as e:
            if config.dbconnection.password() is None:
                import getpass
                login = config.dbuser
                password = getpass.getpass("Enter database password for %s: " % login)
                config.dbconnection.update_login_data(user=login, password=password)
        else:
            break
    image_screen_size = wiking.cms.cfg.image_screen_size
    image_thumbnail_sizes = wiking.cms.cfg.image_thumbnail_sizes
    transaction = pd.DBTransactionDefault(config.dbconnection)
    data.select(transaction=transaction)
    try:
        while True:
            row = data.fetchone()
            if row is None:
                break
            ext = os.path.splitext(row['filename'].value())[1].lower()
            path = os.path.join(wiking.cms.cfg.storage, config.dbname, 'attachments',
                                row['attachment_id'].export() + (ext or '.'))
            attachment = file(path)
            try:
                image = PIL.Image.open(attachment)
            except IOError, e:
                continue
            sys.stderr.write("Resizing %s (%dx%d): " % 
                             (row['filename'].value(), image.size[0], image.size[1]))
            thumbnail_size = row['thumbnail_size'].value()
            if thumbnail_size is None:
                thumbnail_value, real_thumbnail_size = None, (None, None)
            else:
                if thumbnail_size == 'small':
                    size = image_thumbnail_sizes[0]
                elif thumbnail_size == 'medium':
                    size = image_thumbnail_sizes[1]
                else:
                    size = image_thumbnail_sizes[2]
                thumbnail_value, real_thumbnail_size = resize(image, (size, size))
                sys.stderr.write("%dx%d, " % real_thumbnail_size)
            resized_image_value, resized_image_size = resize(image, image_screen_size)
            sys.stderr.write("%dx%d\n" % resized_image_size)
            values = dict(thumbnail=thumbnail_value,
                          thumbnail_width=real_thumbnail_size[0],
                          thumbnail_height=real_thumbnail_size[1],
                          image=resized_image_value)
            r = pd.Row([(key, pd.Value(row[key].type(), value)) for key, value in values.items()])
            #data.update(row['attachment_id'], r, transaction=transaction)
    except:
        try:
            transaction.rollback()
        except:
            pass
        sys.stderr.write("Transaction rolled back.\n")
        raise
    else:
        sys.stderr.write("Transaction commited.\n")
        transaction.commit()
    transaction.close()
コード例 #12
0
ファイル: update-thumbnails.py プロジェクト: cerha/wiking
def run():
    if '--help' in sys.argv:
        usage()
    try:
        pytis.config.add_command_line_options(sys.argv)
        if len(sys.argv) > 1:
            usage()
    except getopt.GetoptError as e:
        usage(e.msg)
    wiking.cfg.user_config_file = pytis.config.config_file
    pytis.config.dblisten = False
    pytis.config.log_exclude = [pytis.util.ACTION, pytis.util.EVENT,
                                pytis.util.DEBUG, pytis.util.OPERATIONAL]
    while True:
        try:
            data = pd.dbtable('cms_page_attachments',
                              ('attachment_id', 'filename', 'width', 'height',
                               'image', 'image_width', 'image_height', 'thumbnail',
                               'thumbnail_size', 'thumbnail_width', 'thumbnail_height'),
                              pytis.config.dbconnection)
        except pd.DBLoginException as e:
            if pytis.config.dbconnection.password() is None:
                import getpass
                login = pytis.config.dbuser
                password = getpass.getpass("Enter database password for %s: " % login)
                pytis.config.dbconnection.update_login_data(user=login, password=password)
        else:
            break
    image_screen_size = wiking.cms.cfg.image_screen_size
    image_thumbnail_sizes = wiking.cms.cfg.image_thumbnail_sizes
    transaction = pd.transaction()
    data.select(transaction=transaction)
    try:
        while True:
            row = data.fetchone()
            if row is None:
                break
            ext = os.path.splitext(row['filename'].value())[1].lower()
            path = os.path.join(wiking.cms.cfg.storage, pytis.config.dbname, 'attachments',
                                row['attachment_id'].export() + (ext or '.'))
            attachment = open(path, 'rb')
            try:
                image = PIL.Image.open(attachment)
            except IOError as e:
                continue
            sys.stderr.write("Resizing %s (%dx%d): " %
                             (row['filename'].value(), image.size[0], image.size[1]))
            thumbnail_size = row['thumbnail_size'].value()
            if thumbnail_size is None:
                thumbnail_value, real_thumbnail_size = None, (None, None)
            else:
                if thumbnail_size == 'small':
                    size = image_thumbnail_sizes[0]
                elif thumbnail_size == 'medium':
                    size = image_thumbnail_sizes[1]
                else:
                    size = image_thumbnail_sizes[2]
                thumbnail_value, real_thumbnail_size = resize(image, (size, size))
                sys.stderr.write("%dx%d, " % real_thumbnail_size)
            resized_image_value, resized_image_size = resize(image, image_screen_size)
            sys.stderr.write("%dx%d\n" % resized_image_size)
            values = dict(
                width=image.size[0],
                height=image.size[1],
                thumbnail=thumbnail_value,
                thumbnail_width=real_thumbnail_size[0],
                thumbnail_height=real_thumbnail_size[1],
                image=resized_image_value,
                image_width=resized_image_size[0],
                image_height=resized_image_size[1],
            )
            r = pd.Row([(key, pd.Value(row[key].type(), value)) for key, value in values.items()])
            data.update(row['attachment_id'], r, transaction=transaction)
    except Exception:
        try:
            transaction.rollback()
        except Exception:
            pass
        sys.stderr.write("Transaction rolled back.\n")
        raise
    else:
        sys.stderr.write("Transaction commited.\n")
        transaction.commit()
    transaction.close()