예제 #1
0
    def init(self):
        if self.itdb_exists():
            print 'Already initialized issue database in branch \'%s\'.' % \
                                                                   it.ITDB_BRANCH
            return

        # else, initialize the new .it database alongside the .git repo
        gitrepo = repo.find_git_repo()
        if not gitrepo:
            log.printerr('Not a valid Git repository.')
        else:
            parent, _ = os.path.split(gitrepo)
            ticket_dir = os.path.join(parent, it.TICKET_DIR)
            hold_file = os.path.join(ticket_dir, it.HOLD_FILE)
            misc.mkdirs(ticket_dir)
            misc.write_file_contents(hold_file, \
                   'This is merely a placeholder file for git-it that prevents ' + \
                   'this directory from\nbeing pruned by Git.')

            # Commit the new itdb to the repo
            curr_branch = git.current_branch()
            git.change_head_branch('git-it')
            git.command_lines('add', [hold_file])
            msg = 'Initialized empty ticket database.'
            git.command_lines('commit', ['-m', msg, hold_file])
            os.remove(hold_file)
            os.rmdir(ticket_dir)
            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 'Initialized empty ticket database.'
예제 #2
0
  def save(self, file = None):
    headers = [ 'Subject: %s'     % self.title,
                'Issuer: %s'      % self.issuer,
                'Date: %s'        % self.date.strftime(DATE_FORMAT),
                'Type: %s'        % self.type,
                'Priority: %d'    % self.prio,
                'Status: %s'      % self.status,
                'Assigned to: %s' % self.assigned_to,
                '',
                self.body
              ]
    contents = os.linesep.join(headers)

    # If an explicit file name is not given, calculate the default
    if file is None:
      file = self.filename()

    # Write the file
    dir, _ = os.path.split(file)
    if dir and not os.path.isdir(dir):
      misc.mkdirs(dir)
    f = open(file, 'w')
    try:
      f.write(contents)
    finally:
      f.close
예제 #3
0
파일: gitit.py 프로젝트: dongrote/git-it
    def init(self):
        if self.itdb_exists():
            print 'Already initialized issue database in branch \'%s\'.' % \
                                                                                                                         it.ITDB_BRANCH
            return

        # else, initialize the new .it database alongside the .git repo
        gitrepo = repo.find_git_repo()
        if not gitrepo:
            log.printerr('Not a valid Git repository.')
        else:
            parent, _ = os.path.split(gitrepo)
            ticket_dir = os.path.join(parent, it.TICKET_DIR)
            hold_file = os.path.join(ticket_dir, it.HOLD_FILE)
            misc.mkdirs(ticket_dir)
            misc.write_file_contents(hold_file, \
                         'This is merely a placeholder file for git-it that prevents ' + \
                         'this directory from\nbeing pruned by Git.')

            # Commit the new itdb to the repo
            curr_branch = git.current_branch()
            git.change_head_branch('git-it')
            git.command_lines('add', [hold_file])
            msg = 'Initialized empty ticket database.'
            git.command_lines('commit', ['-m', msg, hold_file])
            os.remove(hold_file)
            os.rmdir(ticket_dir)
            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 'Initialized empty ticket database.'
예제 #4
0
    def init(self):
        """ Initializes a ITDB if it does not exists. Otherwise search for
            a remote ITDB an branch from it.
        """
        # check wheter it is already initialzed
        if it.ITDB_BRANCH in [b.name for b in self.repo.branches]:
            # check for the hold file
            abs_hold_file = os.path.join(it.TICKET_DIR, it.HOLD_FILE)
            if abs_hold_file in [
                    x.path for x in self.itdb_tree.list_traverse(depth=1)
            ]:
                print("Issue database already initialized.")
                return

        # search for a ITDB on a remote branch
        for r in self.repo.remotes:
            for ref in r.refs:
                if ref.name.endswith(it.ITDB_BRANCH):
                    print("Initialize ticket database from %s." % ref.name)
                    self.repo.create_head('refs/heads/%s' % it.ITDB_BRANCH,
                                          ref.name)
                    return

        # else, initialize the new .it database alongside the .git repo
        gitrepo = self.repo.git_dir
        if not gitrepo:
            log.printerr("%s: Not a valid Git repository." % gitrepo)
            return

        #FIXME: use working_dir directly instead of assuming 'git_repo'
        #       is work_dir/.git
        parent, _ = os.path.split(gitrepo)
        ticket_dir = os.path.join(parent, it.TICKET_DIR)
        hold_file = os.path.join(ticket_dir, it.HOLD_FILE)
        curr_branch = self.repo.active_branch.name
        msg = "Initialized empty ticket database."
        abs_ticket_dir = os.path.join(self.repo.working_dir, it.TICKET_DIR)
        try:
            misc.mkdirs(ticket_dir)
            misc.write_file_contents(hold_file, \
                         'This is merely a placeholder file for git-it that prevents ' + \
                         'this directory from\nbeing pruned by Git.')

            # Commit the new itdb to the repo
            self.repo.git.symbolic_ref(
                ['HEAD', 'refs/heads/' + it.ITDB_BRANCH])
            self.repo.git.add([hold_file])
            self.repo.git.commit(['-m', msg, hold_file])
            print("Initialized empty ticket database.")
        except Exception:
            log.printerr("Error initialising ticket database.")

        finally:
            os.remove(hold_file)
            os.rmdir(ticket_dir)
            self.repo.git.symbolic_ref(['HEAD', 'refs/heads/' + curr_branch])
            self.repo.git.reset(['HEAD', '--', abs_ticket_dir])
            misc.rmdirs(abs_ticket_dir)
예제 #5
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)
예제 #6
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)
예제 #7
0
파일: gitit.py 프로젝트: maurin/git-it
  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)