-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy path__init__.py
More file actions
executable file
·64 lines (51 loc) · 2.76 KB
/
Copy path__init__.py
File metadata and controls
executable file
·64 lines (51 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
import os
import sys
import argparse
import configparser
from Base.activity_store import ActivityStore
from Base import config as cfg
def parse_config():
conf_parser = argparse.ArgumentParser(description=__doc__, add_help=False,
formatter_class=argparse.RawDescriptionHelpFormatter)
conf_parser.add_argument("-c", "--config",
help="Config file with defaults. Command line parameters will override those given in the config file. The config file must start with a \"[Defaults]\" section, followed by [argument]=[value] on each line.", metavar="FILE")
args, remaining_argv = conf_parser.parse_known_args()
defaults = {}
if args.config:
if not os.path.exists(args.config):
raise EnvironmentError(f"Config file {args.config} doesn't exist.")
config = configparser.ConfigParser()
config.read([args.config])
defaults = dict(config.items('Defaults'))
else:
if os.path.exists(os.path.expanduser('~/.Base/Base.conf')):
config = configparser.ConfigParser()
config.read([os.path.expanduser('~/.Base/Base.conf')])
defaults = dict(config.items('Defaults'))
parser = argparse.ArgumentParser(description='Monitor your computer activities and store them in a database for later analysis or disaster recovery.', parents=[conf_parser])
parser.set_defaults(**defaults)
parser.add_argument('-d', '--data-dir', help=f'Data directory for Base, where the database is stored. Remember that Base must have read/write access. Default is {cfg.DATA_DIR}', default=cfg.DATA_DIR)
parser.add_argument('-n', '--no-text', action='store_true', help='Do not store what you type. This will make your database smaller and less sensitive to security breaches. Process name, window titles, window geometry, mouse clicks, number of keys pressed and key timings will still be stored, but not the actual letters. Key timings are stored to enable activity calculation in selfstats.')
parser.add_argument('-r', '--no-repeat', action='store_true', help='Do not store special characters as repeated characters.')
return parser.parse_args()
def main():
try:
args = vars(parse_config())
except EnvironmentError as e:
print(str(e))
sys.exit(1)
args['data_dir'] = os.path.expanduser(args['data_dir'])
try:
os.makedirs(args['data_dir'])
except OSError:
pass
astore = ActivityStore(os.path.join(args['data_dir'], cfg.DBNAME),
store_text=(not args['no_text']),
repeat_char=(not args['no_repeat']))
try:
astore.run()
except KeyboardInterrupt:
astore.close()
if __name__ == '__main__':
main()