summaryrefslogtreecommitdiffstats
path: root/modules/packagesource.py
blob: 2b320cab6a86df2963dd630990e4f99fda5e48b2 (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
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
110
111
112
113
114
115
116
117
118
119
120
121
# 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

from contextlib import contextmanager
from os import makedirs
from os.path import join

from base.factories import BuildSystemFactory
from base.util import pwd

from modules.directory import Directory

class PackageSource(Directory):
    def make_dir(self, dir):
        super(PackageSource, self).make_dir(dir)
        with pwd(dir):
            makedirs(self.pkg_src)
            makedirs(self.branches)

    @property
    def pkg_src(self):
        return '.pkg_src'
    
    @property
    def pkg_src_dir(self):
        return join(self.dir, self.pkg_src)

    @property
    def branches(self):
        return join(self.pkg_src, 'branches')

    @property
    def branches_dir(self):
        return join(self.dir, self.branches)

    @property
    def sourceball(self):
        return self.cfg['sourceball']
    
    @property
    def sourceball_loc(self):
        return join(self.pkg_src_dir, self.sourceball)

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

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

    @property
    def source(self):
        '''the name of the directory where the source is being kept currently
        '''
        return self.cfg['source']

    @property
    def source_dir(self):
        '''the absolute pathname of the directory where the source is being kept currently
        '''
        return join(self.dir, self.source)

    @contextmanager
    def src_dir(self, *args):
        '''executes a code block inside a specific branch and or checkout
        '''
        with self.src(*args):
            with pwd(self.source_dir):
                yield

    @contextmanager
    def src(self, *args):
        '''executes a code block with a particular branch or checkout

        if there are no args, this block is executed in the raw
        '''
        if args:
            old_src = self.cfg['source']
            self.set_cur_to(*args)
        yield
        if args:
            self.cfg['source'] = old_src
            self.set_current_src()

    def set_current_src(self):
        raise NotImplementedError

    def set_cur_to(self, *args):
        raise NotImplementedError

    def branch(self, *args):
        raise NotImplementedError

    def branch_dir(self, *args):
        return join(self.dir, self.branch(*args))

    @property
    def buildsystem(self):
        return self.cfg['buildsystem']

    def set_buildsystem(self, buildsystem):
        self.cfg['buildsystem'] = buildsystem

    @property
    def builder(self):
        return BuildSystemFactory(self.buildsystem, self)