-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
73 lines (56 loc) · 1.87 KB
/
__main__.py
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
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import logging
from argparse import ArgumentParser
import traceback
import pyfuse3
import trio
from .canvas_fs import CanvasFs
from .utilities import Context
try: import faulthandler
except ImportError: pass
else: faulthandler.enable()
log = logging.getLogger(__name__)
def init_logging(debug=False):
formatter = logging.Formatter(
'%(asctime)s.%(msecs)03d %(threadName)s: '
'[%(name)s] %(message)s', datefmt='%Y-%m-%d %H:%M:%S'
)
handler = logging.StreamHandler()
handler.setFormatter(formatter)
root_logger = logging.getLogger()
if debug:
handler.setLevel(logging.DEBUG)
root_logger.setLevel(logging.DEBUG)
else:
handler.setLevel(logging.INFO)
root_logger.setLevel(logging.INFO)
root_logger.addHandler(handler)
def parse_args():
parser = ArgumentParser(allow_abbrev=False)
parser.add_argument('context_id', type=int, help='the ID of the context to be mounted')
parser.add_argument('mountpoint', type=str, help='path to mount the FS at')
parser.add_argument('-c', '--context', choices=['course', 'user', 'group'], default='course', help='canvas context type')
parser.add_argument('--debug', action='store_true', default=False, help='enable debugging output')
parser.add_argument('--debug-fuse', action='store_true', default=False, help='enable FUSE debugging output')
return parser.parse_args()
def main():
options = parse_args()
init_logging(options.debug)
context = Context(options.context + 's')
canvas_fs = CanvasFs(options.context_id, context)
fuse_options = set(pyfuse3.default_options)
fuse_options.add('fsname=canvasfs')
if options.debug_fuse:
fuse_options.add('debug')
pyfuse3.init(canvas_fs, options.mountpoint, fuse_options)
try:
trio.run(pyfuse3.main)
except KeyboardInterrupt:
pyfuse3.close()
except:
traceback.print_exc()
pyfuse3.close()
exit(1)
if __name__ == '__main__':
main()