-
Notifications
You must be signed in to change notification settings - Fork 0
/
rardirfs
executable file
·84 lines (73 loc) · 3.07 KB
/
rardirfs
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
77
78
79
80
81
82
83
84
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2009, Jonas Jonsson <jonas@websystem.se>
# All rights reserved.
#
# See file LICENSE for license details
#
import sys
import os
import subprocess
from RarDirFs import rardirfs
from optparse import OptParseError, OptionParser
import fuse
def unrar_available():
'''
Check if unrar is available by calling it.
'''
try:
subprocess.call('unrar', stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
return True
except OSError:
return False
def main():
usage = "%prog srcdir mountpoint [options]"
desc ="""Mount a directory read-only with all rar archives "unpacked". Only uncompressed archives are supported."""
rarDirFs = rardirfs.RarDirFs(version="%prog 0.1", usage=usage,
description=desc, dash_s_do='setsingle')
rarDirFs.parser.add_option(mountopt="only_first", metavar="OPT",
default="auto", type="choice", choices=['yes', 'no', 'auto'],
help="show only first file in archive: yes, no, auto [default: %default]")
rarDirFs.parser.add_option(mountopt="filter", metavar="FILE",
default="/etc/rardirfs/filter",
help="hide files matching pattern in FILE [default: %default]")
rarDirFs.parser.add_option(mountopt="flatten", metavar="FILE",
default="/etc/rardirfs/flatten",
help="flatten directories matching pattern in FILE [default: %default]")
rarDirFs.parser.add_option(mountopt="cache_path", metavar="PATH",
default="/var/cache/rardirfs",
help="store files from compressed archives in PATH. [default: %default]")
rarDirFs.parser.add_option(mountopt="disable_unrar", dest="enable_unrar", action="store_false",
help="disable support for compressed archives")
rarDirFs.parse(values=rarDirFs, errex=1)
(options, args) = rarDirFs.cmdline
# Add default options
if not options.filter and os.path.isfile("/etc/rardirfs/filter"):
options.filter = "/etc/rardirfs/filter"
if not options.flatten and os.path.isfile("/etc/rardirfs/flatten"):
options.flatten = "/etc/rardirfs/flatten"
if not options.only_first:
options.only_first = 'auto'
if not options.cache_path:
options.cache_path = '/var/cache/rardirfs'
if options.enable_unrar == None:
options.enable_unrar = unrar_available()
options.cache_path = os.path.abspath(options.cache_path)
if rarDirFs.fuse_args.mount_expected():
if len(args) != 1:
OptionParser.error(rarDirFs.parser, "missing srcdir")
elif not os.path.isdir(args[0]):
OptionParser.error(rarDirFs.parser,
"bad srcdir {0}, not a directory.".format(args[0]))
else:
rarDirFs.srcdir = os.path.abspath(args[0])
if not options.only_first in ('yes', 'no', 'auto'):
OptionParser.error(rarDirFs.parser, 'only yes, no and auto is valid arguments to only_first')
try:
rarDirFs.main()
except fuse.FuseError, e:
print e
sys.exit(1)
if __name__ == '__main__':
main()