Exemplo n.º 1
0
 def get_scrap_prefix(self):
     prefix = self.app.preferences['saving.scrap_prefix']
     prefix = fileutils.expanduser_unicode(prefix.decode('utf-8'))
     prefix = os.path.abspath(prefix)
     if os.path.isdir(prefix):
         if not prefix.endswith(os.path.sep):
             prefix += os.path.sep
     return prefix
Exemplo n.º 2
0
 def get_scrap_prefix(self):
     prefix = self.app.preferences['saving.scrap_prefix']
     # This should really use two separate settings, not one.
     # https://github.com/mypaint/mypaint/issues/375
     prefix = fileutils.expanduser_unicode(prefix)
     prefix = os.path.abspath(prefix)
     if os.path.isdir(prefix):
         if not prefix.endswith(os.path.sep):
             prefix += os.path.sep
     return prefix
Exemplo n.º 3
0
def check_old_style_config():
    # Old style config file and user data locations.
    # Return None if using XDG will be correct.
    if sys.platform == 'win32':
        old_confpath = None
    else:
        from lib import fileutils
        homepath = fileutils.expanduser_unicode(u'~')
        old_confpath = join(homepath, '.mypaint/')

    if old_confpath:
        if not os.path.isdir(old_confpath):
            old_confpath = None
        else:
            wiki_base = "https://github.com/mypaint/mypaint/wiki/"
            wiki_page = wiki_base + "Migrating-settings-&-data-from-1.1"
            logger.info("There is an old-style configuration area in %r",
                        old_confpath)
            logger.info("Its contents can be migrated to $XDG_CONFIG_HOME "
                        "and $XDG_DATA_HOME if you wish.")
            logger.info("For further instructions, see: %s" % wiki_page)
    assert isinstance(old_confpath, unicode) or old_confpath is None
    return old_confpath
Exemplo n.º 4
0
def get_paths():
    join = os.path.join

    # Convert sys.argv to a list of unicode objects
    # (actually converting sys.argv confuses gtk, thus we add a new variable)
    if sys.platform == 'win32':
        sys.argv_unicode = win32_unicode_argv()
    else:
        sys.argv_unicode = [
            s.decode(sys.getfilesystemencoding()) for s in sys.argv
        ]

    # Script and its location, in canonical absolute form
    scriptfile = os.path.realpath(sys.argv_unicode[0])
    scriptfile = os.path.abspath(os.path.normpath(scriptfile))
    scriptdir = os.path.dirname(scriptfile)
    assert isinstance(scriptfile, unicode)
    assert isinstance(scriptdir, unicode)

    # Determine the installation's directory layout.
    # Assume a conventional POSIX-style directory structure first,
    # where the launch script resides in $prefix/bin/.
    dir_install = scriptdir
    prefix = os.path.dirname(dir_install)
    assert isinstance(prefix, unicode)
    libpath = join(prefix, 'share', 'mypaint')
    localepath = join(prefix, 'share', 'locale')
    iconspath = join(prefix, 'share', 'icons')
    if os.path.exists(libpath) and os.path.exists(iconspath):
        # This is a normal POSIX-like installation.
        # The Windows standalone distribution works like this too.
        libpath_compiled = join(prefix, 'lib', 'mypaint')  # or lib64?
        sys.path.insert(0, libpath)
        sys.path.insert(0, libpath_compiled)
        sys.path.insert(0, join(prefix, 'share'))  # for libmypaint
        logger.info(
            "Installation layout: conventional POSIX-like structure "
            "with prefix %r", prefix)
    elif all(map(os.path.exists, ['desktop', 'gui', 'lib'])):
        # Testing from within the source tree.
        prefix = None
        libpath = u'.'
        iconspath = u'desktop/icons'
        localepath = 'po'
        logger.info("Installation layout: not installed, "
                    "testing from within the source tree")
    elif sys.platform == 'win32':
        prefix = None
        # This is py2exe point of view, all executables in root of
        # installdir.
        # XXX: are py2exe builds still relevant? The 1.2.0-beta Windows
        # installers are kitchen sink affairs.
        libpath = os.path.realpath(scriptdir)
        sys.path.insert(0, libpath)
        sys.path.insert(0, join(prefix, 'share'))  # for libmypaint
        localepath = join(libpath, 'share', 'locale')
        iconspath = join(libpath, 'share', 'icons')
        logger.info("Installation layout: Windows fallback, assuming py2exe")
    else:
        logger.critical("Installation layout: unknown!")
        raise RuntimeError("Unknown install type; could not determine paths")

    assert isinstance(libpath, unicode)

    datapath = libpath
    if not os.path.isdir(join(datapath, 'brushes')):
        logger.critical('Default brush collection not found!')
        logger.critical('It should have been here: %r', datapath)
        sys.exit(1)

    # Old style config file and user data locations.
    # Return None if using XDG will be correct.
    if sys.platform == 'win32':
        old_confpath = None
    else:
        from lib import fileutils
        homepath = fileutils.expanduser_unicode(u'~')
        old_confpath = join(homepath, '.mypaint/')

    if old_confpath:
        if not os.path.isdir(old_confpath):
            old_confpath = None
        else:
            logger.info("There is an old-style configuration area in %r",
                        old_confpath)
            logger.info("Its contents can be migrated to $XDG_CONFIG_HOME "
                        "and $XDG_DATA_HOME if you wish.")
            logger.info("See the XDG Base Directory Specification for info.")

    assert isinstance(old_confpath, unicode) or old_confpath is None
    assert isinstance(datapath, unicode)
    assert isinstance(iconspath, unicode)

    return datapath, iconspath, old_confpath, localepath
Exemplo n.º 5
0
def get_paths():
    join = os.path.join

    # Convert sys.argv to a list of unicode objects
    # (actually converting sys.argv confuses gtk, thus we add a new variable)
    # Post-Py3: almost certainly not needed, but check *all* platforms
    # before removing this stuff.

    sys.argv_unicode = None
    if sys.platform == 'win32':
        sys.argv_unicode = win32_unicode_argv()

    if sys.argv_unicode is None:
        argv_unicode = []
        for s in sys.argv:
            if hasattr(s, "decode"):
                s = s.decode(sys.getfilesystemencoding())
            argv_unicode.append(s)
        sys.argv_unicode = argv_unicode

    # Script and its location, in canonical absolute form
    scriptfile = os.path.realpath(sys.argv_unicode[0])
    scriptfile = os.path.abspath(os.path.normpath(scriptfile))
    scriptdir = os.path.dirname(scriptfile)
    assert isinstance(scriptfile, unicode)
    assert isinstance(scriptdir, unicode)

    # Determine the installation's directory layout.
    # Assume a conventional POSIX-style directory structure first,
    # where the launch script resides in $prefix/bin/.
    dir_install = scriptdir
    prefix = os.path.dirname(dir_install)
    assert isinstance(prefix, unicode)
    libpath = join(prefix, 'share', 'mypaint')
    localepath = join(prefix, 'share', 'locale')
    iconspath = join(prefix, 'share', 'icons')
    if os.path.exists(libpath) and os.path.exists(iconspath):
        # This is a normal POSIX-like installation.
        # The Windows standalone distribution works like this too.
        libpath_compiled = join(prefix, 'lib', 'mypaint')  # or lib64?
        sys.path.insert(0, libpath)
        sys.path.insert(0, libpath_compiled)
        sys.path.insert(0, join(prefix, 'share'))  # for libmypaint
        logger.info(
            "Installation layout: conventional POSIX-like structure "
            "with prefix %r", prefix)
    elif all(map(os.path.exists, ['desktop', 'gui', 'lib'])):
        # Testing from within the source tree.
        prefix = None
        libpath = u'.'
        iconspath = u'desktop/icons'
        localepath = os.path.join('build', 'locale')
        logger.info("Installation layout: not installed, "
                    "testing from within the source tree")
    elif sys.platform == 'win32':
        prefix = None
        # This is py2exe point of view, all executables in root of
        # installdir.
        # XXX: are py2exe builds still relevant? The 1.2.0-beta Windows
        # installers are kitchen sink affairs.
        libpath = os.path.realpath(scriptdir)
        sys.path.insert(0, libpath)
        sys.path.insert(0, join(prefix, 'share'))  # for libmypaint
        localepath = join(libpath, 'share', 'locale')
        iconspath = join(libpath, 'share', 'icons')
        logger.info("Installation layout: Windows fallback, assuming py2exe")
    else:
        logger.critical("Installation layout: unknown!")
        raise RuntimeError("Unknown install type; could not determine paths")

    assert isinstance(libpath, unicode)

    datapath = libpath

    # There is no need to return the datadir of mypaint-data.
    # It will be set at build time. I still check brushes presence.
    import lib.config
    # Allow brushdir path to be set relative to the installation prefix
    # Use string-formatting *syntax*, but not actual formatting. This is
    # to not have to deal with the remote possibility of a legitimate
    # brushdir path with brace-enclosed components (legal UNIX-paths).
    brushdir_path = lib.config.mypaint_brushdir
    pref_key = "{installation-prefix}/"
    if brushdir_path.startswith(pref_key):
        logger.info("Using brushdir path relative to installation-prefix")
        brushdir_path = join(prefix, brushdir_path[len(pref_key):])
    if not os.path.isdir(brushdir_path):
        logger.critical('Default brush collection not found!')
        logger.critical('It should have been here: %r', brushdir_path)
        sys.exit(1)

    # When using a prefix-relative path, replace it with the absolute path
    lib.config.mypaint_brushdir = brushdir_path

    # Old style config file and user data locations.
    # Return None if using XDG will be correct.
    if sys.platform == 'win32':
        old_confpath = None
    else:
        from lib import fileutils
        homepath = fileutils.expanduser_unicode(u'~')
        old_confpath = join(homepath, '.mypaint/')

    if old_confpath:
        if not os.path.isdir(old_confpath):
            old_confpath = None
        else:
            wiki_base = "https://github.com/mypaint/mypaint/wiki/"
            wiki_page = wiki_base + "Migrating-settings-&-data-from-1.1"
            logger.info("There is an old-style configuration area in %r",
                        old_confpath)
            logger.info("Its contents can be migrated to $XDG_CONFIG_HOME "
                        "and $XDG_DATA_HOME if you wish.")
            logger.info("For further instructions, see: %s" % wiki_page)

    assert isinstance(old_confpath, unicode) or old_confpath is None
    assert isinstance(datapath, unicode)
    assert isinstance(iconspath, unicode)

    return datapath, iconspath, old_confpath, localepath