Skip to content

Commit a1ecc3e

Browse files
author
Tiuxi
committed
✨ Add version finder
1 parent d7a50cf commit a1ecc3e

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

scripts/gen-man.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@
99

1010
from json import load
1111
from datetime import date
12+
from re import search
1213

1314
###### Parameters ######
1415

1516
# path to the JSON option file
1617
pathToHelpFile = "../src/data/help.json"
1718
# man page section
18-
manSection = 1
19-
# version (left footer)
20-
versionNumber = "Fastfetch 1.0"
19+
manSection = 1
2120
# title (center header)
2221
titlePage = "Fastfetch man page"
2322
# date (center footer)
2423
todayDate = date.today().strftime("%b %d %Y") # format : "Month (abbreviation) Day Year"
24+
# file to fastfetch version (left footer)
25+
pathToVersionFile = "../CMakeLists.txt"
2526

2627

2728
# text displayed in the "NAME" section
@@ -85,6 +86,7 @@ def generateManPage():
8586
try:
8687
with open(pathToHelpFile, 'r') as jsonFile:
8788
helpFileData = load(jsonFile) # json.load
89+
jsonFile.close()
8890
except IOError as error:
8991
print("Error with file", pathToHelpFile, ":", error)
9092
return
@@ -97,7 +99,24 @@ def generateManPage():
9799

98100
print(f".TH man {manSection}", end=" ")
99101
print(f"\"{todayDate}\"", end=" ")
100-
print(f"\"{versionNumber}\"", end=" ")
102+
103+
# version number
104+
try:
105+
with open(pathToVersionFile, 'r') as versionFile:
106+
107+
# research version number in file with regex
108+
for line in versionFile:
109+
researchVersion = search("^\s*VERSION (\d+\.\d+\.\d+)$", line) # re.search()
110+
if (researchVersion != None):
111+
versionNumber = line[researchVersion.start():researchVersion.end()]
112+
break
113+
114+
versionFile.close()
115+
except IOError as error:
116+
print("Error with file", pathToHelpFile, ":", error)
117+
return
118+
119+
print(f"\"{versionNumber}\"", end=" ")
101120
print(f"\"{titlePage}\"")
102121

103122

0 commit comments

Comments
 (0)