Example #1
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

        # List-up the wiki pages
        print("--- Available Wiki Pages ---")
        wiki_page_map = {}
        for i, wp in enumerate(ri.wiki_page.filter(project_id=pid), 1):
            print("{}: {}".format(i, wp.title))
            wiki_page_map[i] = wp.title

        wiki = ri.help_ask_wiki_number()
        if wiki is None:
            print("Input is Invalid")
            return True

        if wiki not in wiki_page_map:
            print("Wiki Page Index is Invalid")
            return True

        title = wiki_page_map[wiki]
        try:
            wiki_page = ri.wiki_page.get(title, project_id=pid)
        except:
            print("Cannot load {}'s wiki page".format(title))
            return True
        text = wiki_page.text.replace('\r\n', '\n')
        data = ri.help_user_input(text.encode())
        ri.wiki_page.update(title, project_id=pid, text=data)
Example #2
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)
Example #3
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
Example #4
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())
Example #5
0
    def run(self):
        # TODO: Get api_key from .api_key
        _, url, key = get_current_redmine()
        ri = RedmineHelper(url=url, key=key)
        issue = ri.help_ask_issue_number()
        if issue is None:
            return True

        if ri.help_ask_preview_issue() is True:
            pnum, wname = get_current_redmine_preview()
            # PREVIEW_WIKI_NAME, PREVIEW_PROJ_NUM
            # should be imported without errors.
            # These variables are used for the access temporary wiki page
            # as a preview.
            if pnum is None or wname is None:
                print("No set PREVIEW_WIKI_NAME, PREVIEW_PROJ_NUM")
                return None

            url_path = 'redmine.piolink.com/projects/{}/wiki/{}'.format(
                pnum, wname)

            url_addr = 'https://' + parse.quote(url_path)

            webbrowser.open_new(url_addr)

            # NamedTemporaryFile instance should have "delete" flag False.
            # Because "help_user_input" uses the "delete" mode temp file.
            tfile = tempfile.NamedTemporaryFile(suffix=".txt", delete=False)

            t = Thread(target=self._preview_checker, args=(tfile.name, ri))
            t.start()

            # Load issue's description and open an interactive editor.
            desc = ri.help_get_description(issue)
            cnt = ri.help_user_input(desc.encode(), _temp=tfile)

            # Removing the tempfile triggers to exit the thread.
            os.unlink(tfile.name)
            t.join()

            ret = ri.help_ask_write_issue()
            if not ret:
                return True

            # Show what you've edited.
            print(cnt)
            ri.help_update_description(issue, cnt)
            return True

        else:
            try:
                ri.help_edit_description(issue)
            except:
                print("Edit description Fail")
                return True
        return True
Example #6
0
 def run(self, shell):
     _, url, key = get_current_redmine()
     ri = RedmineHelper(url=url, key=key)
     lines = ["pid: project name", "---+----------------"]
     for project in ri.project.all():
         pid = project.id
         pname = project.name
         lines.append("{: >3}: {}".format(pid, pname))
     text = '\n'.join(lines)
     ri.help_user_input(text.encode())
     print(text)
Example #7
0
 def run(self):
     _, _, key = get_current_redmine()
     script = ScriptManager(key=key)
     keys = sorted(script.script.keys())
     print('=================================')
     for k in keys:
         data = script.script[k]
         print("{}: {}".format(k, data['title']))
         print("{}".format(data['memo']))
         if k == keys[-1]:
             break
         print('---------------------------------')
     print('=================================')
     return True
Example #8
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!")
Example #9
0
    def run(self):
        # TODO: Get api_key from .api_key
        _, url, key = get_current_redmine()
        ri = RedmineHelper(url=url, key=key)
        issue = ri.help_ask_issue_number()
        if issue is None:
            return True
        try:
            desc = ri.help_get_description(issue)
        except:
            print("Get description Fail")
            return True

        ri.help_user_input(desc.encode())
        return True
Example #10
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
Example #11
0
 def run(self):
     _, _, key = get_current_redmine()
     script = ScriptManager(key=key)
     script.create()
     return True
Example #12
0
 def run(self):
     _, url, key = get_current_redmine()
     rrp = RedmineReviewPage(url=url, key=key)
     return rrp.new_review_page()