Beispiel #1
0
    def run(self, args=None):
        _, _, key = get_current_redmine()
        script = ScriptManager(key=key)

        try:
            idx = redmine_input("Index to run?: ").strip()
        except EOFError:
            print("")
            return True
        except KeyboardInterrupt:
            print("")
            return True

        if idx.isdigit() is False:
            print("Error: Plz Input digital number!")
            return True

        try:
            target = int(idx)
            data = script.script[target]['memo']
        except ValueError:
            print("Error: Input script ID is invalid.")
            return True
        except KeyError:
            print("Error: Input script ID is invalid.")
            return True
        except IndexError:
            print("Error: Input script ID is invalid.")
            return True

        commands = data.strip().split('\n')
        return self.batch(commands)
Beispiel #2
0
    def run(self):
        _, url, key = get_current_redmine()
        ri = RedmineHelper(url=url, key=key)
        pid = ri.help_ask_project_number()
        if pid is None:
            return True

        data = {
            'return': None,
            'redmine_issue': ri,
            'project_number': pid,
            'limit': 500,
            'offset': 0
        }

        def _get_contents(data):
            ri = data['redmine_issue']
            issues = ri.issue.filter(project_id=data['project_number'],
                                     limit=data['limit'],
                                     offset=data['offset'])
            data['return'] = self._print_list_issue(issues)

        t = Thread(target=_get_contents, args=(data, ))
        t.start()

        while True:
            t.join()
            t = None

            contents = data['return']
            if not contents:
                break

            if len(contents) != data['limit'] + 2:  #headers
                ri.help_user_input('\n'.join(data['return']).encode())
                break
            else:
                # buffering
                data['return'] = None
                data['offset'] += data['limit']
                t = Thread(target=_get_contents, args=(data, ))
                t.start()

                ri.help_user_input('\n'.join(contents).encode())

                from redmine_shell.shell.input import redmine_input
                try:
                    cont = redmine_input("Continue?(y/n) ")
                except EOFError:
                    print("")
                    return True
                except KeyboardInterrupt:
                    print("")
                    return True

                if cont == 'y':
                    continue
                else:
                    break
        return True
Beispiel #3
0
    def run(self):
        _, url, key = get_current_redmine()
        ri = RedmineHelper(url=url, key=key)

        from redmine_shell.shell.input import redmine_input
        try:
            nissue = redmine_input("Issue number: ")
        except EOFError:
            print("")
            return True
        except KeyboardInterrupt:
            print("")
            return True

        if nissue.isdigit() is False:
            print("Error: Plz Input digital number!")
            return True

        lines = []
        issue = ri.issue.get(nissue, include=['journals'])
        for journal in issue.journals:
            print(dir(journal))
            lines.append("Journal ID: {}\n{}".format(
                journal.id,
                journal.notes.replace('\r', '').strip()))
        msg = '\n====================================\n'.join(lines)
        ri.help_user_input(msg.encode())
Beispiel #4
0
    def run(self, shell):
        from redmine_shell.shell.input import redmine_input
        script = redmine_input("script: ").strip()
        _, url, key = get_current_redmine()
        path = os.path.abspath('/'.join([DATA_PATH, key, script, 'memo']))
        if os.path.exists(path) is False:
            print("No script")
            return True

        with open(path, 'r') as f:
            data = f.read()

        pc.copy(data)
        print("Copy Done!")
Beispiel #5
0
    def help_confirm_issue_number(self, issue):
        ''' Confirm the issue's subject is correct.
        '''

        from redmine_shell.shell.input import redmine_input

        try:
            tmp_issue_ins = self.issue.get(issue)
        except exceptions.ResourceNotFoundError:
            print("Invalid issue number: out of range.")
            return None

        answer = redmine_input("[#{} {}] -> (y/n)".format(
            tmp_issue_ins.id, tmp_issue_ins.subject))
        return answer
Beispiel #6
0
    def help_ask_wiki_number(cls):
        ''' Ask target wiki name. '''
        from redmine_shell.shell.input import redmine_input

        try:
            wiki = int(redmine_input("Target Wiki Number (default: 1): "))
        except EOFError:
            print("")
            return None
        except KeyboardInterrupt:
            print("")
            return None
        except ValueError:
            return None

        return wiki
Beispiel #7
0
    def help_ask_project_number(cls):
        ''' Ask the project number. '''

        from redmine_shell.shell.input import redmine_input
        try:
            pid = int(redmine_input("Project number: "))
        except ValueError:
            print("Error: Plz Input digital number!")
            return None
        except EOFError:
            print("")
            return None
        except KeyboardInterrupt:
            print("")
            return None
        return pid
Beispiel #8
0
 def help_ask_write_issue(self):
     """ Ask "Are you sure?" """
     from redmine_shell.shell.input import redmine_input
     try:
         question = "Are you sure?(y/N) "
         answer = redmine_input(question)
         if answer == 'y':
             return True
         else:
             return False
     except EOFError:
         print("")
         return False
     except KeyboardInterrupt:
         print("")
         return False
Beispiel #9
0
 def help_ask_preview_issue(cls):
     """ Ask "Do you wanna use preview of issue? """
     from redmine_shell.shell.input import redmine_input
     try:
         question = "Do you wanna use preview of issue?(y/N) "
         answer = redmine_input(question)
         if answer == 'y':
             return True
         else:
             return False
     except EOFError:
         print("")
         return False
     except KeyboardInterrupt:
         print("")
         return False
Beispiel #10
0
    def help_ask_wiki_name(cls):
        ''' Ask target wiki name. '''
        from redmine_shell.shell.redmine_input import redmine_input

        try:
            wiki = redmine_input("Target Wiki Name(default:wiki): ")
        except EOFError:
            print("")
            return None
        except KeyboardInterrupt:
            print("")
            return None

        if wiki.strip():
            return wiki
        else:
            return 'Wiki'
Beispiel #11
0
    def create(self):
        ''' Create Script. '''

        if not self.script:
            idx = 1
        else:
            idx = max(self.script.keys()) + 1

        path = "/".join([self.script_key_path, str(idx)])
        os.mkdir(path)

        title = redmine_input("Title: ").strip()
        os.system("echo {} > {}".format(title, path + '/title'))

        temp = tempfile.NamedTemporaryFile()
        os.system("{} {}".format("vi", temp.name))
        os.system("cp {} {}".format(temp.name, path + '/memo'))
        print("Write done")
Beispiel #12
0
    def run(self):
        _, _, key = get_current_redmine()
        script = ScriptManager(key=key)
        try:
            idx = redmine_input("Index to edit?: ").strip()
        except EOFError:
            print("")
            return True
        except KeyboardInterrupt:
            print("")
            return True

        if idx.isdigit() is False:
            print("Error: Plz Input digital number!")
            return True

        script.edit(int(idx))
        return True
Beispiel #13
0
    def help_ask_issue_number(self):
        """ Interactively get issue number from user. """
        from redmine_shell.shell.input import redmine_input

        while True:
            try:
                # TODO: try except EOF Error..
                issue = int(redmine_input("Issue number?: ").strip())
            except ValueError:
                print("Input Wrong Number")
                return None
            except EOFError:
                print("")
                return None
            except KeyboardInterrupt:
                print("")
                return None

            answer = self.help_confirm_issue_number(issue)
            if answer == 'y':
                break

        return issue