Skip to content

Commit 78fd23c

Browse files
committed
Fixed CLI
2 parents fb3d7b7 + a030dd0 commit 78fd23c

File tree

22 files changed

+212
-218
lines changed

22 files changed

+212
-218
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# .travis.yml: Configuration for Travis CI build test
66
#
7-
# Copyright (C) 2017 Sebastian M. Ernst <[email protected]>
7+
# Copyright (C) 2017-2018 Sebastian M. Ernst <[email protected]>
88
#
99
# <LICENSE_BLOCK>
1010
# The contents of this file are subject to the Apache License

CHANGES.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Changes
22
=======
33

4-
0.0.1 (2017-XX-XX)
4+
0.0.1 (2018-XX-XX)
55
------------------
66

77
* TBD

README.rst

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,29 @@
1111
LoggedFS-python - Filesystem monitoring with Fuse and Python
1212
============================================================
1313

14-
**PROJECT STATUS IS BETA** (UNDER DEVELOPMENT).
14+
PROJECT STATUS NOTICE: **BETA** (UNDER DEVELOPMENT)
15+
---------------------------------------------------
1516

16-
FILESYSTEM PASSES `TEST SUITE FOR POSIX COMPLIANCE`_ - (ALL) EXCEPTIONS:
17+
FILESYSTEM PASSES `TEST SUITE FOR POSIX COMPLIANCE`_ - WITH ONE EXCEPTION:
1718

18-
- UPDATING *ATIME* AND *MTIME* FAILS UNDER CERTAIN CIRCUMSTANCES DUE TO BUGS IN LIBFUSE2. TWO TESTS WHICH FAIL BECAUSE OF IT ARE THEREFORE IGNORED.
19+
- UPDATING *ATIME* AND *MTIME* FAILS UNDER CERTAIN CIRCUMSTANCES.
20+
THE ROOT SOURCE CAN LIKELY BE FOUND IN LIBFUSE **2**.
21+
THIS IS UNDER FURTHER INVESTIGATION.
22+
TWO TESTS WHICH FAIL BECAUSE OF IT ARE THEREFORE CURRENTLY BEING IGNORED.
1923

20-
A CUSTOM BUG-FIXED VERSION OF `FUSEPY`_ IS REQUIRED.
24+
A CUSTOM BUG-FIXED VERSION OF `FUSEPY`_ IS REQUIRED FOR FULL POSIX COMPLIANCE.
25+
IF THE LATEST OFFICIAL RELEASE OF FUSEPY IS USED INSTEAD, TIMESTAMPS WILL BE
26+
INACCURATE ON A NANOSECOND TO MICROSECOND SCALE.
27+
THERE IS A `PENDING PULL REQUEST`_.
28+
29+
THE FILESYSTEM HAS YET **NOT** BEEN **STRESS-TESTED**.
2130

2231
THE FILESYSTEM IS CURRENTLY **ONLY** BEING DEVELOPED FOR AND TESTED ON **LINUX**.
2332
ANYONE INTERESTED IN ADDING MACOS AND/OR BSD SUPPORT?
2433

25-
BESIDES, CLI SWITCHES ARE NOT FULLY TESTED. THERE ARE ODD EDGE CASES ...
26-
2734
.. _FUSEPY: https://github.com/s-m-e/fusepy
2835
.. _TEST SUITE FOR POSIX COMPLIANCE: https://github.com/pjd/pjdfstest
36+
.. _PENDING PULL REQUEST: https://github.com/terencehonles/fusepy/pull/76
2937

3038
Description
3139
-----------
@@ -113,14 +121,14 @@ Just use that command:
113121
114122
loggedfs -f -p /var
115123
116-
You should see logs like these :
124+
You should see logs like these:
117125

118126
::
119127

120128
tail -f /var/log/syslog
121129
2017-12-09 17:29:34,910 (loggedfs-python) LoggedFS-python running as a public filesystem
122130
2017-12-09 17:29:34,915 (loggedfs-python) LoggedFS-python not running as a daemon
123-
2017-12-09 17:29:34,920 (loggedfs-python) LoggedFS-python starting at /var.
131+
2017-12-09 17:29:34,920 (loggedfs-python) LoggedFS-python starting at /var
124132
2017-12-09 17:29:34,950 (loggedfs-python) chdir to /var
125133
2017-12-09 17:29:35,246 (loggedfs-python) getattr /var/ {SUCCESS} [ pid = 8700 kded [kdeinit] uid = 1000 ]
126134
2017-12-09 17:29:41,841 (loggedfs-python) getattr /var/ {SUCCESS} [ pid = 10923 ls uid = 1000 ]
@@ -133,7 +141,7 @@ If you have a configuration file to use you should use this command:
133141

134142
.. code:: bash
135143
136-
./loggedfs -c loggedfs.xml -p /var
144+
loggedfs -c loggedfs.xml -p /var
137145
138146
If you want to log what other users do on your filesystem, you should use the
139147
``-p`` option to allow them to see your mounted files. For a complete

makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# makefile: GNU makefile for project management
66
#
7-
# Copyright (C) 2017 Sebastian M. Ernst <[email protected]>
7+
# Copyright (C) 2017-2018 Sebastian M. Ernst <[email protected]>
88
#
99
# <LICENSE_BLOCK>
1010
# The contents of this file are subject to the Apache License
@@ -61,11 +61,7 @@ test:
6161
-rm tests/loggedfs_libtest/__pycache__/*.pyc
6262
# USAGE: make test T="-T chmod/01.t -T chmod/02.t"
6363
# REFERENCE TEST WITH EXT4: make test T="-M ext4"
64-
# pytest -M ext4
6564
pytest $(T)
6665

67-
# test_freeze:
68-
# python3 -c 'import sys; import os; sys.path.append(os.path.join(os.getcwd(), "tests")); import loggedfs_libtest; loggedfs_libtest.freeze_results()'
69-
7066
umount:
7167
python3 -c 'import sys; import os; sys.path.append(os.path.join(os.getcwd(), "tests")); import loggedfs_libtest; loggedfs_libtest.quick_cli_umount()'

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
setup.py: Used for package distribution
1010
11-
Copyright (C) 2017 Sebastian M. Ernst <[email protected]>
11+
Copyright (C) 2017-2018 Sebastian M. Ernst <[email protected]>
1212
1313
<LICENSE_BLOCK>
1414
The contents of this file are subject to the Apache License

src/loggedfs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
src/loggedfs/__init__.py: Module init
1010
11-
Copyright (C) 2017 Sebastian M. Ernst <[email protected]>
11+
Copyright (C) 2017-2018 Sebastian M. Ernst <[email protected]>
1212
1313
<LICENSE_BLOCK>
1414
The contents of this file are subject to the Apache License

src/loggedfs/cli.py

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
src/loggedfs/cli.py: Command line interface
1010
11-
Copyright (C) 2017 Sebastian M. Ernst <[email protected]>
11+
Copyright (C) 2017-2018 Sebastian M. Ernst <[email protected]>
1212
1313
<LICENSE_BLOCK>
1414
The contents of this file are subject to the Apache License
@@ -29,7 +29,7 @@
2929
# IMPORT
3030
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3131

32-
from pprint import pformat as pf
32+
from collections import OrderedDict
3333

3434
from .core import loggedfs_factory
3535

@@ -57,18 +57,22 @@
5757
type = click.File(mode = 'r'),
5858
help = 'Use the "config-file" to filter what you want to log.'
5959
)
60+
@click.option(
61+
'-s',
62+
is_flag = True,
63+
help = 'Deactivate logging to syslog.'
64+
)
6065
@click.option(
6166
'-l',
6267
# type = click.File(mode = 'a'),
6368
type = click.Path(file_okay = True, dir_okay = False, resolve_path = True),
64-
help = ('Use the "log-file" to write logs to. If no log file is specified'
65-
'then logs are only written to syslog or to stdout, depending on -f.')
69+
help = ('Use the "log-file" to write logs to.')
6670
)
6771
@click.argument(
6872
'directory',
6973
type = click.Path(exists = True, file_okay = False, dir_okay = True, resolve_path = True)
7074
)
71-
def cli_entry(f, p, c, l, directory):
75+
def cli_entry(f, p, c, s, l, directory):
7276
"""LoggedFS-python is a transparent fuse-filesystem which allows to log
7377
every operations that happens in the backend filesystem. Logs can be written
7478
to syslog, to a file, or to the standard output. LoggedFS comes with an XML
@@ -78,31 +82,59 @@ def cli_entry(f, p, c, l, directory):
7882
filters are regular expressions.
7983
"""
8084

81-
click.echo(pf((
82-
f, p, c, l, directory
83-
)))
84-
8585
loggedfs_factory(
8686
directory,
87-
no_daemon_bool = f,
88-
allow_other = p,
89-
loggedfs_param_dict = __process_config__(c, f),
90-
log_file = l
87+
**__process_config__(c, l, s, f, p)
9188
)
9289

9390

94-
def __process_config__(config_fh, no_daemon_bool):
95-
96-
def __process_xml__(in_xml):
97-
return xmltodict.parse(in_xml)['loggedFS']
98-
91+
def __process_config__(
92+
config_fh,
93+
log_file,
94+
log_syslog_off,
95+
fuse_foreground_bool,
96+
fuse_allowother_bool
97+
):
98+
99+
def proc_filter_item(in_item):
100+
return {
101+
'extension': in_item['@extension'],
102+
'uid': in_item['@uid'],
103+
'action': in_item['@action'],
104+
'retname': in_item['@retname']
105+
}
106+
107+
def proc_filter_list(in_list):
108+
if in_list is None:
109+
return []
110+
if not isinstance(in_list, list):
111+
return [proc_filter_item(in_list)]
112+
return [proc_filter_item(item) for item in in_list]
113+
114+
config_dict = OrderedDict({
115+
'@logEnabled': True,
116+
'@printProcessName': True,
117+
'includes': [],
118+
'excludes': []
119+
})
120+
121+
config_file = None
99122
if config_fh is not None:
100-
param = __process_xml__(config_fh.read())
101-
elif False: # TODO check /etc
102-
param = {} # TODO fetch from /etc
103-
else:
104-
param = {}
105-
106-
param.update({'daemon': not no_daemon_bool})
107-
108-
return param
123+
config_file = config_fh.name
124+
config_dict.update(xmltodict.parse(config_fh.read())['loggedFS'])
125+
config_fh.close()
126+
127+
for f_type in ['includes', 'excludes']:
128+
config_dict[f_type] = proc_filter_list(config_dict[f_type][f_type[:-1]])
129+
130+
return {
131+
'log_includes': config_dict['includes'],
132+
'log_excludes': config_dict['excludes'],
133+
'log_file': log_file,
134+
'log_syslog': not log_syslog_off,
135+
'log_configmsg': 'LoggedFS-python using configuration file %s' % config_file,
136+
'log_enabled': config_dict['@logEnabled'],
137+
'log_printprocessname': config_dict['@printProcessName'],
138+
'fuse_foreground_bool': fuse_foreground_bool,
139+
'fuse_allowother_bool': fuse_allowother_bool
140+
}

0 commit comments

Comments
 (0)