forked from xedakini/replicator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParams.py
83 lines (77 loc) · 2.59 KB
/
Params.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
74
75
76
77
78
79
80
81
82
83
import sys, os, socket
_args = iter( sys.argv )
PROG = _args.next()
PORT = 8080
ROOT = os.getcwd() + os.sep
VERBOSE = 0
TIMEOUT = 15
FAMILY = socket.AF_INET
FLAT = False
STATIC = False
ONLINE = True
LIMIT = False
LOG = False
DEBUG = False
MAXCHUNK = 1448 # maximum lan packet?
TIMEFMT = ('%a, %d %b %Y %H:%M:%S GMT', '%a, %d %b %Y %H:%M:%S +0000 GMT', '%a, %d %b %Y %H:%M:%S +0000')
SUFFIX = '.incomplete'
USAGE = '''usage: %(PROG)s [options]
options:
-h --help show this help message and exit
-p --port PORT listen on this port for incoming connections, default %(PORT)i
-r --root DIR set cache root directory, default current: %(ROOT)s
-v --verbose show http headers and other info
-t --timeout SEC break connection after so many seconds of inactivity, default %(TIMEOUT)i
-6 --ipv6 try ipv6 addresses if available
--flat flat mode; cache all files in root directory (dangerous!)
--static static mode; assume files never change
--offline offline mode; never connect to server
--limit RATE limit download rate at a fixed K/s
--daemon LOG route output to log and detach
--debug switch from gather to debug output module''' % locals()
for _arg in _args:
if _arg in ( '-h', '--help' ):
sys.exit( USAGE )
elif _arg in ( '-p', '--port' ):
try:
PORT = int( _args.next() )
assert PORT > 0
except:
sys.exit( 'Error: %s requires a positive numerical argument' % _arg )
elif _arg in ( '-r', '--root' ):
try:
ROOT = os.path.realpath( _args.next() ) + os.sep
assert os.path.isdir( ROOT )
except StopIteration:
sys.exit( 'Error: %s requires a directory argument' % _arg )
except:
sys.exit( 'Error: invalid cache directory %s' % ROOT )
elif _arg in ( '-v', '--verbose' ):
VERBOSE += 1
elif _arg in ( '-t', '--timeout' ):
try:
TIMEOUT = int( _args.next() )
assert TIMEOUT > 0
except:
sys.exit( 'Error: %s requires a positive numerical argument' % _arg )
elif _arg in ( '-6', '--ipv6' ):
FAMILY = socket.AF_UNSPEC
elif _arg == '--flat':
FLAT = True
elif _arg == '--static':
STATIC = True
elif _arg == '--offline':
ONLINE = False
STATIC = True
elif _arg == '--limit':
try:
LIMIT = float( _args.next() ) * 1024
except:
sys.exit( 'Error: %s requires a numerical argument' % _arg )
elif _arg == '--daemon':
LOG = _args.next()
elif _arg == '--debug':
DEBUG = True
else:
sys.exit( 'Error: invalid option %r' % _arg )
MAXFILELEN = os.pathconf( ROOT, 'PC_NAME_MAX' ) - len(SUFFIX)