summaryrefslogtreecommitdiffstats
path: root/modules/sourceball.py
blob: 38abf1fe92b878948ef1eb3e46f3f8642b891647 (plain)
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
# Fedora Developer Shell
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Authors: Yaakov M. Nemoy <ynemoy@redhat.com>
#
from __future__ import with_statement

import tarfile

from os import makedirs, getcwd
from os.path import abspath, split, basename, join
from shutil import copytree
from subprocess import Popen, PIPE
from tempfile import mkdtemp

from base.base import log
from base.dirfactory import DirFactory
from base.exceptions import ExecutionException
from base.util import pwd, copy, move

from modules.packagesource import PackageSource

class SourceBall(PackageSource):
    '''a type of package that is a single sourceball, a spec file, and some patches'''
    def __init__(self, name=None, tarball=''):
        if tarball:
            tmp_dir = mkdtemp()
            with pwd(tmp_dir):
                sourceball_name = copy(tarball, split(tarball)[1])
                sourceball = tarfile.open(sourceball_name)
            extract_dir = min([(x.name, x) for x in sourceball])[0]
            extract_dir = basename(abspath(extract_dir))
            if name and not name == extract_dir:
                raise ExecutionException("tarball is not target directory")
            if not name:
                name = extract_dir
        super(SourceBall, self).__init__(name)
        if tarball:
            with pwd(self.dir):
                sourceball.extractall()
            with pwd(self.branch_dir):
                sourceball.extractall()
                move(self.name, self.orig_dir(self.name))
            with pwd(self.pkg_src_dir):
                move(join(tmp_dir, sourceball_name), sourceball_name)
        self.cfg['sourceball'] = sourceball_name

    def orig_dir(self, dir):
        '''where is the original source kept

        use for making patches against modified source'''
        return dir + '_orig'

    def set_cur_to(self, *args):
        '''gives source directory

        first parameter, if 'orig' gives the original source, otherwise
        you get the modified source
        '''
        if len(args) == 1 and args[0] == 'head':
            self.cfg['source'] = '.'
        elif len(args) == 1 and args[0] == 'orig':
            self.cfg['source'] = join(self.branch, self.orig_dir(self.name))

    def setup_sourceball(self, ver=''):
        return

    def setup_sourceball_w_patches(self, ver=''):
        raise NotImplementedError


__all__ = ['SourceBall']