aboutsummaryrefslogtreecommitdiffstats
path: root/fusearchive.py
blob: ab13f0dbc9808b059d6c220c2dd667be9cfd255e (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
#!/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

if enable_stats:
    import hotshot
    prof = hotshot.Profile( "fusearchive_stats" )
    prof.runcall()
    prof.close()

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
print server.fuse_args.assemble()
if ' '.join( server.fuse_args.assemble() ).find( 'debug' ):
    log_level = logging.DEBUG

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()