1
# -*- coding: utf-8 -*-
3
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
4
#Copyright (c) 2005 Ali Afshar aafshar@gmail.com
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:
13
#The above copyright notice and this permission notice shall be included in
14
#all copies or substantial portions of the Software.
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
28
# From the Arch manual (kept here for reference)
31
# D/ deleted directory
32
# /> renamed directory
33
# -/ directory permissions changed
38
# Mb binary file modified
39
# -- permissions of file changed
41
# fl file replaced by link
42
# lf link replaced by file
43
# -> link target changed
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,
55
"D/": _vc.STATE_REMOVED,
56
"/>": _vc.STATE_REMOVED,
57
"-/": _vc.STATE_MODIFIED,
58
"lf": _vc.STATE_MODIFIED,
66
PATCH_INDEX_RE = "--- orig/(.*)"
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):
75
location = os.path.dirname(location)
78
def commit_command(self, message):
79
return [self.CMD, "commit",
82
def diff_command(self):
83
return [self.CMD, "file-diff"]
85
def update_command(self):
86
return [self.CMD, "update"]
88
def add_command(self, binary=0):
89
return [self.CMD, "add-id"]
91
def remove_command(self, force=0):
92
return [self.CMD, "rm"]
94
def revert_command(self):
95
# Will only work on later versions of tla
96
return [self.CMD, "undo", "--"]
98
def get_working_directory(self, workdir):
101
def cache_inventory(self, rootdir):
102
self._cached_statuses = self._calculate_statuses()
104
def uncache_inventory(self):
105
self._cached_statuses = None
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:
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
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
123
def _calculate_statuses(self):
125
commandline = ('%s changes -d %s' % (self.CMD, self.root))
128
p = os.popen(commandline)
131
if e.errno != errno.EAGAIN:
134
if line.startswith('*'):
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
145
def _get_statuses(self, whatsnew, files, fstype):
147
for filename, path in files:
148
state = _vc.STATE_NORMAL
150
state = whatsnew[path]
151
vcfile = fstype(path, filename, state)
152
if filename != "{arch}":
156
def _get_directoryname(self, files, dirs):
159
directory = os.path.dirname(files[0][1])
161
directory = os.path.dirname(dirs[0][1])