3 # gPodder dependency installer for running the CLI from the source tree
5 # Run "python localdepends.py" and it will download and inject dependencies,
6 # so you only need a standard Python installation for the command-line utility
8 # Thomas Perl <thp.io/about>; 2012-02-11
22 sys
.stdout
= sys
.stderr
24 src_dir
= os
.path
.abspath(os
.path
.join(os
.path
.dirname(__file__
), '..', 'src'))
25 tmp_dir
= tempfile
.mkdtemp()
28 # Module name, Regex-file chooser (1st group = location in "src/")
29 ('podcastparser', r
'podcastparser-[0-9.]+/(podcastparser.py)'),
30 ('mygpoclient', r
'mygpoclient-[0-9.]+/(mygpoclient/[^/]*\.py)')
34 def get_tarball_url(modulename
):
35 url
= 'http://pypi.python.org/pypi/' + modulename
36 html
= urllib
.request
.urlopen(url
).read().decode('utf-8')
37 match
= re
.search(r
'(http[s]?://[^>]*%s-([0-9.]*)(?:\.post\d+)?\.tar\.gz)' % modulename
, html
)
38 return match
.group(0) if match
is not None else None
41 for module
, required_files
in MODULES
:
42 print('Fetching', module
, '...', end
=' ')
43 tarball_url
= get_tarball_url(module
)
44 if tarball_url
is None:
45 print('Cannot determine download URL for', module
, '- aborting!')
47 data
= urllib
.request
.urlopen(tarball_url
).read()
48 print('%d KiB' % (len(data
) // 1024))
49 print(' downloaded from %s' % tarball_url
)
50 tar
= tarfile
.open(fileobj
=io
.BytesIO(data
))
51 for name
in tar
.getnames():
52 match
= re
.match(required_files
, name
)
54 target_name
= match
.group(1)
55 target_file
= os
.path
.join(src_dir
, target_name
)
56 if os
.path
.exists(target_file
):
57 print('Skipping:', target_file
)
60 target_dir
= os
.path
.dirname(target_file
)
61 if not os
.path
.isdir(target_dir
):
64 print('Extracting:', target_name
)
65 tar
.extract(name
, tmp_dir
)
66 shutil
.move(os
.path
.join(tmp_dir
, name
), target_file
)
68 shutil
.rmtree(tmp_dir
)