Skip to content

Commit

Permalink
v0.8 - fixed support for x5/x4 ending on providers - added command li…
Browse files Browse the repository at this point in the history
…ne parameters
  • Loading branch information
Arnvid Karstad committed Jan 8, 2020
1 parent 73f3a5e commit fe1269e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
47 changes: 41 additions & 6 deletions tf_pupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
import zipfile
import sys
import re
import getopt

tfver = 0.7
tfver = 0.8
debug = False
verbose = False

Expand All @@ -33,6 +34,31 @@ def remove_prefix(text, prefix):
sys.stderr.write("You need python 3.6 or later to run this script\n")
exit(1)

fullCmdArguments = sys.argv
argumentList = fullCmdArguments[1:]

unixOptions = "hdv"
gnuOptions = ["help","debug","verbose"]
try:
arguments, values = getopt.getopt(argumentList, unixOptions, gnuOptions)
except getopt.error as err:
print (str(err))
sys.exit(2)

for currentArgument, currentValue in arguments:
if currentArgument in ("-v", "--verbose"):
print ("enabling verbose mode.")
verbose = True
elif currentArgument in ("-h", "--help"):
print ("displaying help")
print ("-h or --help - this text")
print ("-d or --debug - enable debug mode")
print ("-v or --verbose - enable verbose mode")
exit(1)
elif currentArgument in ("-d", "--debug"):
print ("enabling debug mode.")
debug = True

config = configparser.ConfigParser()
config.read('tf_pupdate.ini')
config.sections()
Expand Down Expand Up @@ -77,25 +103,33 @@ def remove_prefix(text, prefix):
nodes = html_content.xpath('/html/body/ul/li/a/text()')
tfp_filename=nodes[1]
tfp_version=remove_prefix(tfp_filename, option+"_")
tfp_lfilename=option+"_v"+tfp_version+"_x4"
tfp_lfilename=option+"_v"+tfp_version
tfp_lfilename_x4=option+"_v"+tfp_version+"_x4"
tfp_lfilename_x5=option+"_v"+tfp_version+"_x5"
tfp_url = provider_url+tfp_version+"/"+tfp_filename+"_"+p_os+"_"+p_tfarch+".zip"
tfp_lzippath = tmp_dir+"/"+tfp_filename+"_"+p_os+"_"+p_tfarch+".zip"
if debug : print(tfp_url)
if debug : print(tfp_lfilename)
tfp_lfile = Path(plugins_dir+"/"+tfp_lfilename)
if debug : print(tfp_lfile)
if os.path.isfile(tfp_lfile):
tfp_lfile_x4 = Path(plugins_dir+"/"+tfp_lfilename_x4)
tfp_lfile_x5 = Path(plugins_dir+"/"+tfp_lfilename_x5)
if debug : print("looking for ",tfp_lfile,".")
if (os.path.isfile(tfp_lfile_x4) or os.path.isfile(tfp_lfile_x5)):
if verbose: print("Local file exists:",tfp_lfilename,"not upgrading")
else:
print("Local file does not exist:",tfp_lfilename, " upgrading")
print("Local file does not exist:",tfp_lfilename," upgrading")
if os.path.isfile(tfp_lzippath):
if verbose: print("Local zip file does exist: "+tfp_filename+"_"+p_os+"_"+p_tfarch+".zip - skipping download.")
else:
if verbose: print("Local zip file does not exist: "+tfp_filename+"_"+p_os+"_"+p_tfarch+".zip")
urllib.request.urlretrieve(tfp_url, tfp_lzippath)
zfile = zipfile.ZipFile(tfp_lzippath)
zfile.extract(tfp_lfilename,plugins_dir)
zfile.extractall(plugins_dir)
zfile.close
if os.path.isfile(tfp_lfile_x5):
tfp_lfile = tfp_lfile_x5
if os.path.isfile(tfp_lfile_x4):
tfp_lfile = tfp_lfile_x4
os.chmod(tfp_lfile, 0o755)

tf_url = release_url+"terraform/"
Expand Down Expand Up @@ -148,3 +182,4 @@ def remove_prefix(text, prefix):




2 changes: 1 addition & 1 deletion tf_pupdate.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
python3.7 tf_pupdate.py
python3.7 tf_pupdate.py $1 $2 $3

0 comments on commit fe1269e

Please sign in to comment.