Skip to content

Commit

Permalink
Merge pull request #2349 from midichef/ping_open
Browse files Browse the repository at this point in the history
[ping-] fix open-ping sheet opening
  • Loading branch information
anjakefala authored Mar 17, 2024
2 parents c8162d9 + 93cf091 commit 7eeb719
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ jobs:
- name: Install lxml dependencies
run: sudo apt install -y libxml2-dev libxslt-dev

- name: Install ping dependencies
run: sudo apt install -y traceroute

- name: Install optional dependencies
run: |
pip3 install -r requirements.txt
Expand Down
19 changes: 14 additions & 5 deletions visidata/features/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@
@VisiData.api
def new_ping(vd, p):
'Open a sheet with the round-trip time for each hop along the path to the given host.'
pingsheet = PingSheet(p.given, source=p.given)
return PingStatsSheet("traceroute_"+pingsheet.name, source=pingsheet)
return makePingStats(p.given)

# open_ping() is called when a local file exists matching the path p, otherwise new_ping() is called
vd.open_ping = vd.new_ping

def makePingStats(ip):
pingsheet = PingSheet(ip, source=ip)
return PingStatsSheet("traceroute_"+pingsheet.name, source=pingsheet)

class PingStatsSheet(Sheet):
help='''# ping/traceroute
Expand All @@ -31,7 +36,7 @@ class PingStatsSheet(Sheet):
]
def loader(self):
sheet = self.source
sheet.ensureLoaded()
vd.sync(sheet.ensureLoaded())

self.rows = sheet.columns

Expand Down Expand Up @@ -71,7 +76,7 @@ def traceroute_response(self, ip, data):
def ping_error(self, ip, data):
if ip in self.sources:
self.sources.remove(ip)
vd.warning("%s removed: %s" % (ip, data))
vd.warning("%s removed: %s" % (ip, data.rstrip()))

def update_traces(self, row, ip):
rtes = self.routes.get(ip)
Expand Down Expand Up @@ -145,7 +150,11 @@ def iterload(self):
vd.option('ping_interval', 0.1, 'wait between ping rounds, in seconds', sheettype=PingSheet)

PingSheet.options.null_value = False
BaseSheet.addCommand('', 'open-ping', 'vd.push(openSource(input("ping: ", type="hostip"), filetype="ping"))', 'open sheet to ping input IP Address')
BaseSheet.addCommand('', 'open-ping', 'vd.push(makePingStats(vd.input("ping: ", type="hostip")))', 'open sheet to ping input IP Address')

vd.addGlobals(
makePingStats=makePingStats,
)

vd.addMenuItems('''
System > Ping IP/hostname > open-ping
Expand Down
1 change: 1 addition & 0 deletions visidata/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def isTestableCommand(longname, cmdlist):
'setcol-incr-step': '2',
'setcol-iter': 'range(1, 100)',
'setcol-format-enum': '1=cat',
'open-ping': 'github.com',
'setcol-input': '5',
'show-expr': 'OrderDate',
'setcol-expr': 'OrderDate',
Expand Down

0 comments on commit 7eeb719

Please sign in to comment.