This repository has been archived by the owner on Jan 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
download.py
executable file
·109 lines (81 loc) · 2.19 KB
/
download.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#! /usr/bin/env python
import sys
import os
import os.path as path
import subprocess
from multiprocessing import Process
import util as u
import config as cfg
class IoWrapper(object):
"""
This class represents
"""
def __init__(self, io):
"""
Constructor.
io -- A file io object
"""
assert io != None
self._io = io
def obj(self):
"""
obj() --> file io object
"""
return self._io
def close(self):
"""
close() --> None
Closes the io object, if applicable
"""
self._io.close()
class StdOutWrapper(IoWrapper):
def __init__(self):
IoWrapper.__init__(self, sys.stdout)
def close(self):
""" We don't close stdout """
pass
class DevNullWrapper(IoWrapper):
def __init__(self):
IoWrapper.__init__(self, open(os.devnull, 'w'))
def _internal_download_trim_clean(silence=True):
p = ''
if silence:
# We don't want to see output from our subprocess
output = DevNullWrapper()
else:
output = StdOutWrapper()
try:
p = 'podget'
subprocess.check_call([p], stderr=output.obj(), stdout=output.obj())
p = path.join(os.getcwd(), 'trim.py')
p = path.normpath(p)
subprocess.check_call([p], stdout=output.obj())
except subprocess.CalledProcessError, ex:
u.printWarning('Failed to run %s (%s)' % (p, ex))
except OSError, ex:
u.printWarning('Cannot find application %s (%s)' % (p, ex))
output.close()
def download_trim_clean():
###
#u.printStep('Start download, trim, and cleanup in new thread')
p = Process(target=_internal_download_trim_clean, args=())
p.start()
return p
def wait_for_download(p):
# TODO: consider turning output back on (how?)
print
print
print 'Waiting for download to complete...'
print
p.join()
def main():
u.printStep('Initializing')
u.ensure_folders()
u.printStep('Beginning download')
_internal_download_trim_clean(False)
u.printStep('Done')
def _test():
import doctest
doctest.testmod()
if __name__ == '__main__':
main()