-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportchangelog
executable file
·72 lines (53 loc) · 1.8 KB
/
portchangelog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
from bs4 import BeautifulSoup
from subprocess import Popen, PIPE
import urllib.request, urllib.parse, urllib.error
import sys
FS_PORTS_PATH = '/usr/ports/'
#Validate if a port name was specified
if (len(sys.argv) != 2):
sys.exit('Usage: portchangelog port_name')
#Setting requested port name
port_name=sys.argv[1]
#Getting port's category
pipe = Popen(['whereis', port_name], stdout=PIPE, encoding='utf8')
output = pipe.communicate()[0].strip()
paths = output.split(' ')
freshport_path = None
for p in paths:
if p[0:len(FS_PORTS_PATH)] == FS_PORTS_PATH:
freshport_path = p[len(FS_PORTS_PATH):]
break
if freshport_path is None:
sys.exit('Unable to get category of port %s' % (port_name))
#Set Freshports complete URL
freshport_url = "https://www.freshports.org/%s" % (freshport_path)
print("Fetching info at %s\n" % (freshport_url))
#Open URL
handle = urllib.request.urlopen(freshport_url)
#Validate if we get a valid HTML port informations
if handle.getcode() == 404:
sys.exit("The requested URL %s didn't not exist" % (freshport_url) )
html = handle.read()
soup = BeautifulSoup(html, "html.parser")
commit_history_table = soup.findAll('table', class_="commit-list")[0]
rows = commit_history_table.findAll('tr')[2:]
rows = rows[::-1]
for tr in rows:
timestamp = None
version = None
by = None
description = None
cols = tr.findAll('td')
timestamp = cols[0].find(text=True, recursive=False)
if cols[0].span:
version = cols[0].span.string
by = cols[1].find(text=True)
if len(cols) == 3:
description = ''.join(cols[2].findAll(text=True))
print(timestamp , " " , str(version or ''))
print("By:", by)
print()
print(description)
print()
print("-----------------------------------------------------")