mirror of https://github.com/Kodomo/esxi-vm
PEP8 conformity
parent
dd097e6ed1
commit
bafad5ff2f
|
@ -1,4 +1,6 @@
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
|
import sys
|
||||||
import yaml
|
import yaml
|
||||||
import datetime # For current Date/Time
|
import datetime # For current Date/Time
|
||||||
from math import log
|
from math import log
|
||||||
|
@ -16,10 +18,10 @@ def setup_config():
|
||||||
#
|
#
|
||||||
# System wide defaults
|
# System wide defaults
|
||||||
#
|
#
|
||||||
ConfigData = dict(
|
config_data = dict(
|
||||||
|
|
||||||
# Your logfile
|
# Your logfile
|
||||||
LOG= os.path.expanduser("~") + "/esxi-vm.log",
|
LOG=os.path.expanduser("~") + "/esxi-vm.log",
|
||||||
|
|
||||||
# Enable/Disable dryrun by default
|
# Enable/Disable dryrun by default
|
||||||
isDryRun=False,
|
isDryRun=False,
|
||||||
|
@ -64,53 +66,56 @@ def setup_config():
|
||||||
VMXOPTS=""
|
VMXOPTS=""
|
||||||
)
|
)
|
||||||
|
|
||||||
ConfigDataFileLocation = os.path.expanduser("~") + "/.esxi-vm.yml"
|
config_data_file_location = os.path.expanduser("~") + "/.esxi-vm.yml"
|
||||||
|
|
||||||
#
|
#
|
||||||
# Get ConfigData from ConfigDataFile, then merge.
|
# Get ConfigData from ConfigDataFile, then merge.
|
||||||
#
|
#
|
||||||
if os.path.exists(ConfigDataFileLocation):
|
if os.path.exists(config_data_file_location):
|
||||||
FromFileConfigData = yaml.safe_load(open(ConfigDataFileLocation))
|
from_file_config_data = yaml.safe_load(open(config_data_file_location))
|
||||||
ConfigData.update(FromFileConfigData)
|
config_data.update(from_file_config_data)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(ConfigDataFileLocation, 'w') as FD:
|
with open(config_data_file_location, 'w') as FD:
|
||||||
yaml.dump(ConfigData, FD, default_flow_style=False)
|
yaml.dump(config_data, FD, default_flow_style=False)
|
||||||
FD.close()
|
FD.close()
|
||||||
except:
|
except:
|
||||||
print "Unable to create/update config file " + ConfigDataFileLocation
|
print "Unable to create/update config file " + config_data_file_location
|
||||||
e = sys.exc_info()[0]
|
e = sys.exc_info()[0]
|
||||||
print "The Error is " + str(e)
|
print "The Error is " + str(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
return ConfigData
|
return config_data
|
||||||
|
|
||||||
def SaveConfig(ConfigData):
|
|
||||||
ConfigDataFileLocation = os.path.expanduser("~") + "/.esxi-vm.yml"
|
def save_config(config_data):
|
||||||
|
config_data_file_location = os.path.expanduser("~") + "/.esxi-vm.yml"
|
||||||
try:
|
try:
|
||||||
with open(ConfigDataFileLocation, 'w') as FD:
|
with open(config_data_file_location, 'w') as FD:
|
||||||
yaml.dump(ConfigData, FD, default_flow_style=False)
|
yaml.dump(config_data, FD, default_flow_style=False)
|
||||||
FD.close()
|
FD.close()
|
||||||
except:
|
except:
|
||||||
print "Unable to create/update config file " + ConfigDataFileLocation
|
print "Unable to create/update config file " + config_data_file_location
|
||||||
e = sys.exc_info()[0]
|
e = sys.exc_info()[0]
|
||||||
print "The Error is " + str(e)
|
print "The Error is " + str(e)
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def theCurrDateTime():
|
def the_current_date_time():
|
||||||
i = datetime.datetime.now()
|
i = datetime.datetime.now()
|
||||||
return str(i.isoformat())
|
return str(i.isoformat())
|
||||||
|
|
||||||
|
|
||||||
unit_list = zip(['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'], [0, 0, 1, 2, 2, 2])
|
unit_list = zip(['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'], [0, 0, 1, 2, 2, 2])
|
||||||
|
|
||||||
|
|
||||||
def float2human(num):
|
def float2human(num):
|
||||||
"""Integer to Human readable"""
|
"""Integer to Human readable"""
|
||||||
if num > 1:
|
if num > 1:
|
||||||
exponent = min(int(log(float(num), 1024)), len(unit_list) - 1)
|
exponent = min(int(log(float(num), 1024)), len(unit_list) - 1)
|
||||||
quotient = float(num) / 1024**exponent
|
quotient = float(num) / 1024**exponent
|
||||||
unit, num_decimals = unit_list[exponent]
|
unit, num_decimals = unit_list[exponent]
|
||||||
format_string = '{:.%sf} {}' % (num_decimals)
|
format_string = '{:.%sf} {}' % num_decimals
|
||||||
return format_string.format(quotient, unit)
|
return format_string.format(quotient, unit)
|
||||||
if num == 0:
|
if num == 0:
|
||||||
return '0 bytes'
|
return '0 bytes'
|
||||||
|
|
Loading…
Reference in New Issue