Beispiel #1
0
    def gather_apps(self):
        system_files = []

        user_files = glob.glob(
            os.path.join(GLib.get_user_config_dir(), "autostart", "*.desktop"))
        for app in user_files:
            AUTOSTART_APPS.append(
                AutostartApp(app, user_position=os.path.dirname(app)))

        for d in GLib.get_system_config_dirs():
            system_files.extend(
                glob.glob(os.path.join(d, "autostart", "*.desktop")))

        for sys_app in system_files:
            found = False
            for app in AUTOSTART_APPS:
                if os.path.basename(sys_app) == os.path.basename(app.app):
                    app.system_position = os.path.dirname(sys_app)
                    found = True
                    break

            if not found:
                AUTOSTART_APPS.append(
                    AutostartApp(sys_app,
                                 system_position=os.path.dirname(sys_app)))
Beispiel #2
0
    def getConfigFile(self):
        try:
            from gi.repository import GLib
            configdirs = [GLib.get_user_config_dir()] + GLib.get_system_config_dirs()
            for configdir in configdirs:
                config = os.path.join(configdir, 'mtsend', 'mtsend.ini')
                print("Looking for configuration file %s" % config)
                if os.path.exists(config):
                    break
            assert(os.path.exists(config))
        except:
            try:
                config = os.path.join(os.environ['XDG_CONFIG_HOME'], 'mtsend', 'mtsend.ini');
                print("Looking for configuration file %s" % config)
                assert(os.path.exists(config));
            except:
                try:
                    config = os.path.join(os.environ['HOME'], '.config', 'mtsend', 'mtsend.ini')
                    print("Looking for configuration file %s" % config)
                    assert(os.path.exists(config));
                except:
                    try:
                        config = os.path.join(os.environ['HOME'], '.mtsendrc')
                        print("Looking for configuration file %s" % config)
                        assert(os.path.exists(config))
                    except:
                        config = 'mtsend.ini'
                        print("Looking for configuration file %s" % config)

        if os.access(config, os.R_OK):
            print("Using configuration file %s" % config)
        else:
            raise Exception('Configuration file doesn\'t exist or is not readable')

        return config
Beispiel #3
0
def getSystemMenuPath(file_id):
    """Return the path to the system-installed menu file."""
    for path in GLib.get_system_config_dirs():
        file_path = os.path.join(path, 'menus', file_id)
        if os.path.isfile(file_path):
            return file_path
    return None
Beispiel #4
0
    def gather_apps(self):
        system_files = []

        blacklisted_apps = get_blacklisted_apps()

        user_files = glob.glob(
            os.path.join(GLib.get_user_config_dir(), "autostart", "*.desktop"))
        for app in user_files:
            key = get_appname(app)
            if key in blacklisted_apps:
                continue
            AUTOSTART_APPS[key] = AutostartApp(
                app, user_position=os.path.dirname(app))

        for d in GLib.get_system_config_dirs():
            system_files.extend(
                glob.glob(os.path.join(d, "autostart", "*.desktop")))

        for sys_app in system_files:
            key = get_appname(sys_app)
            if key in blacklisted_apps:
                continue
            if key in AUTOSTART_APPS:
                AUTOSTART_APPS[key].system_position = os.path.dirname(sys_app)
            else:
                AUTOSTART_APPS[key] = AutostartApp(
                    sys_app, system_position=os.path.dirname(sys_app))
    def get_autostart(filename, defaults=None):
        if not defaults:
            defaults = {}
        autostart = os.path.join(GLib.get_user_config_dir(), 'autostart')
        if not os.path.exists(autostart):
            os.makedirs(autostart)
        keyfile = GLib.KeyFile.new()

        dirs = [autostart]
        for directory in (GLib.get_system_config_dirs()):
            dirs.append(os.path.join(directory, 'autostart'))

        try:
            keyfile.load_from_dirs(filename, dirs,
                                   GLib.KeyFileFlags.KEEP_TRANSLATIONS)
        except GLib.Error:
            pass

        for key in defaults.keys():
            try:
                if keyfile.get_value("Desktop Entry", key) is None:
                    keyfile.set_value("Desktop Entry", key, defaults[key])
            except GLib.Error:
                keyfile.set_value("Desktop Entry", key, defaults[key])

        return keyfile
Beispiel #6
0
    def build_default(cls,
                      config_dirs: Optional[List[str]] = None) -> '_Settings':
        if config_dirs is None:
            config_dirs = GLib.get_system_config_dirs() + [
                GLib.get_user_config_dir()
            ] + [os.getcwd()]

        config_files = [dir_ + '/ocrd-browser.conf' for dir_ in config_dirs]
        return cls.build_from_files(config_files)
Beispiel #7
0
    def test_xdg_dirs(self):
        d = GLib.get_user_data_dir()
        self.assertTrue('/' in d, d)
        d = GLib.get_user_special_dir(GLib.USER_DIRECTORY_DESKTOP)
        self.assertTrue('/' in d, d)
        # also works with backwards compatible enum names
        self.assertEqual(GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_MUSIC),
                         GLib.get_user_special_dir(GLib.USER_DIRECTORY_MUSIC))

        for d in GLib.get_system_config_dirs():
            self.assertTrue('/' in d, d)
        for d in GLib.get_system_data_dirs():
            self.assertTrue(isinstance(d, str), d)
    def read(self):
        self._groups.clear()

        pathes = []
        pathes += GLib.get_system_data_dirs()
        pathes += GLib.get_system_config_dirs()
        pathes.append(os.path.dirname(os.path.dirname(self._output_path)))

        files = []
        for path in pathes:
            files += sorted(
                iglob(
                    os.path.join(path, self._base_dir, self._base_name + '.d',
                                 '*.conf')))
            files.append(os.path.join(path, self._base_dir, self._base_name))

        for path in filter(os.path.isfile, files):
            config_file = configparser.RawConfigParser(strict=False,
                                                       allow_no_value=True)
            try:
                if not config_file.read(path):
                    continue
            except configparser.Error as e:
                print(e, file=sys.stderr)
                continue

            for groupname, values in config_file.items():
                if groupname == 'DEFAULT':
                    continue

                if groupname not in self._groups:
                    self._groups[groupname] = Config.ConfigGroup(self)
                group = self._groups[groupname]

                for key, value in values.items():
                    if value is None:
                        print(
                            '[{group}] {key}: Keys without values are not allowed'
                            .format(group=groupname, key=key),
                            file=sys.stderr)
                        continue
                    if key.startswith('-'):
                        key = key[1:]
                        value = None

                    if key in group._items:
                        values = group._items[key]
                        if value is not None or values:
                            values.append((path, value))
                    elif value is not None:
                        group._items[key] = [(path, value)]
Beispiel #9
0
    def test_xdg_dirs(self):
        d = GLib.get_user_data_dir()
        self.assertTrue('/' in d, d)
        d = GLib.get_user_special_dir(GLib.USER_DIRECTORY_DESKTOP)
        self.assertTrue('/' in d, d)
        # also works with backwards compatible enum names
        self.assertEqual(
            GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_MUSIC),
            GLib.get_user_special_dir(GLib.USER_DIRECTORY_MUSIC))

        for d in GLib.get_system_config_dirs():
            self.assertTrue('/' in d, d)
        for d in GLib.get_system_data_dirs():
            self.assertTrue(isinstance(d, str), d)
Beispiel #10
0
    def build_default(cls,
                      config_dirs: Optional[List[str]] = None,
                      validate: bool = True) -> 'Settings':
        if config_dirs is None:
            config_dirs = GLib.get_system_config_dirs() + [
                GLib.get_user_config_dir()
            ]
            try:
                config_dirs.append(os.getcwd())
            except FileNotFoundError:
                # ignore deleted cwd in unit tests
                pass

        config_files = [dir_ + '/ocrd-browser.conf' for dir_ in config_dirs]
        return cls.build_from_files(config_files, validate)
Beispiel #11
0
def desktop_menu_uninstall(directory_files, desktop_files):
    """Remove applications or submenus from the desktop menu system
    previously installed with xdg-desktop-menu install."""
    # Check for the minimum required arguments
    if len(directory_files) == 0 or len(desktop_files) == 0:
        return

    # Do not uninstall from system paths.
    for path in GLib.get_system_config_dirs():
        for filename in directory_files:
            if filename.startswith(path):
                return

    # xdg-desktop-menu uninstall does not work... implement ourselves.
    basenames = []
    for filename in directory_files:
        basenames.append(os.path.basename(filename))
    basenames.sort()
    base_filename = os.path.basename(desktop_files[0])

    # Find the file with all the details to remove the filename.
    merged_dir = os.path.join(GLib.get_user_config_dir(),
                                    "menus", "applications-merged")

    for filename in os.listdir(merged_dir):
        filename = os.path.join(merged_dir, filename)
        found_directories = []
        filename_found = False
        with open(filename, 'r') as open_file:
            write_contents = ""
            for line in open_file:
                if "<Filename>" in line:
                    if base_filename in line:
                        filename_found = True
                    else:
                        write_contents += line
                else:
                    write_contents += line
                if "<Directory>" in line:
                    line = line.split("<Directory>")[1]
                    line = line.split("</Directory>")[0]
                    found_directories.append(line)
        if filename_found:
            found_directories.sort()
            if basenames == found_directories:
                with open(filename, 'w') as open_file:
                    open_file.write(write_contents)
                return
Beispiel #12
0
def desktop_menu_uninstall(directory_files, desktop_files):  # noqa
    """Remove applications or submenus from the desktop menu system
    previously installed with xdg-desktop-menu install."""
    # Check for the minimum required arguments
    if len(directory_files) == 0 or len(desktop_files) == 0:
        return

    # Do not uninstall from system paths.
    for path in GLib.get_system_config_dirs():
        for filename in directory_files:
            if filename.startswith(path):
                return

    # xdg-desktop-menu uninstall does not work... implement ourselves.
    basenames = []
    for filename in directory_files:
        basenames.append(os.path.basename(filename))
    basenames.sort()
    base_filename = os.path.basename(desktop_files[0])

    # Find the file with all the details to remove the filename.
    merged_dir = os.path.join(GLib.get_user_config_dir(), "menus",
                              "applications-merged")

    for filename in os.listdir(merged_dir):
        filename = os.path.join(merged_dir, filename)
        found_directories = []
        filename_found = False
        with open(filename, 'r') as open_file:
            write_contents = ""
            for line in open_file:
                if "<Filename>" in line:
                    if base_filename in line:
                        filename_found = True
                    else:
                        write_contents += line
                else:
                    write_contents += line
                if "<Directory>" in line:
                    line = line.split("<Directory>")[1]
                    line = line.split("</Directory>")[0]
                    found_directories.append(line)
        if filename_found:
            found_directories.sort()
            if basenames == found_directories:
                with open(filename, 'w') as open_file:
                    open_file.write(write_contents)
                return
Beispiel #13
0
    def test_xdg_dirs(self):
        d = GLib.get_user_data_dir()
        self.assertTrue(os.path.sep in d, d)
        d = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DESKTOP)
        self.assertTrue(os.path.sep in d, d)
        with warnings.catch_warnings():
            warnings.simplefilter('ignore', PyGIDeprecationWarning)

            # also works with backwards compatible enum names
            self.assertEqual(GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_MUSIC),
                             GLib.get_user_special_dir(GLib.USER_DIRECTORY_MUSIC))

        for d in GLib.get_system_config_dirs():
            self.assertTrue(os.path.sep in d, d)
        for d in GLib.get_system_data_dirs():
            self.assertTrue(isinstance(d, str), d)
Beispiel #14
0
    def test_xdg_dirs(self):
        d = GLib.get_user_data_dir()
        self.assertTrue(os.path.sep in d, d)
        d = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DESKTOP)
        self.assertTrue(os.path.sep in d, d)
        with warnings.catch_warnings():
            warnings.simplefilter('ignore', PyGIDeprecationWarning)

            # also works with backwards compatible enum names
            self.assertEqual(GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_MUSIC),
                             GLib.get_user_special_dir(GLib.USER_DIRECTORY_MUSIC))

        for d in GLib.get_system_config_dirs():
            self.assertTrue(os.path.sep in d, d)
        for d in GLib.get_system_data_dirs():
            self.assertTrue(isinstance(d, str), d)
    def read(self):
        self._groups.clear()

        pathes = []
        pathes += GLib.get_system_data_dirs()
        pathes += GLib.get_system_config_dirs()
        pathes.append(os.path.dirname(os.path.dirname(self._output_path)))

        files = []
        for path in pathes:
            files += sorted(iglob(os.path.join(path, self._base_dir,
                                               self._base_name + '.d', '*.conf')))
            files.append(os.path.join(path, self._base_dir, self._base_name))

        for path in filter(os.path.isfile, files):
            config_file = configparser.RawConfigParser(strict=False, allow_no_value=True)
            try:
                if not config_file.read(path):
                    continue
            except configparser.Error as e:
                print(e, file=sys.stderr)
                continue

            for groupname, values in config_file.items():
                if groupname == 'DEFAULT':
                    continue

                if groupname not in self._groups:
                    self._groups[groupname] = Config.ConfigGroup(self)
                group = self._groups[groupname]

                for key, value in values.items():
                    if value is None:
                        print('[{group}] {key}: Keys without values are not allowed'.format(
                            group=groupname, key=key), file=sys.stderr)
                        continue
                    if key.startswith('-'):
                        key = key[1:]
                        value = None

                    if key in group._items:
                        values = group._items[key]
                        if value is not None or values:
                            values.append((path, value))
                    elif value is not None:
                        group._items[key] = [(path, value)]
Beispiel #16
0
def desktop_menu_install(directory_files, desktop_files):
    """Install one or more applications in a submenu of the desktop menu
    system.  If multiple directory files are provided each file will represent
    a submenu within the menu that preceeds it, creating a nested menu
    hierarchy (sub-sub-menus). The menu entries themselves will be added to
    the last submenu. """
    # Check for the minimum required arguments
    if len(directory_files) == 0 or len(desktop_files) == 0:
        return

    # Do not install to system paths.
    for path in GLib.get_system_config_dirs():
        for filename in directory_files:
            if filename.startswith(path):
                return

    cmd_list = ["xdg-desktop-menu", "install", "--novendor"]
    cmd_list = cmd_list + directory_files + desktop_files
    subprocess.call(cmd_list)
Beispiel #17
0
def desktop_menu_install(directory_files, desktop_files):
    """Install one or more applications in a submenu of the desktop menu
    system.  If multiple directory files are provided each file will represent
    a submenu within the menu that preceeds it, creating a nested menu
    hierarchy (sub-sub-menus). The menu entries themselves will be added to
    the last submenu. """
    # Check for the minimum required arguments
    if len(directory_files) == 0 or len(desktop_files) == 0:
        return

    # Do not install to system paths.
    for path in GLib.get_system_config_dirs():
        for filename in directory_files:
            if filename.startswith(path):
                return

    cmd_list = ["xdg-desktop-menu", "install", "--novendor"]
    cmd_list = cmd_list + directory_files + desktop_files
    subprocess.call(cmd_list)
Beispiel #18
0
    def load_config(self):
        """ Load configuration. """

        paths = []
        dirs = list(GLib.get_system_config_dirs())
        dirs.append(GLib.get_user_config_dir())

        paths = [
            p for p in
            [os.path.join(d, 'manyssh', 'clusters.conf')
             for d in dirs] + ['clusters.conf'] if os.path.exists(p)
        ]

        self.config = {}

        for path in paths:
            print('-- Loading configuration: {0}'.format(path))
            with open(path) as f:
                self.config.update(json.load(f))
Beispiel #19
0
    def gather_apps(self):
        system_files = []

        user_files = glob.glob(os.path.join(GLib.get_user_config_dir(), "autostart", "*.desktop"))
        for app in user_files:
            AUTOSTART_APPS.append(AutostartApp(app, user_position=os.path.dirname(app)))

        for d in GLib.get_system_config_dirs():
            system_files.extend(glob.glob(os.path.join(d, "autostart", "*.desktop")))

        for sys_app in system_files:
            found = False
            for app in AUTOSTART_APPS:
                if os.path.basename(sys_app) == os.path.basename(app.app):
                    app.system_position = os.path.dirname(sys_app)
                    found = True
                    break

            if not found:
                AUTOSTART_APPS.append(AutostartApp(sys_app, system_position=os.path.dirname(sys_app)))
Beispiel #20
0
    def gather_apps(self):
        system_files = []

        blacklisted_apps = get_blacklisted_apps()

        user_files = glob.glob(os.path.join(GLib.get_user_config_dir(), "autostart", "*.desktop"))
        for app in user_files:
            key = get_appname(app)
            if key in blacklisted_apps:
                continue
            AUTOSTART_APPS[key] = AutostartApp(app, user_position=os.path.dirname(app))

        for d in GLib.get_system_config_dirs():
            system_files.extend(glob.glob(os.path.join(d, "autostart", "*.desktop")))

        for sys_app in system_files:
            key = get_appname(sys_app)
            if key in blacklisted_apps:
                continue
            if key in AUTOSTART_APPS:
                AUTOSTART_APPS[key].system_position = os.path.dirname(sys_app)
            else:
                AUTOSTART_APPS[key] = AutostartApp(sys_app,
                                                   system_position=os.path.dirname(sys_app))
Beispiel #21
0
try:
    for source in glob.iglob(os.path.join('i18n', '*.po')):
        code, _, _ = os.path.basename(source).rpartition('.')
        output = os.path.join('locale', code, 'LC_MESSAGES')
        if not os.path.exists(output):
            os.makedirs(output)
        output = os.path.join(output, NAME + '.mo')
        subprocess.call(('msgfmt', '-o', output, source))
    path = os.path.join('autostart', 'pointer-config.desktop')
    subprocess.call(('intltool-merge', '-d', 'i18n', path + '.in', path))
    path = os.path.join('applications', 'pointer-config.desktop')
    subprocess.call(('intltool-merge', '-d', 'i18n', path + '.in', path))
except OSError:
    sys.exit('msgfmt or intltool-merge missing')

conf = filter(GLib.path_is_absolute, GLib.get_system_config_dirs())[0]
data = filter(GLib.path_is_absolute, GLib.get_system_data_dirs())[0]
data_file = list()
append = lambda d, f: data_file.append(('/'.join(d), ('/'.join(f),)))

for path in glob.iglob(os.path.join('locale', '*', 'LC_MESSAGES')):
    append((data, path), (path, NAME + '.mo'))
append((conf, 'autostart'), ('autostart', NAME + '.desktop'))
append((data, 'applications'), ('applications', NAME + '.desktop'))
append((data, 'doc', NAME), ('COPYING',))
append((data, 'doc', NAME), ('README',))
append((data, 'glib-2.0/schemas'), ('Pointer.Config.gschema.xml',))
append((data, NAME), (NAME, NAME + '.glade'))

setup(
    name=NAME,
Beispiel #22
0
from setuptools import setup, find_packages
from gi.repository import GLib
from pathlib import Path
import os

sys_data_dir = Path(GLib.get_system_data_dirs()[-1])
sys_config_dir = Path(GLib.get_system_config_dirs()[0])
autostart_dir = str(sys_config_dir / 'autostart')
schema_dir = str(sys_data_dir / 'glib-2.0' / 'schemas')
app_dir = str(sys_data_dir / 'applications')
app_data_dir = sys_data_dir / 'passman'
gui_dir = str(app_data_dir / 'gui')
cache_dir = str(app_data_dir / 'cache')

help_walk = os.walk('help')
help_dirs = []
help_files = []
for dirpath, dirnames, filenames in help_walk:
    if filenames:
        dirpath = Path(dirpath)
        help_dirs.append(str(sys_data_dir / dirpath))
        help_files.append([str(dirpath / filename) for filename in filenames])

locale_walk = os.walk('locale')
dirpath, dirnames, filenames = next(locale_walk)
locale_dirs = [Path('locale') / name / 'LC_MESSAGES' for name in dirnames]
locale_files = [[str(name / 'passman.mo')] for name in locale_dirs]
locale_dirs = [str(sys_data_dir / name) for name in locale_dirs]

data_files = [(app_dir, ['freedesktop/passman.desktop']),
              (autostart_dir, ['freedesktop/passman-autostart.desktop']),
Beispiel #23
0
def getSystemMenuPath(file_id):
    for path in GLib.get_system_config_dirs():
        file_path = os.path.join(path, 'menus', file_id)
        if os.path.isfile(file_path):
            return file_path
    return None
Beispiel #24
0
 def _get_system_autostart_files(self):
     return [
         os.path.join(d, "autostart", self._autostart_desktop_filename)
             for d in GLib.get_system_config_dirs()]
Beispiel #25
0
 def get_system_autostart_files():
     f = []
     for d in GLib.get_system_config_dirs():
         f.extend( glob.glob(os.path.join(d, "autostart", "*.desktop")) )
     return f
Beispiel #26
0
 def get_system_autostart_files():
     f = []
     for d in GLib.get_system_config_dirs():
         f.extend( glob.glob(os.path.join(d, "autostart", "*.desktop")) )
     return f
Beispiel #27
0
from setuptools import setup, find_packages
from gi.repository import GLib
from pathlib import Path
import os

sys_data_dir = Path(GLib.get_system_data_dirs()[-1])
sys_config_dir = Path(GLib.get_system_config_dirs()[0])
autostart_dir = str(sys_config_dir / 'autostart')
schema_dir = str(sys_data_dir / 'glib-2.0' / 'schemas')
app_dir = str(sys_data_dir / 'applications')
app_data_dir = sys_data_dir / 'passman'
gui_dir = str(app_data_dir / 'gui')
cache_dir = str(app_data_dir / 'cache')

help_walk = os.walk('help')
help_dirs = []
help_files = []
for dirpath, dirnames, filenames in help_walk:
    if filenames:
        dirpath = Path(dirpath)
        help_dirs.append(str(sys_data_dir / dirpath))
        help_files.append([str(dirpath / filename) for filename in filenames])

locale_walk = os.walk('locale')
dirpath, dirnames, filenames = next(locale_walk)
locale_dirs = [Path('locale') / name / 'LC_MESSAGES' for name in dirnames]
locale_files = [[str(name / 'passman.mo')] for name in locale_dirs]
locale_dirs = [str(sys_data_dir / name) for name in locale_dirs]

data_files = [(app_dir, ['freedesktop/passman.desktop']),
              (autostart_dir, ['freedesktop/passman-autostart.desktop']),