def test_valid_specifiers(*, user):
    test_content('f {} - - - - two words', 'two words', user=user)
    if id128:
        try:
            test_content('f {} - - - - %m',
                         '{}'.format(id128.get_machine().hex),
                         user=user)
        except AssertionError as e:
            print(e)
            print('/etc/machine-id: {!r}'.format(
                open('/etc/machine-id').read()))
            print('/proc/cmdline: {!r}'.format(open('/proc/cmdline').read()))
            print('skipping')
        test_content('f {} - - - - %b',
                     '{}'.format(id128.get_boot().hex),
                     user=user)
    test_content('f {} - - - - %H',
                 '{}'.format(socket.gethostname()),
                 user=user)
    test_content('f {} - - - - %v', '{}'.format(os.uname().release), user=user)
    test_content('f {} - - - - %U', '{}'.format(os.getuid()), user=user)
    test_content('f {} - - - - %G', '{}'.format(os.getgid()), user=user)

    puser = pwd.getpwuid(os.getuid())
    test_content('f {} - - - - %u', '{}'.format(puser.pw_name), user=user)

    pgroup = grp.getgrgid(os.getgid())
    test_content('f {} - - - - %g', '{}'.format(pgroup.gr_name), user=user)

    # Note that %h is the only specifier in which we look the environment,
    # because we check $HOME. Should we even be doing that?
    home = os.path.expanduser("~")
    test_content('f {} - - - - %h', '{}'.format(home), user=user)

    xdg_runtime_dir = os.getenv('XDG_RUNTIME_DIR')
    if xdg_runtime_dir is not None or not user:
        test_content('f {} - - - - %t',
                     xdg_runtime_dir if user else '/run',
                     user=user)

    xdg_config_home = os.getenv('XDG_CONFIG_HOME')
    if xdg_config_home is not None or not user:
        test_content('f {} - - - - %S',
                     xdg_config_home if user else '/var/lib',
                     user=user)

    xdg_cache_home = os.getenv('XDG_CACHE_HOME')
    if xdg_cache_home is not None or not user:
        test_content('f {} - - - - %C',
                     xdg_cache_home if user else '/var/cache',
                     user=user)

    if xdg_config_home is not None or not user:
        test_content('f {} - - - - %L',
                     xdg_config_home + '/log' if user else '/var/log',
                     user=user)

    test_content('f {} - - - - %%', '%', user=user)
def test_valid_specifiers(*, user):
    test_content('f {} - - - - two words', 'two words', user=user)
    if id128:
        try:
            test_content('f {} - - - - %m', '{}'.format(id128.get_machine().hex), user=user)
        except AssertionError as e:
            print(e)
            print('/etc/machine-id: {!r}'.format(open('/etc/machine-id').read()))
            print('/proc/cmdline: {!r}'.format(open('/proc/cmdline').read()))
            print('skipping')
        test_content('f {} - - - - %b', '{}'.format(id128.get_boot().hex), user=user)
    test_content('f {} - - - - %H', '{}'.format(socket.gethostname()), user=user)
    test_content('f {} - - - - %v', '{}'.format(os.uname().release), user=user)
    test_content('f {} - - - - %U', '{}'.format(os.getuid()), user=user)
    test_content('f {} - - - - %G', '{}'.format(os.getgid()), user=user)

    puser = pwd.getpwuid(os.getuid())
    test_content('f {} - - - - %u', '{}'.format(puser.pw_name), user=user)

    pgroup = grp.getgrgid(os.getgid())
    test_content('f {} - - - - %g', '{}'.format(pgroup.gr_name), user=user)

    # Note that %h is the only specifier in which we look the environment,
    # because we check $HOME. Should we even be doing that?
    home = os.path.expanduser("~")
    test_content('f {} - - - - %h', '{}'.format(home), user=user)

    xdg_runtime_dir = os.getenv('XDG_RUNTIME_DIR')
    if xdg_runtime_dir is not None or not user:
        test_content('f {} - - - - %t',
                     xdg_runtime_dir if user else '/run',
                     user=user)

    xdg_config_home = os.getenv('XDG_CONFIG_HOME')
    if xdg_config_home is not None or not user:
        test_content('f {} - - - - %S',
                     xdg_config_home if user else '/var/lib',
                     user=user)

    xdg_cache_home = os.getenv('XDG_CACHE_HOME')
    if xdg_cache_home is not None or not user:
        test_content('f {} - - - - %C',
                     xdg_cache_home if user else '/var/cache',
                     user=user)

    if xdg_config_home is not None or not user:
        test_content('f {} - - - - %L',
                     xdg_config_home + '/log' if user else '/var/log',
                     user=user)

    test_content('f {} - - - - %%', '%', user=user)
Beispiel #3
0
 def get_matching_events(self, boot_id=None):
     #print(self._reader.query_unique('_BOOT_ID'))
     if not boot_id:
         boot_id = get_boot()
     last_monotonic = self._last_monotonic()
     self._reader.seek_monotonic(last_monotonic)
     if self._multiline_match:
         for match in self._next_multiline_match():
             last_monotonic = match[-1]['__MONOTONIC_TIMESTAMP'][0]
             print( match[0]['__REALTIME_TIMESTAMP'])
             for line in match:
                 print(line['_BOOT_ID'], line['MESSAGE'])
     self._state[str(boot_id)] = last_monotonic.total_seconds()
     self._dump_state()
 def get_matching_events(self, boot_id=None):
     r = []
     if not boot_id:
         boot_id = get_boot()
     last_monotonic = self._last_monotonic()
     self._reader.seek_monotonic(last_monotonic)
     if self._multiline_match:
         for match in self._next_multiline_match():
             last_monotonic = match[-1]['__MONOTONIC_TIMESTAMP'][0]
             r.append(match)
     if self._process:
         self._state[str(boot_id)] = last_monotonic.total_seconds()
     self._dump_state()
     return r
Beispiel #5
0
 def _last_monotonic(self, boot_id=None):
     if not boot_id:
         boot_id = get_boot()
     return timedelta(0, self._state.get(str(boot_id), 0))
Beispiel #6
0
def test_get_boot():
    u1 = id128.get_boot()
    u2 = id128.get_boot()
    assert u1 == u2