diff --git a/.gitignore b/.gitignore index 71d02fc..6f07381 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ build/ dist/ .DS_Store tessera-env +.ropeproject/ +tags diff --git a/.tesserae/5eba187a-2251-11e4-addf-001fd0a23bb2/info b/.tesserae/5eba187a-2251-11e4-addf-001fd0a23bb2/info index 3763e7d..53a77e8 100644 --- a/.tesserae/5eba187a-2251-11e4-addf-001fd0a23bb2/info +++ b/.tesserae/5eba187a-2251-11e4-addf-001fd0a23bb2/info @@ -1,3 +1,3 @@ author: André Roth -email: neolynx@gmail.com -updated: 1407869360 +email: None +updated: 1417460922 diff --git a/.tesserae/5eba187a-2251-11e4-addf-001fd0a23bb2/tessera b/.tesserae/5eba187a-2251-11e4-addf-001fd0a23bb2/tessera index 00ade4a..fb333cd 100644 --- a/.tesserae/5eba187a-2251-11e4-addf-001fd0a23bb2/tessera +++ b/.tesserae/5eba187a-2251-11e4-addf-001fd0a23bb2/tessera @@ -4,3 +4,6 @@ @tags git require user to stash changes if dirty + +Or even better: automatically stash the changes and stash +them back again when finished operation. diff --git a/.tesserae/650e4b28-799b-11e4-ba2f-00ff1070e019/info b/.tesserae/650e4b28-799b-11e4-ba2f-00ff1070e019/info new file mode 100644 index 0000000..1e8a69f --- /dev/null +++ b/.tesserae/650e4b28-799b-11e4-ba2f-00ff1070e019/info @@ -0,0 +1,3 @@ +author: Claudio Klingler +email: None +updated: 1417467144 diff --git a/.tesserae/650e4b28-799b-11e4-ba2f-00ff1070e019/tessera b/.tesserae/650e4b28-799b-11e4-ba2f-00ff1070e019/tessera new file mode 100644 index 0000000..a422e78 --- /dev/null +++ b/.tesserae/650e4b28-799b-11e4-ba2f-00ff1070e019/tessera @@ -0,0 +1,13 @@ +# better commit message on changed tessera +@status new +@type todo +// @tags + +If you change an tessera, you get a pretty commit message +in your log showing you which tessera was changed. + +However, it would be nice to extract the status info from the file +and add it to the commit message like: + +"tessera updated: XZ, status: new" + diff --git a/tessera/gitcommands.py b/tessera/gitcommands.py index 4f2de85..126a608 100644 --- a/tessera/gitcommands.py +++ b/tessera/gitcommands.py @@ -2,8 +2,9 @@ import os import stat +import re from subprocess import Popen -from sys import stdin, stdout, stderr +from sys import stdin, stdout import types import shutil @@ -14,90 +15,178 @@ from exceptions import TesseraError, ArgumentError +class TRepository: + def __init__(self, git_tessera): + self.GitTessera = git_tessera + + def find(self, args): + + refspec = "" + ls_args = [] + while args: + arg = args.pop() + + if arg == "-": + refspec = "-" + continue + + m = re.match("-(\d+)", arg) + if m is not None: + refspec = m.group(1) + continue + + ls_args.append(arg) + + results = self.GitTessera.ls(ls_args) + if refspec == "-": + return [results[0]] + + if re.match("^\d+$", refspec): + return [results[int(refspec)]] + + if refspec != "": + ret = [] + for t in results: + if t.tessera_hash.startswidth(refspec): + ret.append(t) + + return ret + return results + + class GitCommands(object): def __init__(self): git_directory = "." self.git = MyGit(git_directory) - Tessera._tesserae = os.path.relpath(os.path.join(git_directory, ".tesserae")) + Tessera._tesserae = os.path.relpath(os.path.join( + git_directory, ".tesserae")) self._config = TesseraConfig(os.path.join(Tessera._tesserae, "config")) + def cmd_help(self, args): + """ git tessera + + manage your project issues within your git reporitory + + commands: + """ + if len(args) > 0: + function = self.__getattribute__("cmd_" + args[0]) + print function.__doc__ + return + print self.cmd_help.__doc__ + for cmd in dir(self): + if cmd.startswith("cmd_"): + print " {0} {1}".format(cmd[4:], cmd.__doc__) + def cmd_init(self, args): + """ git tessera init + + initialises tessera in an existing git repository + """ if len(args) != 0: raise ArgumentError("git tessera init takes no arguments") if os.path.exists(Tessera._tesserae): - raise TesseraError("git tesserae directory already exists: %s" % Tessera._tesserae) + raise TesseraError("git tesserae directory already exists: %s" + % Tessera._tesserae) os.mkdir(Tessera._tesserae) files = [] - for source in [ "template", "config" ]: + for source in ["template", "config"]: files.append(_install(Tessera._tesserae, source)) self.git.add(files, "tessera: initialized") return True def cmd_ls(self, args): + """ git tessera ls + + list available tesseraes in current git repository + + git tessera ls - + list the last entry + + git tessera ls -2 + list the second last entry + + git tessera ls - -e + edit the listed (last) entry + + git tessera ls -2 -e + edit the second last entry + """ + + if "-e" in args: + args.remove("-e") + return self.cmd_edit(args) + gt = GitTessera(self._config) - tesserae = gt.ls(args) + tr = TRepository(gt) + tesserae = tr.find(args) + for t in tesserae: print t.summary() return True def cmd_show(self, args): if len(args) != 1: - raise ArgumentError("git tessera show takes identifier as argument") + raise ArgumentError( + "git tessera show takes identifier as argument") gt = GitTessera(self._config) - t = gt.get(args[0]) - if not t: + gr = TRepository(gt) + ts = gr.find(args) + if not ts: return False - short = t.summary() - length = len(short) - print "=" * length - print short - print "=" * length - print t.content + for t in ts: + short = t.summary() + length = len(short) + print "=" * length + print short + print "=" * length + print t.content return True def cmd_edit(self, args): + """ git tessera edit + + opens a existing tessera identified by in editor + for modifying it. automatically add the modifications + as a commit to the repository. + + may be: + '-' for the last entry + '-1' for the second last entry + '-2' for the thirt last entry + the SHA1 id of the tessera + """ if len(args) < 1: - raise ArgumentError("git tessera edit takes one or more identifier as argument") - - tessera_paths = [] - for key in args: - tessera_path = None - found = False - for i in os.listdir(Tessera._tesserae): - tessera_path = "%s/%s" % (Tessera._tesserae, i) - if not stat.S_ISDIR(os.lstat(tessera_path).st_mode): - continue - if i.split('-')[0] == key or i == key: - found = True - break - if not found: - raise TesseraError("git tessera %s not found" % key) + raise ArgumentError( + "git tessera edit takes one or more identifier as argument") - tessera_paths.append(tessera_path) + gt = GitTessera(self._config) + gr = TRepository(gt) + tesserae = gr.find(args) while True: - tessera_files = ["%s/tessera" % x for x in tessera_paths] + tessera_files = ["%s" % x.filename for x in tesserae] _edit(tessera_files, self._config) # if self.git.is_dirty(): failed = [] - while tessera_paths: - tessera_path = tessera_paths.pop() - t = Tessera(tessera_path, self._config) + while tesserae: + t = tesserae.pop() if not t.error: t._write_info() - files = [ "%s/tessera" % tessera_path, "%s/info" % tessera_path ] - self.git.add( files, "tessera updated: %s" % t.get_attribute("title")) + files = [t.filename, t.infofile] + self.git.add(files, "tessera updated: %s" + % t.get_attribute("title")) continue # failed parsing - failed.append(tessera_path) + failed.append(t) if failed: stdout.write("Abort ? [y/N] ") @@ -107,7 +196,8 @@ def cmd_edit(self, args): break if answer and answer.lower() == "y": break - tessera_paths = failed + # FIXME: what shall that line do? + # tessera_paths = failed else: break @@ -136,7 +226,8 @@ def cmd_create(self, args): def cmd_remove(self, args): if len(args) != 1: - raise ArgumentError("git tessera remove takes identifier as argument") + raise ArgumentError( + "git tessera remove takes identifier as argument") key = args[0] tessera_file = None @@ -236,6 +327,7 @@ def _edit(files, config): p.communicate() return p.wait() + def _install(tesserae_path, source): """ Installs the file named {source} from config directory of tessera into the target repository.