-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
66 lines (47 loc) · 1.72 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
import logging
import os
from argparse import ArgumentParser
import trio
import pyfuse3
import faulthandler
from library_info import PhotoLibrary
from photo_fs import PhotoFS
faulthandler.enable()
def parse_args():
parser = ArgumentParser()
parser.add_argument('photolibrary', type=str,
help='The .photoslibrary file to mount')
parser.add_argument('mountpoint', type=str,
help='Where to mount the file system')
parser.add_argument('--debug', action='store_true', default=False,
help='Enable debug logging')
parser.add_argument('--fuse-debug', action='store_true', default=False,
help='Enable FUSE debug logging')
return parser.parse_args()
def main():
options = parse_args()
# Build the photo library from the file
library = PhotoLibrary(options.photolibrary)
# Set the log level depending on the flags
log_level = 'DEBUG' if options.debug else 'INFO'
logging.basicConfig(level=os.environ.get('LOGLEVEL', log_level))
print(f'Parsed photo library with {len(library.assets)} unique assets')
print(f'Mounting photo library to {options.mountpoint}...')
# Create and run the file system
filesystem = PhotoFS(library)
fuse_options = set(pyfuse3.default_options)
fuse_options.add('fsname=PhotoLibrary')
# Set up fuse debugging if requested
if options.fuse_debug:
fuse_options.add('debug')
pyfuse3.init(filesystem, options.mountpoint, fuse_options)
print('Mounted!')
try:
trio.run(pyfuse3.main)
except:
pyfuse3.close(unmount=False)
raise
pyfuse3.close()
print('Unmounted filesystem')
if __name__ == '__main__':
main()