Alien-SVN
view release on metacpan or search on metacpan
src/subversion/tools/examples/svnshell.py view on Meta::CPAN
sys.exit(0)
def _path_to_parts(self, path):
return [_f for _f in path.split('/') if _f]
def _parts_to_path(self, parts):
return '/' + '/'.join(parts)
def _parse_path(self, path):
# cleanup leading, trailing, and duplicate '/' characters
newpath = self._parts_to_path(self._path_to_parts(path))
# if PATH is absolute, use it, else append it to the existing path.
if path.startswith('/') or self.path == '/':
newpath = '/' + newpath
else:
newpath = self.path + '/' + newpath
# cleanup '.' and '..'
parts = self._path_to_parts(newpath)
finalparts = []
for part in parts:
if part == '.':
pass
elif part == '..':
if len(finalparts) != 0:
finalparts.pop(-1)
else:
finalparts.append(part)
# finally, return the calculated path
return self._parts_to_path(finalparts)
def _format_date(self, date):
date = core.svn_time_from_cstring(date)
date = time.asctime(time.localtime(date / 1000000))
return date[4:-8]
def _do_path_landing(self):
"""try to land on self.path as a directory in root, failing up to '/'"""
not_found = 1
newpath = self.path
while not_found:
kind = fs.check_path(self.root, newpath)
if kind == core.svn_node_dir:
not_found = 0
else:
parts = self._path_to_parts(newpath)
parts.pop(-1)
newpath = self._parts_to_path(parts)
self.path = newpath
def _setup_prompt(self):
"""present the prompt and handle the user's input"""
if self.is_rev:
self.prompt = "<rev: " + str(self.rev)
else:
self.prompt = "<txn: " + self.txn
self.prompt += " " + self.path + ">$ "
def _complete(self, text, line, begidx, endidx, limit_node_kind=None):
"""Generic tab completer. Takes the 4 standard parameters passed to a
cmd.Cmd completer function, plus LIMIT_NODE_KIND, which should be a
svn.core.svn_node_foo constant to restrict the returned completions to, or
None for no limit. Catches and displays exceptions, because otherwise
they are silently ignored - which is quite frustrating when debugging!"""
try:
args = line.split()
if len(args) > 1:
arg = args[1]
else:
arg = ""
dirs = arg.split('/')
user_elem = dirs[-1]
user_dir = "/".join(dirs[:-1] + [''])
canon_dir = self._parse_path(user_dir)
entries = fs.dir_entries(self.root, canon_dir)
acceptable_completions = []
for name, dirent_t in entries.items():
if not name.startswith(user_elem):
continue
if limit_node_kind and dirent_t.kind != limit_node_kind:
continue
if dirent_t.kind == core.svn_node_dir:
name += '/'
acceptable_completions.append(name)
if limit_node_kind == core.svn_node_dir or not limit_node_kind:
if user_elem in ('.', '..'):
for extraname in ('.', '..'):
if extraname.startswith(user_elem):
acceptable_completions.append(extraname + '/')
return acceptable_completions
except:
ei = sys.exc_info()
sys.stderr.write("EXCEPTION WHILST COMPLETING\n")
import traceback
traceback.print_tb(ei[2])
sys.stderr.write("%s: %s\n" % (ei[0], ei[1]))
raise
def complete_cd(self, text, line, begidx, endidx):
return self._complete(text, line, begidx, endidx, core.svn_node_dir)
def complete_cat(self, text, line, begidx, endidx):
return self._complete(text, line, begidx, endidx, core.svn_node_file)
def complete_ls(self, text, line, begidx, endidx):
return self._complete(text, line, begidx, endidx)
def complete_pcat(self, text, line, begidx, endidx):
return self._complete(text, line, begidx, endidx)
def _basename(path):
"Return the basename for a '/'-separated path."
idx = path.rfind('/')
if idx == -1:
return path
return path[idx+1:]
def usage(exit):
if exit:
output = sys.stderr
else:
output = sys.stdout
output.write(
"usage: %s REPOS_PATH\n"
"\n"
"Once the program has started, type 'help' at the prompt for hints on\n"
"using the shell.\n" % sys.argv[0])
sys.exit(exit)
def main():
if len(sys.argv) != 2:
usage(1)
SVNShell(sys.argv[1])
if __name__ == '__main__':
main()
( run in 0.414 second using v1.01-cache-2.11-cpan-96521ef73a4 )