aboutsummaryrefslogtreecommitdiffstats
path: root/fusearchive.py
blob: 624cc3c7b452de681a961d43f7df321b0a9d6dcf (plain)
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
74
75
76
#!/usr/bin/env python

#  FuseArchive:
#    Copyright (C) 2009  Steve Slaven  <bpk@hoopajoo.net>
#
#    This program can be distributed under the terms of the GNU GPL.
#    See the file COPYING.
#

import logging, sys, os, fuse
import FuseArchive

enable_stats = False
enable_psyco = False

if enable_psyco:
    # Import Psyco if available
    try:
        import psyco
        psyco.full()
    except ImportError:
        pass

def main():
    usage = """
    Userspace filesystem that uses chunks to eliminate multiple copies of parts
    of files for long term storage

    """ + fuse.Fuse.fusage

    server = FuseArchive.FileSystem(version="%prog " + fuse.__version__,
                    usage=usage,
                    dash_s_do='setsingle')

    server.multithreaded = False

    server.parse(values=server, errex=1)

    if server.parser.largs == None or len(server.parser.largs) != 2:
        print "Usage: " + sys.argv[0] + " storageDirectory mountDirectory"
        sys.exit(1)

    log_level = logging.WARNING
    # If debug is in the assembed opts then enable our debug too
    if server.fuse_args.assemble()[ -1 ].find( 'debug' ) != -1:
        log_level = logging.DEBUG
    else:
        # Null-out the logging.debug statement, otherwise it's a top-3 cpu
        # eater in stat profiling
        logging.debug = lambda x: 1

    logging.basicConfig( level = log_level,
                        format = '%(asctime)s %(levelname)s %(filename)s:%(lineno)d %(module)s:%(funcName)s() %(message)s',
                        stream = sys.stderr,
                        filemode = 'w' )

    # Get backing store directory
    server.root = server.parser.largs[0]

    try:
        if server.fuse_args.mount_expected():
            os.chdir(server.root)
    except OSError:
        print >> sys.stderr, "can't enter root of underlying filesystem"
        sys.exit(1)

    server.main()

if enable_stats:
    import cProfile
    print "Note:stats are in the server root, not the caller cwd()"
    cProfile.run( 'main()', "fusearchive_stats" )
else:
    main()