Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
OPAL
runOPAL
Commits
68c546d5
Commit
68c546d5
authored
May 08, 2020
by
Renato Bellotti
Browse files
Code reformatting for better compliance with PEP8.
parent
69761a5e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
26 deletions
+21
-26
runOPAL/PathNameGenerator.py
runOPAL/PathNameGenerator.py
+8
-15
runOPAL/opaldict.py
runOPAL/opaldict.py
+13
-11
No files found.
runOPAL/PathNameGenerator.py
View file @
68c546d5
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
runOPAL/opaldict.py
View file @
68c546d5
...
...
@@ -9,6 +9,8 @@ OpalDictionary class
@author: Yves Ineichen
@version: 0.1
"""
class
OpalDict
:
def
__init__
(
self
,
template
):
...
...
@@ -25,7 +27,7 @@ class OpalDict:
def
__setitem__
(
self
,
key
,
value
):
scalevars
=
{}
scalevars
[
'GUNSOLB'
]
=
1.0
scalevars
[
'GUNSOLB'
]
=
1.0
try
:
self
.
dict
[
key
]
=
value
*
scalevars
[
key
]
...
...
@@ -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
:
...
...
@@ -87,15 +89,15 @@ class OpalDict:
def
addUserValues
(
self
,
argv
):
for
arg
in
argv
:
if
arg
.
find
(
"="
)
>
0
:
data
=
str
(
arg
.
split
(
" "
))
# arguments are separated by spaces
eqsidx
=
data
.
find
(
"="
)
# idx of =
data
=
str
(
arg
.
split
(
" "
))
# arguments are separated by spaces
eqsidx
=
data
.
find
(
"="
)
# idx of =
var
=
data
[
2
:
eqsidx
]
rhs
=
data
[
eqsidx
+
1
:
len
(
data
)
-
2
]
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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment