Пример #1
0
def _get_download_info(info_generator, dburl, download_ids=None, html=False, outfile=None):
    '''processes dinfo ro dstats'''
    session = load_session_for_dinfo(dburl)
    if html:
        openbrowser = False
        if not outfile:
            openbrowser = True
            outfile = os.path.join(gettempdir(),
                                   "s2s_%s.html" % info_generator.__class__.__name__.lower())
        # get_dstats_html returns unicode characters in py2, str in py3,
        # so it is safe to use open like this (cf below):
        with open(outfile, 'w', encoding='utf8', errors='replace') as opn:
            opn.write(info_generator.html(session, download_ids))
        if openbrowser:
            open_in_browser('file://' + outfile)
        threading.Timer(1, lambda: sys.exit(0)).start()
    else:
        itr = info_generator.str_iter(session, download_ids)
        if outfile is not None:
            # itr is an iterator of strings in py2, and str in py3, so open must be input
            # differently (see utils module):
            with open2writetext(outfile, encoding='utf8', errors='replace') as opn:
                for line in itr:
                    line += '\n'
                    opn.write(line)
        else:
            for line in itr:
                print(line)
Пример #2
0
def render_in_browser(html):
    """
    Starts a simple HTTP server, directs the browser to it and handles that
    request before closing down. This avoids the need to create many temp
    files. However, it does mean the page can't be reloaded after which is
    a little odd.
    """

    class RequestHandler(BaseHTTPRequestHandler):

        def do_GET(self):
            """
            Write the HTML to the request file
            """
            self.send_response(200)
            self.send_header("Content-type", "text/html")
            self.end_headers()
            self.wfile.write(html)

    # Start the server on a given random port
    server = HTTPServer(('127.0.0.1', 0), RequestHandler)
    # point the browser to that IP and port.
    open_in_browser('http://127.0.0.1:%s' % server.server_port)
    # handle the single request and then end.
    server.handle_request()
Пример #3
0
    def on_visit_page( self, widget, path, column ):
        if column.get_title() == '':
            return

        url = self.data_view.get_model()[ path ][-1]

        open_in_browser( url )
Пример #4
0
    def open_comparision_in_browser(self, owner, branch):
        base_remote = github.parse_remote(self.get_integrated_remote_url())
        url = base_remote.url
        base_owner = base_remote.owner
        base_branch = self.get_integrated_branch_name()

        open_in_browser("{}/compare/{}:{}...{}:{}?expand=1".format(
            url, base_owner, base_branch, owner, branch))
Пример #5
0
def open_repo(remote):
    """
    Open the GitHub repo in a new browser window, given the specified remote.
    """
    github_repo = parse_remote(remote)
    if not github_repo:
        return None
    open_in_browser(github_repo.url)
Пример #6
0
def open_repo(remote):
    """
    Open the GitHub repo in a new browser window, given the specified remote.
    """
    github_repo = parse_remote(remote)
    if not github_repo:
        return None
    open_in_browser(github_repo.url)
Пример #7
0
def open_issues(remote):
    """
    Open the GitHub issues in a new browser window, given the specified remote.
    """
    github_repo = parse_remote(remote)
    if not github_repo:
        return None
    open_in_browser("{}/issues".format(github_repo.url))
Пример #8
0
def open_issues(remote):
    """
    Open the GitHub issues in a new browser window, given the specified remote.
    """
    github_repo = parse_remote(remote)
    if not github_repo:
        return None
    open_in_browser("{}/issues".format(github_repo.url))
Пример #9
0
    def open_comparision_in_browser(self, owner, branch):
        base_remote = github.parse_remote(self.get_integrated_remote_url())
        url = base_remote.url
        base_owner = base_remote.owner
        base_branch = self.get_integrated_branch_name()

        open_in_browser("{}/compare/{}:{}...{}:{}?expand=1".format(
            url,
            base_owner,
            base_branch,
            owner,
            branch
        ))
Пример #10
0
    def show_action_window(self, label):
        url = ''

        if self.row_values:
            url = self.row_values[0]

        if label == 'Copy URL' and url:
            self.master.clipboard_clear()
            self.master.clipboard_append(url)
        elif label == 'Open URL in Browser' and url:
            open_in_browser(url, new=2)
        elif label == 'View Inlinks' and url:
            ViewInlinks(url, self.crawler.get_inlinks)
Пример #11
0
def open_file_in_browser(rel_path, remote, commit_hash, start_line=None, end_line=None):
    """
    Open the URL corresponding to the provided `rel_path` on `remote`.
    """
    github_repo = parse_remote(remote)
    if not github_repo:
        return None

    line_numbers = "#L{}-L{}".format(start_line, end_line) if start_line is not None else ""

    url = "{repo_url}/blob/{commit_hash}/{path}{lines}".format(
        repo_url=github_repo.url, commit_hash=commit_hash, path=rel_path, lines=line_numbers
    )

    open_in_browser(url)
def _gui(args: _GuiArgs) -> None:
    if 1 + 1 == 2:
        raise Exception("Won't work, gui code was removed")

    port = 5000
    app = get_app()
    pid = app.load_etl_and_get_process_id[0](args.trace_file,
                                             process_predicate_from_parts(
                                                 args.process))

    assert not is_port_used(port)
    params = {"etlPath": args.trace_file, "pid": pid}
    open_in_browser(
        f"http://localhost:{port}/gui/index.html?{urlencode(params)}")

    app.app.run(port=port)
Пример #13
0
def open_file_in_browser(rel_path, remote, commit_hash, start_line=None, end_line=None):
    """
    Open the URL corresponding to the provided `rel_path` on `remote`.
    """
    github_repo = parse_remote(remote)
    if not github_repo:
        return None

    line_numbers = "#L{}-{}".format(start_line, end_line) if start_line is not None else ""

    url = "{repo_url}/blob/{commit_hash}/{path}{lines}".format(
        repo_url=github_repo.url,
        commit_hash=commit_hash,
        path=rel_path,
        lines=line_numbers
    )

    open_in_browser(url)
Пример #14
0
def render_in_browser(html):
    """
    Starts a simple HTTP server, directs the browser to it and handles that
    request before closing down. This avoids the need to create many temp
    files. However, it does mean the page can't be reloaded after which is
    a little odd.
    """
    class RequestHandler(BaseHTTPRequestHandler):
        def do_GET(self):
            """
            Write the HTML to the request file
            """
            self.wfile.write(html)

    # Start the server on a given random port
    server = HTTPServer(('127.0.0.1', 0), RequestHandler)
    # point the browser to that IP and port.
    open_in_browser('http://127.0.0.1:%s' % server.server_port)
    # handle the single request and then end.
    server.handle_request()
Пример #15
0
def run_in_browser(app, port=None, debug=False):
    app.config.update(
        ENV='development'  # https://stackoverflow.com/a/53919435,
        # DEBUG = True,
        # SECRET_KEY=b'_5#y2L"F4Q8z\n\xec]/'
    )
    if port is None:
        port = 5000 + random.randint(0, 999)
    url = "http://127.0.0.1:{0}".format(port)
    if not debug:
        threading.Timer(1.25, lambda: open_in_browser(url)).start()
    app.run(port=port, debug=debug)
Пример #16
0
 def open_comparision_in_browser(self, url, owner, branch):
     open_in_browser("{}/compare/{}:{}?expand=1".format(
         url,
         owner,
         branch
     ))
Пример #17
0
 def open_mr_in_browser(self):
     open_in_browser(self.mr["web_url"])
Пример #18
0
 def btn_ok_pushed(self):
     open_in_browser(Defaults.download_url, new=2)
     self.destroy()
Пример #19
0
 def link_clicked(self, e, link):
     open_in_browser(link, new=2)
Пример #20
0
 def open_pr_in_browser(self):
     open_in_browser(self.pr["html_url"])
Пример #21
0
def _navigate(obj):
    if obj.data and obj.data.get('url'):
        open_in_browser(obj.data['url'])
Пример #22
0
 def open_pr_in_browser(self):
     open_in_browser(self.pr["html_url"])
Пример #23
0
 def open_comparision_in_browser(self, url, owner, branch):
     open_in_browser("{}/compare/{}:{}?expand=1".format(
         url,
         owner,
         branch
     ))