Skip to content

Fix #2429 - Update button compat with NETCORE#2432

Merged
jmcouffin merged 4 commits intodevelopfrom
fix/2429
Nov 4, 2024
Merged

Fix #2429 - Update button compat with NETCORE#2432
jmcouffin merged 4 commits intodevelopfrom
fix/2429

Conversation

@jmcouffin
Copy link
Copy Markdown
Contributor

fix #2429

@jmcouffin jmcouffin added Bug Bug that stops user from using the tool or a major portion of pyRevit functionality [class] pyRevit 5 pyRevit 5 coming release labels Oct 24, 2024
@dosymep
Copy link
Copy Markdown
Member

dosymep commented Oct 24, 2024

@jmcouffin maybe try to use Ping?

@jmcouffin
Copy link
Copy Markdown
Contributor Author

@jmcouffin maybe try to use Ping?

I will have a look eventually,
I am a bit swamped with work right now.

@sanzoghenzo
Copy link
Copy Markdown
Contributor

sanzoghenzo commented Oct 24, 2024

Do we really need to check the connection before doing anything? It makes sense if we don't want to crash the code with timeout exceptions... anyway:

  • can_access_url is only used by check_internet_connection;
  • check_internet_connection uses (not-so-)random urls that have nothing to do with the update process (well, only github.com does), and returns the first successful url, but nobody cares about it
  • check_internet_connection is only used by versionmgr.updater._check_connection that actually "cares" about that url, just to display a debug message and return True

This SO answer suggests using socket and a fixed ip address and tcp port instead of relying on name resolutions and application layers.
Here's the code, that I would put in the _check_connection function and discard the other two functions
Not sure if it plays well with IronPython/python.net, though...

import socket

def _check_connection(host="8.8.8.8", port=53, timeout=3):
    """
    Host: 8.8.8.8 (google-public-dns-a.google.com)
    OpenPort: 53/tcp
    Service: domain (DNS/TCP)
    """
    try:
        socket.setdefaulttimeout(timeout)
        socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
        return True
    except socket.error as ex:
        print(ex)  # change it with some logging
        return False

Obviously the .net Ping solution could be the best solution, so that we can port the core of pyrevit to .NET more easily 😉

@sanzoghenzo
Copy link
Copy Markdown
Contributor

I didn't test it, but something like this should work

from System.Net.NetworkInformation import Ping, IPStatus

def _check_connection(ip_address="8.8.8.8"):
    ping_sender = Ping()
    try:
        reply = ping_sender.Send(ip_address)
    except Exception:
        return False
    return reply.Status == IPStatus.Success

@jmcouffin
Copy link
Copy Markdown
Contributor Author

I didn't test it, but something like this should work

from System.Net.NetworkInformation import Ping, IPStatus

def _check_connection(ip_address="8.8.8.8"):
    ping_sender = Ping()
    try:
        reply = ping_sender.Send(ip_address)
    except Exception:
        return False
    return reply.Status == IPStatus.Success

this did not work.

@jmcouffin
Copy link
Copy Markdown
Contributor Author

Do we really need to check the connection before doing anything? It makes sense if we don't want to crash the code with timeout exceptions... anyway:

  • can_access_url is only used by check_internet_connection;
  • check_internet_connection uses (not-so-)random urls that have nothing to do with the update process (well, only github.com does), and returns the first successful url, but nobody cares about it
  • check_internet_connection is only used by versionmgr.updater._check_connection that actually "cares" about that url, just to display a debug message and return True

This SO answer suggests using socket and a fixed ip address and tcp port instead of relying on name resolutions and application layers. Here's the code, that I would put in the _check_connection function and discard the other two functions Not sure if it plays well with IronPython/python.net, though...

import socket

def _check_connection(host="8.8.8.8", port=53, timeout=3):
    """
    Host: 8.8.8.8 (google-public-dns-a.google.com)
    OpenPort: 53/tcp
    Service: domain (DNS/TCP)
    """
    try:
        socket.setdefaulttimeout(timeout)
        socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
        return True
    except socket.error as ex:
        print(ex)  # change it with some logging
        return False

Obviously the .net Ping solution could be the best solution, so that we can port the core of pyrevit to .NET more easily 😉

on the contrary, this did work (tested in 2022 and 2025)

@jmcouffin jmcouffin merged commit 0283bcb into develop Nov 4, 2024
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Nov 4, 2024

📦 New work-in-progress (wip) builds are available for 5.0.0.24309+2043-wip

@sanzoghenzo sanzoghenzo mentioned this pull request Nov 5, 2024
5 tasks
@tay0thman
Copy link
Copy Markdown
Contributor

Testing WIP build: [5.0.0.24309+2043-wip]

IronPython Traceback:
Traceback (most recent call last):
File "C:\Program Files\pyRevit-Master\bin\netcore\engines\pyRevitLoader.py", line 30, in
File "C:\Program Files\pyRevit-Master\pyrevitlib\pyrevit\loader\sessionmgr.py", line 30, in
File "C:\Program Files\pyRevit-Master\pyrevitlib\pyrevit\versionmgr\updater.py", line 14, in
ImportError: No module named NetworkInformation

@jmcouffin jmcouffin mentioned this pull request Nov 10, 2024
@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.24315+1435-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.24325+1012-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 3, 2024

📦 New work-in-progress (wip) builds are available for 5.0.0.24338+2325-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 5, 2024

📦 New work-in-progress (wip) builds are available for 5.0.0.24340+1616-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 5, 2024

📦 New work-in-progress (wip) builds are available for 5.0.0.24340+1645-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.24345+0715-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.24351+0714-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.24354+1726-wip

@jmcouffin jmcouffin deleted the fix/2429 branch December 28, 2024 13:34
@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.24364+2228-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.24364+2256-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.24365+2215-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 6, 2025

📦 New work-in-progress (wip) builds are available for 5.0.0.25006+1041-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 9, 2025

📦 New work-in-progress (wip) builds are available for 5.0.0.25009+2113-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.25010+1021-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.25010+1128-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.25013+1201-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.25013+1638-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.25013+1855-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.25013+1857-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.25015+1341-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.25015+1357-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.25024+1520-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.25024+1957-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.25025+1310-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.25030+1056-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.25030+1130-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.25030+1138-wip

@github-actions
Copy link
Copy Markdown
Contributor

📦 New work-in-progress (wip) builds are available for 5.0.0.25031+1700-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 1, 2025

📦 New work-in-progress (wip) builds are available for 5.0.0.25032+1615-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 1, 2025

📦 New work-in-progress (wip) builds are available for 5.0.0.25032+1635-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 1, 2025

📦 New work-in-progress (wip) builds are available for 5.0.0.25032+1841-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 2, 2025

📦 New work-in-progress (wip) builds are available for 5.0.0.25033+1337-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 2, 2025

📦 New work-in-progress (wip) builds are available for 5.0.0.25033+1402-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 3, 2025

📦 New work-in-progress (wip) builds are available for 5.0.0.25034+1241-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 3, 2025

📦 New work-in-progress (wip) builds are available for 5.0.0.25034+1511-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 3, 2025

📦 New public release are available for 5.0.0.24174+2300

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Bug that stops user from using the tool or a major portion of pyRevit functionality [class] pyRevit 5 pyRevit 5 coming release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: update button in 2025

4 participants