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
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
package_database.py
~~~~~~~~~~~~~~~~~~~
a simple script that create a package database from the octave-forge
SVN repository.
:copyright: (c) 2010 by Rafael Goncalves Martins
:license: GPL-2, see LICENSE for more details.
"""
from __future__ import print_function
import os
import sys
current_dir = os.path.dirname(os.path.realpath(__file__))
if os.path.exists(os.path.join(current_dir, '..', 'g_octave')):
sys.path.insert(0, os.path.join(current_dir, '..'))
import shutil
import tarfile
import tempfile
from contextlib import closing
from g_octave import config
from g_octave.svn import revisions, utils
def main(argv):
if len(argv) < 2:
print('You should provide the name of the generated tarball', file=sys.stderr)
return 1
conf = config.Config()
json_file = os.path.join(conf.db, 'revisions.json')
db = revisions.Revisions(json_file).get()
pkg_cache = os.listdir(conf.pkg_cache)
temp_dir = tempfile.mkdtemp()
try:
for category in db:
category_dir = os.path.join(temp_dir, category)
if not os.path.exists(category_dir):
os.makedirs(category_dir)
for package in db[category]:
for tarball in pkg_cache:
if tarball.startswith(package + '-') and tarball.endswith('.tar.gz'):
dirname = tarball[:tarball.find('.tar.gz')]
tarball_path = os.path.join(conf.pkg_cache, tarball)
with closing(tarfile.open(tarball_path, 'r:gz')) as src_tar:
src_tar.extract(
os.path.join(dirname, 'DESCRIPTION'),
path = category_dir
)
utils.create_tarball(temp_dir, argv[1], 'octave-forge')
except Exception as err:
raise RuntimeError('An error was ocurred: %s' % err)
finally:
shutil.rmtree(temp_dir)
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))
|