source: rtems-source-builder/source-builder/sb/cvs.py @ 5237f1cc

4.104.114.95
Last change on this file since 5237f1cc was 5237f1cc, checked in by Chris Johns <chrisj@…>, on 05/13/13 at 04:44:49

Fix support for Windows (MinGW) native builds using MSYS.

Fix paths that need to be coverted to host format.

The shell expansion needs to invoke a shell on Windows as cmd.exe
will not work.

Munch the paths into smaller sizes for Windows due to the limited
path size.

  • Property mode set to 100644
File size: 5.1 KB
Line 
1#
2# RTEMS Tools Project (http://www.rtems.org/)
3# Copyright 2010-2013 Chris Johns (chrisj@rtems.org)
4# All rights reserved.
5#
6# This file is part of the RTEMS Tools package in 'rtems-tools'.
7#
8# Permission to use, copy, modify, and/or distribute this software for any
9# purpose with or without fee is hereby granted, provided that the above
10# copyright notice and this permission notice appear in all copies.
11#
12# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20#
21# Provide some basic access to the cvs command.
22#
23
24import os
25
26import error
27import execute
28import log
29import options
30import path
31
32class repo:
33    """An object to manage a cvs repo."""
34
35    def __init__(self, _path, opts, macros = None, prefix = None):
36        self.path = _path
37        self.opts = opts
38        self.prefix = prefix
39        if macros is None:
40            self.macros = opts.defaults
41        else:
42            self.macros = macros
43        self.cvs = self.macros.expand('%{__cvs}')
44
45    def _cvs_exit_code(self, cmd, ec, output):
46        if ec:
47            log.output(output)
48            raise error.general('cvs command failed (%s): %d' % (cmd, ec))
49
50    def _parse_args(self, url):
51        if not url.startswith('cvs://'):
52            raise error.general('invalid cvs url: %s' % (url))
53        opts = { 'cvsroot': ':%s' % (us[0][6:]),
54                 'module':  '' }
55        for o in us:
56            os = o.split('=')
57            if len(os) == 1:
58                opts[os[0]] = True
59            else:
60                opts[os[0]] = os[1:]
61        return opts
62
63    def _run(self, args, check = False, cwd = None):
64        e = execute.capture_execution()
65        if cwd is None:
66            cwd = path.join(self.path, self.prefix)
67        if not path.exists(cwd):
68            raise error.general('cvs path needs to exist: %s' % (cwd))
69        cmd = [self.cvs, '-z', '9', '-q'] + args
70        log.output('cmd: (%s) %s' % (str(cwd), ' '.join(cmd)))
71        exit_code, proc, output = e.spawn(cmd, cwd = path.host(cwd))
72        log.trace(output)
73        if check:
74            self._cvs_exit_code(cmd, exit_code, output)
75        return exit_code, output
76
77    def cvs_version(self):
78        ec, output = self._run(['--version'], True)
79        lines = output.split('\n')
80        if len(lines) < 12:
81            raise error.general('invalid version string from cvs: %s' % (output))
82        cvs = lines[0].split(' ')
83        if len(cvs) != 6:
84            raise error.general('invalid version number from cvs: %s' % (lines[0]))
85        vs = cvs[4].split('.')
86        if len(vs) < 3:
87            raise error.general('invalid version number from cvs: %s' % (cvs[4]))
88        return (int(vs[0]), int(vs[1]), int(vs[2]))
89
90    def checkout(self, root, module = None, tag = None, date = None):
91        cmd = ['-d', root, 'co', '-N']
92        if tag:
93           cmd += ['-r', tag]
94        if date:
95            cmd += ['-D', date]
96        if module:
97            cmd += [module]
98        ec, output = self._run(cmd, check = True, cwd = self.path)
99
100    def update(self):
101        ec, output = self._run(['up'], check = True)
102
103    def reset(self):
104        ec, output = self._run(['up', '-C'], check = True)
105
106    def branch(self):
107        ec, output = self._run(['branch'])
108        if ec == 0:
109            for b in output.split('\n'):
110                if b[0] == '*':
111                    return b[2:]
112        return None
113
114    def status(self):
115        keys = { 'U': 'modified',
116                 'P': 'modified',
117                 'M': 'modified',
118                 'R': 'removed',
119                 'C': 'conflict',
120                 'A': 'added',
121                 '?': 'untracked' }
122        _status = {}
123        if path.exists(self.path):
124            ec, output = self._run(['-n', 'up'])
125            if ec == 0:
126                state = 'none'
127                for l in output.split('\n'):
128                    if len(l) > 2 and l[0] in keys:
129                        if keys[l[0]] not in _status:
130                            _status[keys[l[0]]] = []
131                        _status[keys[l[0]]] += [l[2:]]
132        return _status
133
134    def clean(self):
135        _status = self.status()
136        return len(_status) == 0
137
138    def valid(self):
139        if path.exists(self.path):
140            ec, output = self._run(['-n', 'up', '-l'])
141            if ec == 0:
142                if not output.startswith('cvs status: No CVSROOT specified'):
143                    return True
144        return False
145
146if __name__ == '__main__':
147    import sys
148    opts = options.load(sys.argv, defaults = 'defaults.mc')
149    ldir = 'cvs-test-rm-me'
150    c = repo(ldir, opts)
151    if not path.exists(ldir):
152        path.mkdir(ldir)
153        c.checkout(':pserver:anoncvs@sourceware.org:/cvs/src', module = 'newlib')
154    print c.cvs_version()
155    print c.valid()
156    print c.status()
157    c.reset()
158    print c.clean()
Note: See TracBrowser for help on using the repository browser.