ctrochalakis / tx-submissions (http://transifex.org/)

fork of transifex

GSoC '08: Introducing a new transifex submission system, an api and a command line client
Clone URL : http://bitbucket.org/ctrochalakis/tx-submissions/ (size: 1.4 MB)
commit 458: 5ef4a2e3412c
parent 457: d617dcad170f
branch: default
Added bazaar submission support. Thanks Toshio! Bazzaar submitter uses lightweighted checkouts.
Christos Trochalakis / ctrochalakis
4 months ago

Changed (Δ4.6 KB):

raw changeset »

README (1 lines added, 1 lines removed)

transifex/submissions/__init__.py (3 lines added, 0 lines removed)

transifex/submissions/methods/bzr.py (104 lines added, 0 lines removed)

tx-init.py (26 lines added, 2 lines removed)

Up to file-list README:

@@ -35,7 +35,7 @@ You can either install Tx from source or
35
35
You can either install Tx from source or using Python packaging. For both
36
36
you'll need to have these additional packages installed::
37
37
38
    yum install cvs subversion mercurial git
38
    yum install cvs pysvn subversion mercurial git bzr bzrtools
39
39
40
40
41
41
To **install using Python packaging**, run the following command, either as

Up to file-list transifex/submissions/__init__.py:

@@ -10,6 +10,7 @@ GIT = 2
10
10
GIT = 2
11
11
HG = 3
12
12
SVN = 4
13
BZR = 5
13
14
EMAIL = 10
14
15
15
16
SUBMISSION_CHOICES = (
@@ -17,6 +18,7 @@ SUBMISSION_CHOICES = (
17
18
    (GIT, 'git'),
18
19
    (HG, 'hg'),
19
20
    (SVN, 'svn'),
21
    (BZR, 'bzr'),
20
22
    (EMAIL, 'email'),
21
23
)
22
24
@@ -25,6 +27,7 @@ SUBMISSION_CLASSES = {
25
27
    GIT: 'transifex.submissions.methods.git.GitSubmitter',
26
28
    HG: 'transifex.submissions.methods.hg.HgSubmitter',
27
29
    SVN: 'transifex.submissions.methods.svn.SvnSubmitter',
30
    BZR: 'transifex.submissions.methods.bzr.BzrSubmitter',
28
31
}
29
32
30
33
def get_submission_class(sub_type):

Up to file-list transifex/submissions/methods/bzr.py:

1
import os
2
from bzrlib import bzrdir
3
from bzrlib.plugins.bzrtools import clean_tree
4
from bzrlib.errors import NotBranchError
5
6
from turbogears import config, identity
7
8
from transifex.util import get_user_email
9
from transifex.submissions.methods import BrowserMixin, dvcs_submit_msg
10
11
bzrrepo_path = os.path.join(config.get('scratchdir'), 'bzr')
12
13
class BzrSubmitter(BrowserMixin):
14
    def __init__(self, sresource):
15
        self.sresource = sresource
16
17
        directory = '%s.%s' % (sresource.module.scmmodule,
18
                                sresource.branch.name)
19
20
        self.path = os.path.join(bzrrepo_path, directory)
21
22
        # Transifex only needs the latest workingtree and the ability to make
23
        # commits.  So a lightweight checkout makes a lot of sense.
24
        try:
25
            # Check that the path is a checkout
26
            self.work_tree, self.repo = bzrdir.BzrDir.open_tree_or_branch(
27
                    self.path)
28
        except NotBranchError:
29
            # Else create a lightweight checkout there.
30
            self.init_repo()
31
32
33
    def submit_msg(self, msg):
34
        return dvcs_submit_msg % { 'message' : msg,
35
                                    'domain' : config.get('project_tx_domain')}
36
37
    @property
38
    def remote_path(self):
39
        """
40
        Calculate remote path for cloning:
41
        Example::
42
            mod.repository.root: 'bzr+ssh://bzr.fedorahosted.org/bzr/'
43
            mod.scmmodule: 'python-fedora'
44
            branch_name = 'python-fedora-devel'
45
        """
46
        mod = self.sresource.module
47
        branch_name = self.sresource.branch.name
48
        return '%s/%s/%s' % (mod.repository.root, mod.scmmodule, branch_name)
49
50
    def init_repo(self):
51
        """
52
        Initialize the working tree for the first time.  Commands used:
53
54
        bzr checkout --lightweight <remote_path> <self.path>
55
        """
56
        remote_work_tree, self.repo = bzrdir.BzrDir.open_tree_or_branch(
57
                    self.remote_path)
58
        self.work_tree = self.repo.create_checkout(self.path,
59
                lightweight=True, accelerator_tree=remote_work_tree)
60
61
62
    def submit(self, files, msg, *args, **kwargs):
63
        """
64
        update to upstream
65
        bzr add <filename>
66
        bzr commit -m <msg>
67
        # Lightweight checkout so no push is needed
68
        """
69
        self.update()
70
71
        for filename, contents in files.iteritems():
72
            self.save_file_contents(filename, contents)
73
74
        # smart_add recursively checks all files in the tree
75
        self.work_tree.smart_add([self.path])
76
        user = '%s <%s>' % (identity.current.user.display_name,
77
                                   get_user_email(identity))
78
        self.work_tree.commit(message=self.submit_msg(msg),
79
                revprops={'author': user})
80
81
    def _clean_dir(self):
82
        """
83
        bzr revert --no-backup
84
        bzr clean_tree --ignored --unknown --detritus
85
86
        revert removes any pending changes (left over from a submit that
87
        encoutnered an error, for instance.
88
89
        clean_tree removes all unknown files.  This is important as we don't
90
        want to import files that were left over from another run by mistake.
91
        """
92
        self.work_tree.revert(backups=False)
93
        clean_tree.clean_tree(self.path, unknown=True, ignored=True,
94
                detritus=True)
95
96
    def update(self):
97
        """
98
        clean dir
99
        bzr update
100
        # Note: If we used a branch instead of a checkout, we'd want to use
101
        # bzr pull.
102
        """
103
        self._clean_dir()
104
        self.work_tree.update()

Up to file-list tx-init.py:

@@ -36,7 +36,7 @@ def init_dirs():
36
36
        else:
37
37
            print "Dir %s exists, skipping." % dir
38
38
39
    for dir in ['hg','cvs', 'git', 'svn']:
39
    for dir in ['hg','cvs', 'git', 'svn', 'bzr']:
40
40
        fullpath = path.join(config.get('scratchdir'),dir)
41
41
        try:
42
42
            mkdir(fullpath)
@@ -135,7 +135,7 @@ def create_test_repos():
135
135
    """
136
136
    troot = get_testing_dir()
137
137
    log.info("Creating Testing repositories...")
138
    sets = ["init", "cvs", "svn", "hg", "git"]
138
    sets = ["init", "cvs", "svn", "hg", "git", "bzr"]
139
139
    coms_set =[]
140
140
    #init
141
141
    coms = []
@@ -168,6 +168,17 @@ def create_test_repos():
168
168
    coms.append(["git", "clone", "git://git.fedorahosted.org/git/system-config-boot",
169
169
                 "%s/gitroot/system-config-boot" % troot])
170
170
    coms_set.append(coms)
171
    # bzr
172
    coms = []
173
    coms.append(["mkdir", "-p", "%s/bzrroot" % troot])
174
    coms.append(["bzr", "init-repository", "%s/bzrroot/python-fedora" % troot])
175
    coms.append(["bzr", "branch",
176
        "bzr://bzr.fedorahosted.org/bzr/python-fedora/python-fedora-devel",
177
        "%s/bzrroot/python-fedora/devel" % troot])
178
    coms.append(["bzr", "branch",
179
        "bzr://bzr.fedorahosted.org/bzr/python-fedora/python-fedora-stable",
180
        "%s/bzrroot/python-fedora/stable" % troot])
181
    coms_set.append(coms)
171
182
172
183
    for (i, scmtype) in enumerate(sets):
173
184
        log.info(' - %s' % scmtype)
@@ -199,6 +210,10 @@ def import_test_repos():
199
210
             {'name': u'testrepo-git',
200
211
              'type': u'git',
201
212
              'root': u'%s/gitroot' % troot,
213
             },
214
             {'name': u'testrepo-bzr',
215
              'type': u'bzr',
216
              'root': u'%s/bzrroot' % troot,
202
217
             },
203
218
            )
204
219
    for item in items:
@@ -253,6 +268,15 @@ def import_test_modules():
253
268
              'changelog': u'',
254
269
              'submission_method': submissions.GIT,
255
270
              'branches': [u'master'],
271
             },
272
             {'name': u'testmodule-bzr',
273
              'repository': u'testrepo-bzr',
274
              'scmmodule': u'python-fedora',
275
              'filefilter': u'po/.*',
276
              'directory': u'',
277
              'changelog': u'',
278
              'submission_method': submissions.BZR,
279
              'branches': [u'devel'],
256
280
             },
257
281
            )
258
282
    for item in items: