Commit 68c546d5 authored by Renato Bellotti's avatar Renato Bellotti
Browse files

Code reformatting for better compliance with PEP8.

parent 69761a5e
import hashlib
"""
Simple path name generator that ensures that actual path lengths do not exceed
the UNIX 255 chars.
Directory names that are longer than 255 chars will be shortened to a sha
hash. The mapping can later be writte to stdout or file to have access to the
original filename.
"""
class PathNameGenerator:
"""
Ensures that actual path lengths do not exceed the UNIX 255 chars.
def __init__(self):
Directory names that are longer than 255 chars will be shortened to a sha
hash. The mapping can later be written to stdout or file to have access to
the original filename.
"""
def __init__(self):
self.mapping = {}
self.max_path_length = 160
def __str__(self):
mapping = ""
for hash_value, dir_name in self.mapping.items():
mapping += hash_value + " => " + dir_name + "\n"
return mapping
def compress(self, path_name):
if len(path_name) < self.max_path_length:
return path_name
......@@ -37,5 +32,3 @@ class PathNameGenerator:
self.mapping[path_name_hex] = path_name
return path_name_hex
......@@ -9,6 +9,8 @@ OpalDictionary class
@author: Yves Ineichen
@version: 0.1
"""
class OpalDict:
def __init__(self, template):
......@@ -39,13 +41,13 @@ class OpalDict:
return self.dict.items()
def fillDictionary(self, fileName):
fp = open(fileName,"r")
fp = open(fileName, "r")
for line in fp:
if not line == "\n":
li = line.strip()
if not li.startswith("#"):
aline = line.split("#")[0]
name,val = aline.split()
name, val = aline.split()
self.dict[name.rstrip()] = val.lstrip().rstrip()
fp.close()
......@@ -69,7 +71,7 @@ class OpalDict:
#if self.dict.has_key(var):
self.dict[var] = float(self.dict[var])*scaleWith
def getType(self,s):
def getType(self, s):
try:
return int(s)
except ValueError:
......@@ -95,7 +97,7 @@ class OpalDict:
if var in self.dict:
#if self.dict.has_key(var):
#check if we have a range
# check if we have a range
if rhs.find(':') > 0:
range = rhs.split(":")
if len(range) == 3:
......@@ -105,18 +107,18 @@ class OpalDict:
self.rangevars[var] = rvar
self.numRanges = self.numRanges + 1
else:
print( "OpalDict: Range has to be of the form from:to:step!")
print("OpalDict: Range has to be of the form from:to:step!")
sys.exit(1)
else:
try:
val = literal_eval(rhs)
if (isinstance(val, int) or isinstance(val, float)):
self.uservars.append( (var, Decimal(rhs)) )
self.uservars.append((var, Decimal(rhs)))
self.dict[var] = Decimal(rhs) #self.getType(rhs)
except: # add string
self.uservars.append( (var, rhs) )
self.dict[var] = rhs
else:
if var.find("--") < 0: # not a regular option
print( 'OpalDict: Key (' + var + ')not found can not add to dictionary, check the OPAL template file')
print(f'OpalDict: Key ({key}) not found cannot add to dictionary, check the OPAL template file')
sys.exit(1)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment