~ubuntu-branches/ubuntu/saucy/pida/saucy

« back to all changes in this revision

Viewing changes to pida/utils/vc/tla.py

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2006-08-01 13:08:56 UTC
  • mfrom: (0.1.2 etch) (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060801130856-v92ktopgdxc8rv7q
Tags: 0.3.1-2ubuntu1
* Re-sync with Debian
* Remove bashisms from debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*- 
 
2
 
 
3
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
 
4
#Copyright (c) 2005 Ali Afshar aafshar@gmail.com
 
5
 
 
6
#Permission is hereby granted, free of charge, to any person obtaining a copy
 
7
#of this software and associated documentation files (the "Software"), to deal
 
8
#in the Software without restriction, including without limitation the rights
 
9
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
10
#copies of the Software, and to permit persons to whom the Software is
 
11
#furnished to do so, subject to the following conditions:
 
12
 
 
13
#The above copyright notice and this permission notice shall be included in
 
14
#all copies or substantial portions of the Software.
 
15
 
 
16
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
17
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
18
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
19
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
20
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
21
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
22
#SOFTWARE.
 
23
 
 
24
import os
 
25
import errno
 
26
import _vc
 
27
 
 
28
# From the Arch manual (kept here for reference)
 
29
 
 
30
# A/   added directory
 
31
# D/   deleted directory
 
32
# />   renamed directory
 
33
# -/   directory permissions changed
 
34
 
 
35
# A    added file
 
36
# D    deleted file
 
37
# M    file modified
 
38
# Mb   binary file modified
 
39
# --   permissions of file changed
 
40
# =>   renamed file
 
41
# fl   file replaced by link
 
42
# lf   link replaced by file
 
43
# ->   link target changed
 
44
 
 
45
STATES = {
 
46
    "a": _vc.STATE_NONE,
 
47
    "A": _vc.STATE_NEW,
 
48
    "M": _vc.STATE_MODIFIED,
 
49
    "C": _vc.STATE_CONFLICT,
 
50
    "D": _vc.STATE_REMOVED,
 
51
    "--": _vc.STATE_MODIFIED,
 
52
    "=>": _vc.STATE_REMOVED,
 
53
    "->": _vc.STATE_MODIFIED,
 
54
    "A/": _vc.STATE_NEW,
 
55
    "D/": _vc.STATE_REMOVED,
 
56
    "/>": _vc.STATE_REMOVED,
 
57
    "-/": _vc.STATE_MODIFIED,
 
58
    "lf": _vc.STATE_MODIFIED,
 
59
}
 
60
 
 
61
class Vc(_vc.Vc):
 
62
 
 
63
    CMD = "tla"
 
64
    NAME = "Arch"
 
65
    PATCH_STRIP_NUM = 1
 
66
    PATCH_INDEX_RE = "--- orig/(.*)"
 
67
 
 
68
    def __init__(self, location):
 
69
        self._cachetime = None
 
70
        self._cached_statuses = None
 
71
        while location != "/":
 
72
            if os.path.isdir( "%s/{arch}" % location):
 
73
                self.root = location
 
74
                return
 
75
            location = os.path.dirname(location)
 
76
        raise ValueError()
 
77
 
 
78
    def commit_command(self, message):
 
79
        return [self.CMD, "commit",
 
80
                "-s", message]
 
81
 
 
82
    def diff_command(self):
 
83
        return [self.CMD, "file-diff"]
 
84
 
 
85
    def update_command(self):
 
86
        return [self.CMD, "update"]
 
87
 
 
88
    def add_command(self, binary=0):
 
89
        return [self.CMD, "add-id"]
 
90
 
 
91
    def remove_command(self, force=0):
 
92
        return [self.CMD, "rm"]
 
93
 
 
94
    def revert_command(self):
 
95
        # Will only work on later versions of tla
 
96
        return [self.CMD, "undo", "--"]
 
97
 
 
98
    def get_working_directory(self, workdir):
 
99
        return self.root
 
100
 
 
101
    def cache_inventory(self, rootdir):
 
102
        self._cached_statuses = self._calculate_statuses()
 
103
 
 
104
    def uncache_inventory(self):
 
105
        self._cached_statuses = None
 
106
 
 
107
    def lookup_files(self, dirs, files):
 
108
        "files is array of (name, path). assume all files in same dir"
 
109
        directory = self._get_directoryname(files, dirs)
 
110
        if directory is None:
 
111
            return [], []
 
112
        else:
 
113
            whatsnew = self._get_cached_statuses()
 
114
            retfiles, retdirs = (self._get_statuses(whatsnew, files, _vc.File),
 
115
                                 self._get_statuses(whatsnew, dirs, _vc.Dir))
 
116
            return retfiles, retdirs
 
117
 
 
118
    def _get_cached_statuses(self):
 
119
        if self._cached_statuses is None:
 
120
            self._cached_statuses = self._calculate_statuses()
 
121
        return self._cached_statuses
 
122
    
 
123
    def _calculate_statuses(self):
 
124
        whatsnew = {}
 
125
        commandline = ('%s changes -d %s' % (self.CMD, self.root))
 
126
        while 1:
 
127
            try:
 
128
                p = os.popen(commandline)
 
129
                break
 
130
            except OSError, e:
 
131
                if e.errno != errno.EAGAIN:
 
132
                    raise
 
133
        for line in p:
 
134
            if line.startswith('*'):
 
135
                continue
 
136
            elements = line.split()
 
137
            if len(elements) > 1:
 
138
                status = STATES[elements.pop(0)]
 
139
                filename = elements.pop(0)
 
140
                filepath = os.path.join(self.root,
 
141
                                    os.path.normpath(filename))
 
142
                whatsnew[filepath] = status
 
143
        return whatsnew
 
144
 
 
145
    def _get_statuses(self, whatsnew, files, fstype):
 
146
        rets = []
 
147
        for filename, path in files:
 
148
            state = _vc.STATE_NORMAL
 
149
            if path in whatsnew:
 
150
                state = whatsnew[path]
 
151
            vcfile = fstype(path, filename, state)
 
152
            if filename != "{arch}":
 
153
                rets.append(vcfile)
 
154
        return rets
 
155
 
 
156
    def _get_directoryname(self, files, dirs):
 
157
        directory = None
 
158
        if len(files):
 
159
            directory = os.path.dirname(files[0][1])
 
160
        elif len(dirs):
 
161
            directory = os.path.dirname(dirs[0][1])
 
162
        return directory
 
163