auto-install-gui: Fix whitespace

Signed-off-by: Matthew Stidham <stidmatt@gmail.com>
This commit is contained in:
Matthew Stidham
2021-12-22 12:19:38 -08:00
committed by shivam
parent ab03c067de
commit df6bf0126e

View File

@@ -11,8 +11,7 @@ import glob
import sys
import subprocess
#===========ARGUMENT PARSING==============
# ===========ARGUMENT PARSING==============
parser = argparse.ArgumentParser()
parser.add_argument("--versionNumber", type=str, help="Specify version number to search for")
@@ -23,13 +22,13 @@ else:
parser.print_help()
parser.exit()
#=============HTML PARSING================
# =============HTML PARSING================
url = "http://jed-centos7/pld/"
with urllib.request.urlopen(url) as response:
html = response.read()
webpage = html.decode('utf-8')
#print(webpage)
# print(webpage)
searchPattern = '(LANforgeGUI_(\d+\.\d+\.\d+)_Linux64.tar.bz2)<\/a><\/td><td align="right">(\d+\-\d+\-\d+\ \d+\:\d+)'
searchResults = re.findall(searchPattern, webpage)
@@ -38,27 +37,30 @@ webFiles = []
for file in searchResults:
if ver == file[1]:
webFiles.append({'filename':file[0], 'timestamp': datetime.datetime.strptime(file[2], "%Y-%m-%d %H:%M")})
webFiles.append({'filename': file[0], 'timestamp': datetime.datetime.strptime(file[2], "%Y-%m-%d %H:%M")})
if len(webFiles) == 0:
print("Failed to find webfile with version number %s" % (ver))
sys.exit(1)
#=========CHECK DIR FOR FILES=============
# =========CHECK DIR FOR FILES=============
filePath = "/home/lanforge/Downloads/"
dir = glob.glob(filePath + "LANforgeGUI_%s*" % ver)
dirFiles = []
for file in dir:
if ver in file:
fileTime = datetime.datetime.strptime(time.ctime(os.stat(file).st_ctime), "%a %b %d %H:%M:%S %Y") # Fri May 8 08:31:43 2020
dirFiles.append({'filename':file[25:], 'timestamp':fileTime})
fileTime = datetime.datetime.strptime(time.ctime(os.stat(file).st_ctime),
"%a %b %d %H:%M:%S %Y") # Fri May 8 08:31:43 2020
dirFiles.append({'filename': file[25:], 'timestamp': fileTime})
if len(dirFiles) == 0:
print("Unable to find file in {filePath} with version %s" % ver)
#sys.exit(1)
#============FIND NEWEST FILES============
# sys.exit(1)
# ============FIND NEWEST FILES============
def findNewestVersion(filesArray):
newest = filesArray[0]
if len(filesArray) > 0:
@@ -68,14 +70,14 @@ def findNewestVersion(filesArray):
return newest
newestWebFile = findNewestVersion(webFiles)
if len(dirFiles) != 0:
newestDirFile = findNewestVersion(dirFiles)
else:
newestDirFile = {'filename':'placeholder', 'timestamp': datetime.datetime.strptime("0", "%H")}
newestDirFile = {'filename': 'placeholder', 'timestamp': datetime.datetime.strptime("0", "%H")}
#=======COMPARE WEB AND DIR FILES=========
# =======COMPARE WEB AND DIR FILES=========
if newestWebFile['timestamp'] > newestDirFile['timestamp']:
try:
if newestDirFile['filename'] != 'placeholder':
@@ -85,8 +87,9 @@ if newestWebFile['timestamp'] > newestDirFile['timestamp']:
else:
print("Found newer version of GUI")
print("Downloading %s from %s" % (newestWebFile['filename'], url))
#=====ATTEMPT DOWNLOAD AND INSTALL=========
subprocess.call(["curl", "-o", "%s%s" % (filePath, newestWebFile['filename']), "%s%s" % (url, newestWebFile['filename'])])
# =====ATTEMPT DOWNLOAD AND INSTALL=========
subprocess.call(
["curl", "-o", "%s%s" % (filePath, newestWebFile['filename']), "%s%s" % (url, newestWebFile['filename'])])
time.sleep(5)
except Exception as e:
print("%s Download failed. Please try again." % e)
@@ -98,22 +101,25 @@ if newestWebFile['timestamp'] > newestDirFile['timestamp']:
print("%s\nExtraction failed. Please try again" % e)
sys.exit(1)
#time.sleep(90)
# time.sleep(90)
try:
if "/home/lanforge/.config/autostart/LANforge-auto.desktop" not in glob.glob("/home/lanforge/.config/autostart/*"):
if "/home/lanforge/.config/autostart/LANforge-auto.desktop" not in glob.glob(
"/home/lanforge/.config/autostart/*"):
print("Copying LANforge-auto.desktop to /home/lanforge/.config/autostart/")
subprocess.call(["cp", "/home/lanforge/%s/LANforge-auto.desktop" % (newestWebFile['filename'][:len(newestWebFile)-18]), "/home/lanforge/.config/autostart/"])
subprocess.call(["cp", "/home/lanforge/%s/LANforge-auto.desktop" % (
newestWebFile['filename'][:len(newestWebFile) - 18]), "/home/lanforge/.config/autostart/"])
except Exception as e:
print("%s\nCopy failed. Please try again" % e)
sys.exit(1)
try:
print("Attempting to install %s at /home/lanforge" % newestWebFile['filename'])
os.system("cd /home/lanforge/%s; sudo bash lfgui_install.bash" % (newestWebFile['filename'][:len(newestWebFile)-18]))
os.system("cd /home/lanforge/%s; sudo bash lfgui_install.bash" % (
newestWebFile['filename'][:len(newestWebFile) - 18]))
except Exception as e:
print("%s\nInstallation failed. Please Try again." % e)
sys.exit(1)
#=========ATTEMPT TO RESTART GUI==========
# =========ATTEMPT TO RESTART GUI==========
# try:
# print("Killing current GUI process")
# os.system("if pgrep java; then pgrep java | xargs kill -9 ;fi")
@@ -124,4 +130,3 @@ if newestWebFile['timestamp'] > newestDirFile['timestamp']:
else:
print("Current GUI version up to date")
sys.exit(0)