Beispiel #1
0
def initialize(args=None, **kwargs):
    """
    Initialize the profile system. You may use the following arguments to
    configure the profile system:

    =============  ============  ============
    Argument       Default       Description
    =============  ============  ============
    portable       ``False``     If True, the profile system will attempt to live entirely in the root path.
    profile        ``default``   The name of the profile to load.
    package                      If this is set, and ``pkg_resources`` is available, then attempt to find resources in this package or requirement.
    profile_path                 If this is set, load the profile from this path.
    root_path                    The application root directory. If not set, this will be calculated with ``os.path.abspath(os.path.dirname(sys.argv[0]))``.
    cache_path                   If this is set, this path will be used to cache data rather than a profile-specific path.
    =============  ============  ============

    In addition, you can provide a list of command line arguments to have
    siding load them automatically. Example::

        siding.profile.initialize(sys.argv[1:])

    The following command line arguments are supported:

    ===================  ============
    Argument             Description
    ===================  ============
    ``--portable``       If set, the profile system will attempt to live entirely in the ``root_path``.
    ``--profile``        The name of the profile to load.
    ``--profile-path``   If this is set, load the profile from this path.
    ``--root-path``      The application root directory.
    ``--cache-path``     If this is set, this path will be used to cache data rather than a profile-specific path.
    ``--package``        If this is set, and ``pkg_resources`` is available, then attempt to find resources in this package or requirement.
    ===================  ============
    """
    global name
    global portable
    global package
    global profile_path
    global root_path
    global cache_path
    global settings

    # Set the defaults now.
    portable = kwargs.get('portable', False)
    name = kwargs.get('profile', 'default')

    # And load the paths if we've got them.
    package = kwargs.get('package', package)
    root_path = kwargs.get('root_path', root_path)
    profile_path = kwargs.get('profile_path', profile_path)
    cache_path = kwargs.get('cache_path', cache_path)

    # Now, parse the options we've got.
    if args:
        if args is True:
            args = sys.argv[1:]

        parser = argparse.ArgumentParser(add_help=False)
        parser.add_argument('--portable', action='store_true', default=None)
        parser.add_argument('--profile')
        parser.add_argument('--profile-path')
        parser.add_argument('--root-path')
        parser.add_argument('--cache-path')
        parser.add_argument('--package')

        options = parser.parse_known_args(args)[0]

        # Let's set stuff up then.
        if options.portable is not None:
            portable = options.portable

        if options.profile:
            name = options.profile

        if options.package:
            package = package

        if options.profile_path:
            profile_path = options.profile_path
            if not os.path.exists(profile_path):
                os.makedirs(profile_path)

        if options.root_path:
            root_path = options.root_path
            if not os.path.exists(root_path):
                parser.error("The specified root path doesn't exist.")

        if options.cache_path:
            cache_path = options.cache_path
            if not os.path.exists(cache_path):
                os.makedirs(cache_path)

    # Now, open the settings file with QSettings and we're done.
    ensure_paths()
    file = os.path.join(profile_path, u'settings.ini')
    settings = QSettings(file, QSettings.IniFormat)

    log.info(u'Using profile: %s (%s)' % (name, profile_path))
    log.debug(u'settings.ini contains %d keys across %d groups.' %
              (len(settings.allKeys()), len(settings.childGroups())))
Beispiel #2
0
def initialize(args=None, **kwargs):
    """
    Initialize the profile system. You may use the following arguments to
    configure the profile system:

    =============  ============  ============
    Argument       Default       Description
    =============  ============  ============
    portable       ``False``     If True, the profile system will attempt to live entirely in the root path.
    profile        ``default``   The name of the profile to load.
    package                      If this is set, and ``pkg_resources`` is available, then attempt to find resources in this package or requirement.
    profile_path                 If this is set, load the profile from this path.
    root_path                    The application root directory. If not set, this will be calculated with ``os.path.abspath(os.path.dirname(sys.argv[0]))``.
    cache_path                   If this is set, this path will be used to cache data rather than a profile-specific path.
    =============  ============  ============

    In addition, you can provide a list of command line arguments to have
    siding load them automatically. Example::

        siding.profile.initialize(sys.argv[1:])

    The following command line arguments are supported:

    ===================  ============
    Argument             Description
    ===================  ============
    ``--portable``       If set, the profile system will attempt to live entirely in the ``root_path``.
    ``--profile``        The name of the profile to load.
    ``--profile-path``   If this is set, load the profile from this path.
    ``--root-path``      The application root directory.
    ``--cache-path``     If this is set, this path will be used to cache data rather than a profile-specific path.
    ``--package``        If this is set, and ``pkg_resources`` is available, then attempt to find resources in this package or requirement.
    ===================  ============
    """
    global name
    global portable
    global package
    global profile_path
    global root_path
    global cache_path
    global settings

    # Set the defaults now.
    portable = kwargs.get('portable', False)
    name = kwargs.get('profile', 'default')

    # And load the paths if we've got them.
    package = kwargs.get('package', package)
    root_path = kwargs.get('root_path', root_path)
    profile_path = kwargs.get('profile_path', profile_path)
    cache_path = kwargs.get('cache_path', cache_path)

    # Now, parse the options we've got.
    if args:
        if args is True:
            args = sys.argv[1:]

        parser = argparse.ArgumentParser(add_help=False)
        parser.add_argument('--portable', action='store_true', default=None)
        parser.add_argument('--profile')
        parser.add_argument('--profile-path')
        parser.add_argument('--root-path')
        parser.add_argument('--cache-path')
        parser.add_argument('--package')

        options = parser.parse_known_args(args)[0]

        # Let's set stuff up then.
        if options.portable is not None:
            portable = options.portable

        if options.profile:
            name = options.profile

        if options.package:
            package = package

        if options.profile_path:
            profile_path = options.profile_path
            if not os.path.exists(profile_path):
                os.makedirs(profile_path)

        if options.root_path:
            root_path = options.root_path
            if not os.path.exists(root_path):
                parser.error("The specified root path doesn't exist.")

        if options.cache_path:
            cache_path = options.cache_path
            if not os.path.exists(cache_path):
                os.makedirs(cache_path)

    # Now, open the settings file with QSettings and we're done.
    ensure_paths()
    file = os.path.join(profile_path, u'settings.ini')
    settings = QSettings(file, QSettings.IniFormat)

    log.info(u'Using profile: %s (%s)' % (name, profile_path))
    log.debug(u'settings.ini contains %d keys across %d groups.' % (
        len(settings.allKeys()), len(settings.childGroups())))
Beispiel #3
0
def initialize(args=None, **kwargs):
    """
    Initialize the profile system. You may use the following arguments to
    configure the profile system:

    =============  ============  ============
    Argument       Default       Description
    =============  ============  ============
    portable       ``False``     If True, the profile system will create a profile path within the root folder, allowing the application to work as a portable app.
    profile        ``default``   The name of the profile to load.
    sources        ``[]``        A list of additional sources for the path system to use. These will be fed into :func:`siding.path.add_source`, along with any sources from the command line.
    profile_path                 If this is set, load the profile from this path rather than building a path.
    root_path                    The application root directory. This is always the last source to be used by the path system.
    =============  ============  ============

    .. warning::
        ``root_path`` will *probably* not work as expected after your
        application is frozen into an executable, so be sure to test that it's
        working properly before distributing your application if you're using
        ``root_path``.

    In addition, you can provide a list of command line arguments to have
    siding load them automatically. Example::

        siding.profile.initialize(sys.argv[1:])

    The following command line arguments are supported:

    ===================  ============
    Argument             Description
    ===================  ============
    ``--portable``       If True, the profile system will create a profile path within the root folder, allowing the application to work as a portable app.
    ``--profile``        The name of the profile to load.
    ``--profile-path``   The path to load the profile from.
    ``--root-path``      The application root directory.
    ``--source``         An additional source for the path system. This can be used multiple times.
    ===================  ============
    """
    global name
    global portable
    global profile_path
    global root_path
    global settings

    # Set the defaults now.
    portable = kwargs.get('portable', False)
    name = kwargs.get('profile', 'default')

    # And load the paths if we've got them.
    root_path = kwargs.get('root_path', root_path)
    profile_path = kwargs.get('profile_path', profile_path)

    # Get the source list.
    sources = kwargs.get('sources', [])

    # Now, parse the options we've got.
    if args:
        if args is True:
            args = sys.argv[1:]

        parser = argparse.ArgumentParser(add_help=False)
        parser.add_argument('--portable', action='store_true', default=None)
        parser.add_argument('--profile')
        parser.add_argument('--profile-path')
        parser.add_argument('--root-path')
        parser.add_argument('--source', action='append')

        options = parser.parse_known_args(args)[0]

        # Let's set stuff up then.
        if options.portable is not None:
            portable = options.portable

        if options.profile:
            name = options.profile

        if options.profile_path:
            profile_path = options.profile_path
            if not os.path.exists(profile_path):
                os.makedirs(profile_path)

        if options.root_path:
            root_path = options.root_path
            if not os.path.exists(root_path):
                parser.error("The specified root path doesn't exist.")

        if options.source:
            for source in options.source:
                if not source in sources:
                    if not os.path.exists(source):
                        parser.error("The source %r doesn't exist." % source)
                    sources.append(source)

    # Now, do the path stuff.
    for source in sources:
        path.add_source(source)

    # Do we already have our paths?
    if profile_path or root_path:
        path.add_source(profile_path)

    # Make sure.
    ensure_paths()

    # Now, open the settings file with QSettings and we're done.
    file = os.path.join(profile_path, 'settings.ini')
    settings = QSettings(file, QSettings.IniFormat)

    log.info(u'Using profile: %s (%s)' % (name, profile_path))
    log.debug(u'settings.ini contains %d keys across %d groups.' % (
        len(settings.allKeys()), len(settings.childGroups())))