Ejemplo n.º 1
0
    def test_runtime_dir_notset(self):
        environ.pop('XDG_RUNTIME_DIR', None)
        self.assertRaises(KeyError, BaseDirectory.get_runtime_dir, strict=True)
        fallback = BaseDirectory.get_runtime_dir(strict=False)
        assert fallback.startswith('/tmp/'), fallback
        assert os.path.isdir(fallback), fallback
        mode = stat.S_IMODE(os.stat(fallback).st_mode)
        self.assertEqual(mode, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)

        # Calling it again should return the same directory.
        fallback2 = BaseDirectory.get_runtime_dir(strict=False)
        self.assertEqual(fallback, fallback2)
        mode = stat.S_IMODE(os.stat(fallback2).st_mode)
        self.assertEqual(mode, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
Ejemplo n.º 2
0
 def test_runtime_dir_notset(self):
     environ.pop('XDG_RUNTIME_DIR', None)
     self.assertRaises(KeyError, BaseDirectory.get_runtime_dir, strict=True)
     fallback = BaseDirectory.get_runtime_dir(strict=False)
     assert fallback.startswith('/tmp/'), fallback
     assert os.path.isdir(fallback), fallback
     mode = stat.S_IMODE(os.stat(fallback).st_mode)
     self.assertEqual(mode, stat.S_IRUSR|stat.S_IWUSR|stat.S_IXUSR)
     
     # Calling it again should return the same directory.
     fallback2 = BaseDirectory.get_runtime_dir(strict=False)
     self.assertEqual(fallback, fallback2)
     mode = stat.S_IMODE(os.stat(fallback2).st_mode)
     self.assertEqual(mode, stat.S_IRUSR|stat.S_IWUSR|stat.S_IXUSR)
Ejemplo n.º 3
0
def _get_status_filename():
    """
    Get the status filename.
    Filename generated from xdg module, in $XDG_RUNTIME_DIR or in /tmp (in this order).
    """
    logger = logging.getLogger("_get_status_filename")
    status_basename = "chrandr.state"
    runtime_dir = None
    try:
        from xdg import BaseDirectory

        runtime_dir = BaseDirectory.get_runtime_dir()
    except ImportError:
        logger.info("xdg module not found")
        runtime_dir = os.getenv("XDG_RUNTIME_DIR")
    except KeyError:
        pass
    if runtime_dir is None:
        logger.debug("No environment variable XDG_RUNTIME_DIR")
        # no runtime dir, use /tmp
        import tempfile

        runtime_dir = tempfile.gettempdir()
        status_basename = "chrandr." + str(os.getuid()) + ".state"
    filename = os.path.join(runtime_dir, status_basename)
    logger.debug("Status filename: %s", filename)
    return filename
Ejemplo n.º 4
0
    def __init__(self):
        # Init databases and fifo
        name = 'roficlip'
        self.ring_db = '{0}/{1}'.format(BaseDirectory.save_data_path(name),
                                        'ring.db')
        self.persist_db = '{0}/{1}'.format(BaseDirectory.save_data_path(name),
                                           'persistent.db')
        self.fifo_path = '{0}/{1}.fifo'.format(
            BaseDirectory.get_runtime_dir(strict=False), name)
        self.config_path = '{0}/settings'.format(
            BaseDirectory.save_config_path(name))
        if not os.path.isfile(self.ring_db):
            open(self.ring_db, "a+").close()
        if not os.path.isfile(self.persist_db):
            open(self.persist_db, "a+").close()
        if (not os.path.exists(self.fifo_path)
                or not stat.S_ISFIFO(os.stat(self.fifo_path).st_mode)):
            os.mkfifo(self.fifo_path)
        self.fifo = os.open(self.fifo_path, os.O_RDONLY | os.O_NONBLOCK)

        # Init clipboard and read databases
        self.cb = gtk.Clipboard()
        self.ring = self.read(self.ring_db)
        self.persist = self.read(self.persist_db)

        # Load settings
        self.load_config()

        # Init notifications
        if self.cfg['notify']:
            pynotify.init(name)
Ejemplo n.º 5
0
    def __init__(self):
        self.run_dir = os.path.join(BaseDirectory.get_runtime_dir(), "pacman-notifier")
        self.pid_file = os.path.join(self.run_dir, "pid")
        self.pid = os.getpid()

        self.PIDFileCreate(mode="f")

        for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]:
            signal.signal(sig, self.SigHandler)
Ejemplo n.º 6
0
    def __iter__(self) -> ServiceGeneratorType:
        if not self.enabled:
            return

        PIPEWIRE_SOCKET_NAME = 'pipewire-0'
        original_socket_path = (Path(BaseDirectory.get_runtime_dir()) /
                                PIPEWIRE_SOCKET_NAME)

        new_socket_path = self.xdg_runtime_dir / 'pipewire-0'

        yield ReadOnlyBind(original_socket_path, new_socket_path)
Ejemplo n.º 7
0
    def __init__(self):
        self.key_sequence = KeySequence()
        self.nag_interval = 300
        self.nag_header = '\nReminders:'
        self.use_git = True

        os.environ.pop('GIT_DIR', None)

        # for path in xdgbase.load_config_paths(APP_NAME, 'config.py'):
        #   with file(path) as stream:
        #     exec stream in self.__dict__

        self.nag_home = xdgbase.save_config_path(APP_NAME)
        self.nag_file_dir = xdgbase.save_config_path(APP_NAME, 'files')
        self.runtime = os.path.join(xdgbase.get_runtime_dir(), APP_NAME)
        self.timestamp = os.path.join(self.runtime, 'timestamp')
Ejemplo n.º 8
0
Archivo: nag.py Proyecto: johnw42/nag
  def __init__(self):
    self.key_sequence = KeySequence()
    self.nag_interval = 300
    self.nag_header = '\nReminders:'
    self.use_git = True

    os.environ.pop('GIT_DIR', None)

    # for path in xdgbase.load_config_paths(APP_NAME, 'config.py'):
    #   with file(path) as stream:
    #     exec stream in self.__dict__

    self.nag_home = xdgbase.save_config_path(APP_NAME)
    self.nag_file_dir = xdgbase.save_config_path(APP_NAME, 'files')
    self.runtime = os.path.join(xdgbase.get_runtime_dir(), APP_NAME)
    self.timestamp = os.path.join(self.runtime, 'timestamp')
Ejemplo n.º 9
0
    def __iter__(self) -> ServiceGeneratorType:
        if not self.enabled:
            return

        try:
            wayland_display_env = environ['WAYLAND_DISPLAY']
        except KeyError:
            print("No wayland display.")

        for x in XDG_DESKTOP_VARS:
            if x in environ:
                yield EnvrimentalVar(x)

        yield EnvrimentalVar('GDK_BACKEND', 'wayland')
        yield EnvrimentalVar('MOZ_DBUS_REMOTE', '1')
        yield EnvrimentalVar('MOZ_ENABLE_WAYLAND', '1')

        yield EnvrimentalVar('WAYLAND_DISPLAY', 'wayland-0')
        original_socket_path = (Path(BaseDirectory.get_runtime_dir()) /
                                wayland_display_env)

        new_socket_path = Path('/run/user/1000') / 'wayland-0'
        yield Bind(str(original_socket_path), str(new_socket_path))
        yield from generate_toolkits()
Ejemplo n.º 10
0
    def __init__(self,
                 server=None,
                 palette='default',
                 keymap='default',
                 path=None):
        self.path = self.verifyConfigFile(path)

        self.config = yaml.safe_load(open(self.path))
        schema = ConfigSchema().getSchema(self.config)
        schema(self.config)
        server = self.getServer(server)
        self.server = server
        api_url = server.get('api_url', 'https://api.github.com/')
        if not api_url.endswith('/'):
            api_url += '/'
        self.api_url = api_url
        url = server.get('url', 'https://github.com/')
        if not url.endswith('/'):
            url += '/'
        self.url = url
        self.token = self.getToken(server['name'], url)
        self.git_root = os.path.expanduser(server['git-root'])
        git_url = server.get('git-url', 'https://github.com/')
        if not git_url.endswith('/'):
            git_url += '/'
        self.git_url = git_url
        data_path = BaseDirectory.save_data_path('hubtty')
        runtime_path = BaseDirectory.get_runtime_dir(strict=False)
        self.dburi = server.get(
            'dburi', 'sqlite:///' + os.path.join(data_path, 'hubtty.db'))
        socket_path = server.get('socket',
                                 os.path.join(runtime_path, 'hubtty.sock'))
        self.socket_path = os.path.expanduser(socket_path)
        log_file = server.get('log-file', os.path.join(data_path,
                                                       'hubtty.log'))
        self.log_file = os.path.expanduser(log_file)
        lock_file = server.get(
            'lock-file',
            os.path.join(runtime_path, 'hubtty.%s.lock' % server['name']))
        self.lock_file = os.path.expanduser(lock_file)

        self.additional_repositories = server.get('additional-repositories',
                                                  [])

        self.palettes = {
            'default': hubtty.palette.Palette({}),
            'light': hubtty.palette.Palette(hubtty.palette.LIGHT_PALETTE),
        }
        for p in self.config.get('palettes', []):
            if p['name'] not in self.palettes:
                self.palettes[p['name']] = hubtty.palette.Palette(p)
            else:
                self.palettes[p['name']].update(p)
        self.palette = self.palettes[self.config.get('palette', palette)]

        self.keymaps = {
            'default': hubtty.keymap.KeyMap({}),
            'vi': hubtty.keymap.KeyMap(hubtty.keymap.VI_KEYMAP)
        }
        for p in self.config.get('keymaps', []):
            if p['name'] not in self.keymaps:
                self.keymaps[p['name']] = hubtty.keymap.KeyMap(p)
            else:
                self.keymaps[p['name']].update(p)
        self.keymap = self.keymaps[self.config.get('keymap', keymap)]

        self.commentlinks = [
            hubtty.commentlink.CommentLink(c)
            for c in self.config.get('commentlinks', [])
        ]
        self.commentlinks.append(
            hubtty.commentlink.CommentLink(
                dict(match="(?P<url>https?://\\S*)",
                     replacements=[dict(link=dict(text="{url}", url="{url}"))
                                   ])))

        self.repository_pr_list_query = self.config.get(
            'pr-list-query', 'state:open')

        self.diff_view = self.config.get('diff-view', 'side-by-side')

        self.dashboards = OrderedDict()
        for d in self.config.get('dashboards', []):
            self.dashboards[d['key']] = d
            self.dashboards[d['key']]

        self.reviewkeys = OrderedDict()
        for k in self.config.get('reviewkeys', []):
            self.reviewkeys[k['key']] = k

        self.hide_comments = []
        for h in self.config.get('hide-comments', []):
            self.hide_comments.append(re.compile(h['author']))

        # self.thread_prs = self.config.get('thread-prs', True)
        self.utc = self.config.get('display-times-in-utc', False)
        self.breadcrumbs = self.config.get('breadcrumbs', True)
        self.close_pr_on_review = self.config.get('close-pr-on-review', False)
        self.handle_mouse = self.config.get('handle-mouse', True)

        pr_list_options = self.config.get('pr-list-options', {})
        self.pr_list_options = {
            'sort-by': pr_list_options.get('sort-by', 'number'),
            'reverse': pr_list_options.get('reverse', False)
        }

        self.expire_age = self.config.get('expire-age', '2 months')

        self.size_column = self.config.get('size-column', {})
        self.size_column['type'] = self.size_column.get('type', 'graph')
        if self.size_column['type'] == 'graph':
            self.size_column['thresholds'] = self.size_column.get(
                'thresholds', [1, 10, 100, 1000])
        else:
            self.size_column['thresholds'] = self.size_column.get(
                'thresholds', [1, 10, 100, 200, 400, 600, 800, 1000])
Ejemplo n.º 11
0
 def test_runtime_dir(self):
     rd = '/pyxdg-example/run/user/fred'
     environ['XDG_RUNTIME_DIR'] = rd
     self.assertEqual(BaseDirectory.get_runtime_dir(strict=True), rd)
     self.assertEqual(BaseDirectory.get_runtime_dir(strict=False), rd)
Ejemplo n.º 12
0
def get_user_runtime_dir():
    try:
        return basedir.get_runtime_dir()
    except KeyError:
        import tempfile
        return tempfile.mkdtemp()
Ejemplo n.º 13
0
 def test_runtime_dir(self):
     rd = '/pyxdg-example/run/user/fred'
     environ['XDG_RUNTIME_DIR'] = rd
     self.assertEqual(BaseDirectory.get_runtime_dir(strict=True), rd)
     self.assertEqual(BaseDirectory.get_runtime_dir(strict=False), rd)