Beispiel #1
0
  def oneline(self, cols, annotate_ownership):
    colstrings = []
    for col in cols:
      if not col['visible']:
        continue

      w = col['width']
      id = col['id']
      if id == 'id':
        colstrings.append(misc.chop(self.id, w))
      elif id == 'type':
        colstrings.append(misc.pad_to_length(self.type, w))
      elif id == 'date':
        colstrings.append(misc.pad_to_length('%s/%s' % (self.date.month, self.date.day), w))
      elif id == 'title':
        if not annotate_ownership or self.assigned_to == '-':
          colstrings.append('%s%s%s' % (colors.colors[self.status_colors[self.status]],        \
                                        misc.pad_to_length(misc.chop(self.title, w, '..'), w), \
	                    colors.colors['default']))
        else:
          name_suffix = ' (%s)' % self.assigned_to
          w = w - len(name_suffix)
          colstrings.append('%s%s' % (misc.pad_to_length(misc.chop(self.title, w, '..'), w), \
                                      name_suffix))
      elif id == 'status':
        colstrings.append('%s%s%s' % (colors.colors[self.status_colors[self.status]],        \
                                      misc.pad_to_length(self.status, 8),                             \
	                  colors.colors['default']))
      elif id == 'priority':
        priostr = self.prio_names[self.prio-1]
        colstrings.append('%s%s%s' % (colors.colors[self.prio_colors[priostr]],              \
                                      priostr,                                               \
	                  colors.colors['default']))

    return ' '.join(colstrings)
Beispiel #2
0
    def edit(self, sha):
        i, rel, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)

        # Save the contents of this ticket to a file, so it can be edited
        i.save(it.EDIT_TMP_FILE)
        timestamp1 = os.path.getmtime(it.EDIT_TMP_FILE)
        success = os.system('vim "%s"' % it.EDIT_TMP_FILE) == 0
        timestamp2 = os.path.getmtime(it.EDIT_TMP_FILE)
        if success:
            if timestamp1 < timestamp2:
                i = ticket.create_from_file(it.EDIT_TMP_FILE, fullsha, rel)

                # Now, when the edit has succesfully taken place, switch branches, commit,
                # and switch back
                curr_branch = git.current_branch()
                git.change_head_branch('git-it')
                msg = 'ticket \'%s\' edited' % sha7
                i.save()
                git.command_lines('commit', ['-m', msg, i.filename()])
                git.change_head_branch(curr_branch)
                abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
                git.command_lines('reset', ['HEAD', abs_ticket_dir])
                misc.rmdirs(abs_ticket_dir)
                print 'ticket \'%s\' edited succesfully' % sha7
                print ''
                self.list()
            else:
                print 'editing of ticket \'%s\' cancelled' % sha7
        else:
            log.printerr('editing of ticket \'%s\' failed' % sha7)

        # Remove the temporary file
        os.remove(it.EDIT_TMP_FILE)
Beispiel #3
0
  def edit(self, sha):
    i, rel, fullsha, match = self.get_ticket(sha)
    sha7 = misc.chop(fullsha, 7)

    # Save the contents of this ticket to a file, so it can be edited
    i.save(it.EDIT_TMP_FILE)
    timestamp1 = os.path.getmtime(it.EDIT_TMP_FILE)
    success = os.system('vim "%s"' % it.EDIT_TMP_FILE) == 0
    timestamp2 = os.path.getmtime(it.EDIT_TMP_FILE)
    if success:
      if timestamp1 < timestamp2:
        i = ticket.create_from_file(it.EDIT_TMP_FILE, fullsha, rel)

        # Now, when the edit has succesfully taken place, switch branches, commit,
        # and switch back
        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        msg = 'ticket \'%s\' edited' % sha7
        i.save()
        git.command_lines('commit', ['-m', msg, i.filename()])
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        print 'ticket \'%s\' edited succesfully' % sha7
        print ''
        self.list()
      else:
        print 'editing of ticket \'%s\' cancelled' % sha7
    else:
      log.printerr('editing of ticket \'%s\' failed' % sha7)

    # Remove the temporary file
    os.remove(it.EDIT_TMP_FILE)
Beispiel #4
0
    def rm(self, sha):
        match = self.match_or_error(sha)
        print("Remove permanently '%s'" % match)
        print("(Press CTRL-C to abort...)")
        try:
            raw_input()
        except KeyboardInterrupt:
            log.printerr("Abort!")
            sys.exit(1)

        _, basename = os.path.split(match)
        sha7 = misc.chop(basename, 7)

        # prepare the critical section
        curr_branch = self.repo.active_branch.name
        curr_dir = os.getcwd()
        msg = "Removed ticket '%s'" % sha7
        abs_ticket_dir = os.path.join(self.repo.working_dir, it.TICKET_DIR)

        # Commit the new itdb to the repo
        try:
            os.chdir(self.repo.working_dir)
            self.repo.git.symbolic_ref(
                ['HEAD', 'refs/heads/' + it.ITDB_BRANCH])
            self.repo.git.commit(['-m', msg, match])
            print("ticket '%s' removed" % sha7)
        except Exception:
            log.printerr("Error commiting change!")
            sys.exit(1)
        finally:
            self.repo.git.symbolic_ref(['HEAD', 'refs/heads/' + curr_branch])
            self.repo.git.reset(['HEAD', '--', abs_ticket_dir])
            misc.rmdirs(abs_ticket_dir)
            os.chdir(curr_dir)
Beispiel #5
0
    def finish_ticket(self, sha, new_status):
        i, _, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)
        if i.status not in ['open', 'test']:
            log.printerr("Ticket '%s' already %s" % (sha7, i.status))
            sys.exit(1)

        # Now, when the edit has succesfully taken place, switch branches, commit,
        # and switch back
        curr_branch = self.repo.active_branch.name
        curr_dir = os.getcwd()
        msg = "%s ticket '%s'" % (i.status, sha7)
        msg = msg.capitalize()
        abs_ticket_dir = os.path.join(self.repo.working_dir, it.TICKET_DIR)

        try:
            os.chdir(self.repo.working_dir)
            self.repo.git.symbolic_ref(
                ['HEAD', 'refs/heads/' + it.ITDB_BRANCH])
            i.status = new_status
            i.save()
            self.repo.git.commit(['-m', msg, match])
            print("Ticket '%s' now %s" % (sha7, new_status))
        except Exception:
            log.printerr("Error commiting changes to ticket '%s'" % sha7)
        finally:
            self.repo.git.symbolic_ref(['HEAD', 'refs/heads/' + curr_branch])
            self.repo.git.reset(['HEAD', '--', abs_ticket_dir])
            misc.rmdirs(abs_ticket_dir)
            os.chdir(curr_dir)
Beispiel #6
0
    def reopen_ticket(self, sha):
        i, _, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)
        if i.status == 'open':
            log.printerr("Ticket '%s' already open" % sha7)
            sys.exit(1)

        # Now, when the edit has succesfully taken place, switch branches, commit,
        # and switch back
        curr_branch = self.repo.active_branch.name
        curr_dir = os.getcwd()
        msg = "Ticket '%s' reopened" % sha7
        abs_ticket_dir = os.path.join(self.repo.working_dir, it.TICKET_DIR)

        try:
            os.chdir(self.repo.working_dir)
            self.repo.git.symbolic_ref(
                ['HEAD', 'refs/heads/' + it.ITDB_BRANCH])
            i.status = 'open'
            i.save()
            self.repo.git.commit(['-m', msg, match])
            print(msg)

        finally:
            self.repo.git.symbolic_ref(['HEAD', 'refs/heads/' + curr_branch])
            self.repo.git.reset(['HEAD', '--', abs_ticket_dir])
            misc.rmdirs(abs_ticket_dir)
            os.chdir(curr_dir)
Beispiel #7
0
    def leave_ticket(self, sha):
        i, _, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)
        fullname = self.get_cfg('name', section='user', default='Anonymous')

        if i.assigned_to == '-':
            print("Ticket '%s' already left alone" % (sha7))
            return

        # prepare for the critical section
        curr_branch = self.repo.active_branch.name
        curr_dir = os.getcwd()
        msg = "Ticket %s was left alone from '%s'" % (sha7, fullname)
        abs_ticket_dir = os.path.join(self.repo.working_dir, it.TICKET_DIR)

        try:
            os.chdir(self.repo.working_dir)
            self.repo.git.symbolic_ref(
                ['HEAD', 'refs/heads/' + it.ITDB_BRANCH])
            i.assigned_to = '-'
            i.save()
            self.repo.git.commit(['-m', msg, match])
            print(msg)
        except Exception:
            print("Error commiting change -- cleanup")
        finally:
            self.repo.git.symbolic_ref(['HEAD', 'refs/heads/' + curr_branch])
            self.repo.git.reset(['HEAD', '--', abs_ticket_dir])
            misc.rmdirs(abs_ticket_dir)
            os.chdir(curr_dir)
Beispiel #8
0
 def get_ticket(self, sha):
     match = self.match_or_error(sha)
     contents = git.cat_file(it.ITDB_BRANCH + ':' + match)
     parent, fullsha = os.path.split(match)
     rel = os.path.basename(parent)
     sha7 = misc.chop(fullsha, 7)
     i = ticket.create_from_lines(contents, fullsha, rel)
     return (i, rel, fullsha, match)
Beispiel #9
0
 def get_ticket(self, sha):
     match = self.match_or_error(sha)
     contents = git.cat_file(it.ITDB_BRANCH + ':' + match)
     parent, fullsha = os.path.split(match)
     rel = os.path.basename(parent)
     sha7 = misc.chop(fullsha, 7)
     i = ticket.create_from_lines(contents, fullsha, rel, True)
     return (i, rel, fullsha, match)
Beispiel #10
0
    def oneline(self, cols, annotate_ownership):
        colstrings = []
        for col in cols:
            if not col['visible']:
                continue

            w = col['width']
            id = col['id']
            if id == 'id':
                colstrings.append(misc.chop(self.id, w))
            elif id == 'type':
                colstrings.append(misc.pad_to_length(self.type, w))
            elif id == 'date':
                colstrings.append(
                    misc.pad_to_length(
                        '%d-%02d-%02d' %
                        (self.date.year, self.date.month, self.date.day), w))
            elif id == 'title':
                title = self.title
                if self.assigned_to != '-' and annotate_ownership:
                    name_suffix = ' (%s)' % self.assigned_to.split()[0]
                    w = w - len(name_suffix)
                    title = '%s%s' % (misc.pad_to_length(
                        misc.chop(title, w, '..'), w), name_suffix)
                else:
                    title = misc.pad_to_length(misc.chop(title, w, '..'), w)
                colstrings.append('%s%s%s' % (colors.colors[self.status_colors[self.status]],        \
                                                                            title, \
                                                                            colors.colors['default']))
            elif id == 'status':
                colstrings.append('%s%s%s' % (colors.colors[self.status_colors[self.status]],        \
                                                                            misc.pad_to_length(self.status, 8),                             \
                                        colors.colors['default']))
            elif id == 'prio':
                priostr = self.prio_names[self.prio - 1]
                colstrings.append('%s%s%s' % (colors.colors[self.prio_colors[priostr]],              \
                                                                            misc.pad_to_length(priostr, 4),
                                        colors.colors['default']))
            elif id == 'wght':
                weightstr = self.weight_names[min(
                    3, max(0, int(round(math.log(self.weight, 3)))))]
                colstrings.append(misc.pad_to_length(weightstr, 5))

        return ' '.join(colstrings)
Beispiel #11
0
  def oneline(self, cols, annotate_ownership):
    colstrings = []
    for col in cols:
      if not col['visible']:
        continue

      w = col['width']
      id = col['id']
      if id == 'id':
        colstrings.append(misc.chop(self.id, w))
      elif id == 'type':
        colstrings.append(misc.pad_to_length(self.type, w))
      elif id == 'date':
        colstrings.append(misc.pad_to_length('%s/%s' % (self.date.month, self.date.day), w))
      elif id == 'title':
        title = self.title
        if self.assigned_to != '-' and annotate_ownership:
          name_suffix = ' (%s)' % self.assigned_to.split()[0]
          w = w - len(name_suffix)
          title = '%s%s' % (misc.pad_to_length(misc.chop(title, w, '..'), w), name_suffix)
        else:
          title = misc.pad_to_length(misc.chop(title, w, '..'), w)
        colstrings.append('%s%s%s' % (colors.colors[self.status_colors[self.status]],        \
                                      title, \
                                      colors.colors['default']))
      elif id == 'status':
        colstrings.append('%s%s%s' % (colors.colors[self.status_colors[self.status]],        \
                                      misc.pad_to_length(self.status, 8),                             \
	                  colors.colors['default']))
      elif id == 'prio':
        priostr = self.prio_names[self.prio-1]
        colstrings.append('%s%s%s' % (colors.colors[self.prio_colors[priostr]],              \
                                      misc.pad_to_length(priostr, 4),
	                  colors.colors['default']))
      elif id == 'wght':
        weightstr = self.weight_names[min(3, max(0, int(round(math.log(self.weight, 3)))))]
        colstrings.append(misc.pad_to_length(weightstr, 5))
      elif id == 'hours':
		colstrings.append(misc.pad_to_length(self.devtime, w))

    return ' '.join(colstrings)
Beispiel #12
0
    def edit(self, sha):
        i, rel, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)

        # Save the contents of this ticket to a file, so it can be edited
        fd, filename = mkstemp(prefix='git-it.')
        i.save(filename)
        timestamp1 = os.path.getmtime(filename)
        success = os.system(
            self.get_cfg('editor', default='vim') + ' "%s"' % filename) == 0
        timestamp2 = os.path.getmtime(filename)
        if not success:
            log.printerr("Editing of ticket '%s' failed" % sha7)
            os.remove(filename)
            sys.exit(1)

        if timestamp1 >= timestamp2:
            print("Editing of ticket '%s' cancelled" % sha7)
            os.remove(filename)
            return

        try:
            i = ticket.create_from_file(filename, fullsha, rel)
        except ticket.MalformedTicketFieldException as e:
            log.printerr("Error parsing ticket: %s" % e)
            sys.exit(1)
        except ticket.MissingTicketFieldException as e:
            log.printerr("Error parsing ticket: %s" % e)
            sys.exit(1)

        # Now, when the edit has succesfully taken place, switch branches, commit,
        # and switch back
        curr_branch = self.repo.active_branch.name
        msg = "Ticket '%s' edited" % sha7
        abs_ticket_dir = os.path.join(self.repo.working_dir, it.TICKET_DIR)
        try:
            self.repo.git.symbolic_ref(
                ['HEAD', 'refs/heads/' + it.ITDB_BRANCH])
            i.save()
            self.repo.git.commit(['-m', msg, i.filename()])
            print("Ticket '%s' edited succesfully" % sha7)
        except Exception:
            log.printerr("Error commiting modified ticket.")

        finally:
            self.repo.git.symbolic_ref(['HEAD', 'refs/heads/' + curr_branch])
            self.repo.git.reset(['HEAD', '--', abs_ticket_dir])
            misc.rmdirs(abs_ticket_dir)

        # Remove the temporary file
        os.remove(filename)
Beispiel #13
0
    def leave_ticket(self, sha):
        i, _, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(sha, 7)

        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        msg = 'ticket \'%s\' left alone' % sha7
        i.assigned_to = '-'
        i.save()
        git.command_lines('commit', ['-m', msg, match], from_root=True)
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        print 'ticket \'%s\' left alone' % sha7
Beispiel #14
0
    def rm(self, sha):
        match = self.match_or_error(sha)
        _, basename = os.path.split(match)
        sha7 = misc.chop(basename, 7)

        # Commit the new itdb to the repo
        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        msg = 'removed ticket \'%s\'' % sha7
        git.command_lines('commit', ['-m', msg, match])
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        print 'ticket \'%s\' removed' % sha7
Beispiel #15
0
    def leave_ticket(self, sha):
        i, _, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(sha, 7)

        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        msg = 'ticket \'%s\' left alone' % sha7
        i.assigned_to = '-'
        i.save()
        git.command_lines('commit', ['-m', msg, match], from_root=True)
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        print 'ticket \'%s\' left alone' % sha7
Beispiel #16
0
    def rm(self, sha):
        match = self.match_or_error(sha)
        _, basename = os.path.split(match)
        sha7 = misc.chop(basename, 7)

        # Commit the new itdb to the repo
        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        msg = 'removed ticket \'%s\'' % sha7
        git.command_lines('commit', ['-m', msg, match], from_root=True)
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        print 'ticket \'%s\' removed'% sha7
Beispiel #17
0
  def take_ticket(self, sha):
    i, _, fullsha, match = self.get_ticket(sha)
    sha7 = misc.chop(sha, 7)

    curr_branch = git.current_branch()
    git.change_head_branch('git-it')
    fullname = os.popen('git config user.name').read().strip()
    msg = 'ticket \'%s\' taken by %s' % (sha7, fullname)
    i.assigned_to = fullname
    i.save()
    git.command_lines('commit', ['-m', msg, match])
    git.change_head_branch(curr_branch)
    abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
    git.command_lines('reset', ['HEAD', abs_ticket_dir])
    misc.rmdirs(abs_ticket_dir)
    print 'ticket \'%s\' taken' % sha7
    print ''
    self.list()
Beispiel #18
0
    def take_ticket(self, sha):
        i, _, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(sha, 7)

        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        fullname = os.popen('git config user.name').read().strip()
        msg = 'ticket \'%s\' taken by %s' % (sha7, fullname)
        i.assigned_to = fullname
        i.save()
        git.command_lines('commit', ['-m', msg, match])
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        print 'ticket \'%s\' taken' % sha7
        print ''
        self.list()
Beispiel #19
0
    def mv(self, sha, to_rel):
        self.require_itdb()
        i, rel, fullsha, src_path = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)

        src_dir = os.path.join(self.repo.working_dir, it.TICKET_DIR, rel)
        target_dir = os.path.join(self.repo.working_dir, it.TICKET_DIR, to_rel)
        target_path = os.path.join(target_dir, fullsha)
        if src_dir == target_dir:
            log.printerr("Ticket '%s' already in '%s'" % (sha7, to_rel))
            return

        # Create the target dir, if neccessary
        if not os.path.isdir(target_dir):
            misc.mkdirs(target_dir)

        # Try to move the file into it
        curr_branch = self.repo.active_branch.name
        msg = "Moved ticket '%s' (%s --> %s)" % (sha7, rel, to_rel)
        abs_ticket_dir = os.path.join(self.repo.working_dir, it.TICKET_DIR)
        try:
            # Commit the new itdb to the repo
            self.repo.git.symbolic_ref(
                ['HEAD', 'refs/heads/' + it.ITDB_BRANCH])

            i.save(target_path)
            if os.path.isfile(src_path):
                os.remove(src_path)

            self.repo.git.add([target_path])
            self.repo.git.commit(['-m', msg, src_path, target_path])
            print("Ticket '%s' moved to release '%s'" % (sha7, to_rel))
        except OSError as e:
            log.printerr("Could not move ticket '%s' to '%s':" %
                         (sha7, to_rel))
            log.printerr(e)
        except Exception:
            log.printerr("Could not move ticket '%s' to '%s':" %
                         (sha7, to_rel))

        finally:
            self.repo.git.symbolic_ref(['HEAD', 'refs/heads/' + curr_branch])
            self.repo.git.reset(['HEAD', '--', abs_ticket_dir])
            misc.rmdirs(abs_ticket_dir)
Beispiel #20
0
    def new(self):
        self.require_itdb()

        # Create a fresh ticket
        try:
            i = ticket.create_interactive(self._gitcfg)
        except KeyboardInterrupt:
            print('')
            print("Aborting new ticket.")
            return None

        # Generate a SHA1 id
        s = sha1_constructor()
        s.update(i.__str__())
        s.update(os.getlogin())
        s.update(datetime.datetime.now().__str__())
        i.id = ticketname = s.hexdigest()

        # Save the ticket to disk
        i.save()
        sha7 = misc.chop(ticketname, 7)
        print("New ticket '%s' saved" % sha7)

        # Commit the new ticket to the 'aaa' branch
        curr_branch = self.repo.active_branch.name
        msg = "%s added ticket '%s'" % (i.issuer, sha7)
        msg = msg.capitalize()
        abs_ticket_dir = os.path.join(self.repo.working_dir, it.TICKET_DIR)

        try:
            self.repo.git.symbolic_ref(
                ['HEAD', 'refs/heads/' + it.ITDB_BRANCH])
            self.repo.git.add([i.filename()])
            self.repo.git.commit(['-m', msg, i.filename()])
        except:
            log.printerr("Error commiting changes to ticket '%s'" % sha7)
        finally:
            os.remove(i.filename())
            self.repo.git.rm(['--cached', i.filename()])
            self.repo.git.symbolic_ref(['HEAD', 'refs/heads/' + curr_branch])
            self.repo.git.reset(['HEAD', '--', abs_ticket_dir])
            misc.rmdirs(abs_ticket_dir)
        return i
Beispiel #21
0
    def finish_ticket(self, sha, new_status):
        i, _, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)
        if i.status not in ['open', 'test']:
            log.printerr('ticket \'%s\' already %s' % (sha7, i.status))
            sys.exit(1)

        # Now, when the edit has succesfully taken place, switch branches, commit,
        # and switch back
        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        i.status = new_status
        msg = '%s ticket \'%s\'' % (i.status, sha7)
        i.save()
        git.command_lines('commit', ['-m', msg, match], from_root=True)
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        print 'ticket \'%s\' %s' % (sha7, new_status)
Beispiel #22
0
    def reopen_ticket(self, sha):
        i, _, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(sha, 7)
        if i.status == 'open':
            log.printerr('ticket \'%s\' already open' % sha7)
            sys.exit(1)

        # Now, when the edit has succesfully taken place, switch branches, commit,
        # and switch back
        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        msg = 'ticket \'%s\' reopened' % sha7
        i.status = 'open'
        i.save()
        git.command_lines('commit', ['-m', msg, match], from_root=True)
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        print 'ticket \'%s\' reopened' % sha7
Beispiel #23
0
    def finish_ticket(self, sha, new_status):
        i, _, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)
        if i.status not in ['open', 'test']:
            log.printerr('ticket \'%s\' already %s' % (sha7, i.status))
            sys.exit(1)

        # Now, when the edit has succesfully taken place, switch branches, commit,
        # and switch back
        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        i.status = new_status
        msg = '%s ticket \'%s\'' % (i.status, sha7)
        i.save()
        git.command_lines('commit', ['-m', msg, match], from_root=True)
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        print 'ticket \'%s\' %s' % (sha7, new_status)
Beispiel #24
0
    def reopen_ticket(self, sha):
        i, _, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(sha, 7)
        if i.status == 'open':
            log.printerr('ticket \'%s\' already open' % sha7)
            sys.exit(1)

        # Now, when the edit has succesfully taken place, switch branches, commit,
        # and switch back
        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        msg = 'ticket \'%s\' reopened' % sha7
        i.status = 'open'
        i.save()
        git.command_lines('commit', ['-m', msg, match], from_root=True)
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        print 'ticket \'%s\' reopened' % sha7
Beispiel #25
0
    def mv(self, sha, to_rel):
        self.require_itdb()
        i, rel, fullsha, src_path = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)

        src_dir = os.path.join(repo.find_root(), it.TICKET_DIR, rel)
        target_dir = os.path.join(repo.find_root(), it.TICKET_DIR, to_rel)
        target_path = os.path.join(target_dir, fullsha)
        if src_dir == target_dir:
            log.printerr('ticket \'%s\' already in \'%s\'' % (sha7, to_rel))
            return

        # Create the target dir, if neccessary
        if not os.path.isdir(target_dir):
            misc.mkdirs(target_dir)

        # Try to move the file into it
        try:
            # Commit the new itdb to the repo
            curr_branch = git.current_branch()
            git.change_head_branch('git-it')

            i.save(target_path)
            if os.path.isfile(src_path):
                os.remove(src_path)

            msg = 'moved ticket \'%s\' (%s --> %s)' % (sha7, rel, to_rel)
            git.command_lines('add', [target_path])
            git.command_lines('commit', ['-m', msg, src_path, target_path])
            git.change_head_branch(curr_branch)
            abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
            git.command_lines('reset', ['HEAD', abs_ticket_dir])
            misc.rmdirs(abs_ticket_dir)

            print 'ticket \'%s\' moved to release \'%s\'' % (sha7, to_rel)
            print ''
            self.list()
        except OSError, e:
            log.printerr('could not move ticket \'%s\' to \'%s\':' %
                         (sha7, to_rel))
            log.printerr(e)
Beispiel #26
0
 def reject_ticket(self, sha, message):
     i, _, fullsha, match = self.get_ticket(sha)
     sha7 = misc.chop(sha, 7)
     if 'rejected' == i.status:
         log.printerr('ticket \'%s\' already rejected' % sha7)
         sys.exit(1)
     if message is None or message == '':
         message = ticket.ask_for_pattern(
             'Reason for rejection: ', ticket.not_empty)
     curr_branch = git.current_branch()
     git.change_head_branch('git-it')
     i.status = 'rejected'
     i.body = 'REJECTED: %s\n\n%s' % (message, i.body)
     msg = '%s ticket \'%s\'' % (i.status, sha7)
     i.save()
     git.command_lines('commit', ['-m', msg, match], from_root=True)
     git.change_head_branch(curr_branch)
     abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
     git.command_lines('reset', ['HEAD', abs_ticket_dir])
     misc.rmdirs(abs_ticket_dir)
     print 'ticket \'%s\' rejected' % sha7
Beispiel #27
0
 def reject_ticket(self, sha, message):
     i, _, fullsha, match = self.get_ticket(sha)
     sha7 = misc.chop(sha, 7)
     if 'rejected' == i.status:
         log.printerr('ticket \'%s\' already rejected' % sha7)
         sys.exit(1)
     if message is None or message == '':
         message = ticket.ask_for_pattern('Reason for rejection: ',
                                          ticket.not_empty)
     curr_branch = git.current_branch()
     git.change_head_branch('git-it')
     i.status = 'rejected'
     i.body = 'REJECTED: %s\n\n%s' % (message, i.body)
     msg = '%s ticket \'%s\'' % (i.status, sha7)
     i.save()
     git.command_lines('commit', ['-m', msg, match], from_root=True)
     git.change_head_branch(curr_branch)
     abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
     git.command_lines('reset', ['HEAD', abs_ticket_dir])
     misc.rmdirs(abs_ticket_dir)
     print 'ticket \'%s\' rejected' % sha7
Beispiel #28
0
  def mv(self, sha, to_rel):
    self.require_itdb()
    i, rel, fullsha, src_path = self.get_ticket(sha)
    sha7 = misc.chop(fullsha, 7)

    src_dir = os.path.join(repo.find_root(), it.TICKET_DIR, rel)
    target_dir = os.path.join(repo.find_root(), it.TICKET_DIR, to_rel)
    target_path = os.path.join(target_dir, fullsha)
    if src_dir == target_dir:
      log.printerr('ticket \'%s\' already in \'%s\'' % (sha7, to_rel))
      return

    # Create the target dir, if neccessary
    if not os.path.isdir(target_dir):
      misc.mkdirs(target_dir)

    # Try to move the file into it
    try:
      # Commit the new itdb to the repo
      curr_branch = git.current_branch()
      git.change_head_branch('git-it')

      i.save(target_path)
      if os.path.isfile(src_path):
        os.remove(src_path)

      msg = 'moved ticket \'%s\' (%s --> %s)' % (sha7, rel, to_rel)
      git.command_lines('add', [target_path])
      git.command_lines('commit', ['-m', msg, src_path, target_path])
      git.change_head_branch(curr_branch)
      abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
      git.command_lines('reset', ['HEAD', abs_ticket_dir])
      misc.rmdirs(abs_ticket_dir)

      print 'ticket \'%s\' moved to release \'%s\'' % (sha7, to_rel)
      print ''
      self.list()
    except OSError, e:
      log.printerr('could not move ticket \'%s\' to \'%s\':' % (sha7, to_rel))
      log.printerr(e)
Beispiel #29
0
    def edit(self, sha):
        i, rel, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)

        # Save the contents of this ticket to a file, so it can be edited
        i.save(it.EDIT_TMP_FILE)
        timestamp1 = os.path.getmtime(it.EDIT_TMP_FILE)
        # fetch the editor command from the following sources in this order:
        #    - git config --local core.editor
        #    - git config --global core.editor
        #    - git config --system core.editor
        #    - $GIT_EDITOR
        #    - $EDITOR
        #    - /usr/bin/nano
        success = os.system('%s "%s"' %
                            (git.get_editor(), it.EDIT_TMP_FILE)) == 0
        timestamp2 = os.path.getmtime(it.EDIT_TMP_FILE)
        if success:
            if timestamp1 < timestamp2:
                try:
                    i = ticket.create_from_file(it.EDIT_TMP_FILE, fullsha, rel)
                except ticket.MalformedTicketFieldException, e:
                    print 'Error parsing ticket: %s' % e
                    sys.exit(1)
                except ticket.MissingTicketFieldException, e:
                    print 'Error parsing ticket: %s' % e
                    sys.exit(1)

                # Now, when the edit has succesfully taken place, switch branches, commit,
                # and switch back
                curr_branch = git.current_branch()
                git.change_head_branch('git-it')
                msg = 'ticket \'%s\' edited' % sha7
                i.save()
                git.command_lines('commit', ['-m', msg, i.filename()])
                git.change_head_branch(curr_branch)
                abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
                git.command_lines('reset', ['HEAD', abs_ticket_dir])
                misc.rmdirs(abs_ticket_dir)
                print 'ticket \'%s\' edited succesfully' % sha7
Beispiel #30
0
    def edit(self, sha):
        i, rel, fullsha, match = self.get_ticket(sha)
        sha7 = misc.chop(fullsha, 7)

        # Save the contents of this ticket to a file, so it can be edited
        i.save(it.EDIT_TMP_FILE)
        timestamp1 = os.path.getmtime(it.EDIT_TMP_FILE)
        # fetch the editor command from the following sources in this order:
        #    - git config --local core.editor
        #    - git config --global core.editor
        #    - git config --system core.editor
        #    - $GIT_EDITOR
        #    - $EDITOR
        #    - /usr/bin/nano
        success = os.system('%s "%s"' % (git.get_editor(),it.EDIT_TMP_FILE)) == 0
        timestamp2 = os.path.getmtime(it.EDIT_TMP_FILE)
        if success:
            if timestamp1 < timestamp2:
                try:
                    i = ticket.create_from_file(it.EDIT_TMP_FILE, fullsha, rel)
                except ticket.MalformedTicketFieldException, e:
                    print 'Error parsing ticket: %s' % e
                    sys.exit(1)
                except ticket.MissingTicketFieldException, e:
                    print 'Error parsing ticket: %s' % e
                    sys.exit(1)

                # Now, when the edit has succesfully taken place, switch branches, commit,
                # and switch back
                curr_branch = git.current_branch()
                git.change_head_branch('git-it')
                msg = 'ticket \'%s\' edited' % sha7
                i.save()
                git.command_lines('commit', ['-m', msg, i.filename()])
                git.change_head_branch(curr_branch)
                abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
                git.command_lines('reset', ['HEAD', abs_ticket_dir])
                misc.rmdirs(abs_ticket_dir)
                print 'ticket \'%s\' edited succesfully' % sha7
Beispiel #31
0
    def new(self):
        self.require_itdb()

        # Create a fresh ticket
        try:
            i = ticket.create_interactive()
        except KeyboardInterrupt:
            print ''
            print 'aborting new ticket'
            return None

        # Generate a SHA1 id
        s = sha1_constructor()
        s.update(i.__str__())
        s.update(os.getenv('LOGNAME'))
        s.update(datetime.datetime.now().__str__())
        i.id = s.hexdigest()

        # Save the ticket to disk
        i.save()
        _, ticketname = os.path.split(i.filename())
        sha7 = misc.chop(ticketname, 7)
        print 'new ticket \'%s\' saved' % sha7

        # Commit the new ticket to the 'aaa' branch
        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        git.command_lines('add', [i.filename()])
        msg = '%s added ticket \'%s\'' % (i.issuer, sha7)
        git.command_lines('commit', ['-m', msg, i.filename()])
        os.remove(i.filename())
        git.command_lines('rm', ['--cached', i.filename()])
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        return i
Beispiel #32
0
    def new(self):
        self.require_itdb()

        # Create a fresh ticket
        try:
            i = ticket.create_interactive()
        except KeyboardInterrupt:
            print ''
            print 'aborting new ticket'
            return None

        # Generate a SHA1 id
        s = sha1_constructor()
        s.update(i.__str__())
        s.update(os.getlogin())
        s.update(datetime.datetime.now().__str__())
        i.id = s.hexdigest()

        # Save the ticket to disk
        i.save()
        _, ticketname = os.path.split(i.filename())
        sha7 = misc.chop(ticketname, 7)
        print 'new ticket \'%s\' saved' % sha7

        # Commit the new ticket to the 'aaa' branch
        curr_branch = git.current_branch()
        git.change_head_branch('git-it')
        git.command_lines('add', [i.filename()])
        msg = '%s added ticket \'%s\'' % (i.issuer, sha7)
        git.command_lines('commit', ['-m', msg, i.filename()])
        os.remove(i.filename())
        git.command_lines('rm', ['--cached', i.filename()])
        git.change_head_branch(curr_branch)
        abs_ticket_dir = os.path.join(repo.find_root(), it.TICKET_DIR)
        git.command_lines('reset', ['HEAD', abs_ticket_dir])
        misc.rmdirs(abs_ticket_dir)
        return i