Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Corryvreckan
Corryvreckan
Commits
83df909e
Commit
83df909e
authored
Apr 06, 2021
by
Jens Kroeger
Browse files
completed porting of jobsub to python3
parent
4d9de7a4
Changes
1
Hide whitespace changes
Inline
Side-by-side
jobsub/jobsub.py
View file @
83df909e
...
...
@@ -98,13 +98,13 @@ def loadparamsfromcsv(csvfilename, runs):
def
rewind
(
self
):
self
.
f
.
seek
(
0
)
self
.
linecount
=
0
def
next
(
self
):
line
=
next
(
self
.
f
)
def
__
next
__
(
self
):
line
=
self
.
f
.
__next__
(
)
self
.
linecount
+=
1
while
line
.
startswith
(
bytes
(
self
.
commentstring
,
encoding
=
'utf-8'
)
)
or
not
line
.
strip
():
# test if line commented or empty
line
=
next
(
self
.
f
)
while
line
.
startswith
(
self
.
commentstring
)
or
not
line
.
strip
():
# test if line commented or empty
line
=
self
.
f
.
__next__
(
)
self
.
linecount
+=
1
return
line
return
str
(
line
)
def
__iter__
(
self
):
return
self
...
...
@@ -117,7 +117,7 @@ def loadparamsfromcsv(csvfilename, runs):
exit
(
1
)
try
:
log
.
debug
(
"Opening csv file '"
+
csvfilename
+
"'."
)
csvfile
=
open
(
csvfilename
,
'r
b
'
)
csvfile
=
open
(
csvfilename
,
'r
t
'
)
filteredfile
=
CommentedFile
(
csvfile
)
try
:
...
...
@@ -125,19 +125,16 @@ def loadparamsfromcsv(csvfilename, runs):
sample
=
""
try
:
while
(
len
(
sample
)
<
1024
):
sample
+=
str
(
next
(
filteredfile
)
)
sample
+=
filteredfile
.
__next__
(
)
except
StopIteration
:
log
.
debug
(
"End of csv file reached, sample limited to "
+
str
(
len
(
sample
))
+
" bytes"
)
dialect
=
csv
.
Sniffer
().
sniff
(
sample
)
# test csv file format details
dialect
.
escapechar
=
"
\\
"
log
.
debug
(
"Determined the CSV dialect as follows: delimiter=%s, doublequote=%s, escapechar=%s, lineterminator=%s, quotechar=%s , quoting=%s, skipinitialspace=%s"
,
dialect
.
delimiter
,
dialect
.
doublequote
,
dialect
.
escapechar
,
list
(
ord
(
c
)
for
c
in
dialect
.
lineterminator
),
dialect
.
quotechar
,
dialect
.
quoting
,
dialect
.
skipinitialspace
)
filteredfile
.
rewind
()
# back to beginning of file
reader
=
csv
.
DictReader
(
csvfile
,
dialect
=
dialect
)
# now process CSV file contents here and load them into memory
#next(reader) # python < 2.6 requires an actual read access before filling 'DictReader.fieldnames'
for
row
in
reader
:
print
(
row
)
reader
=
csv
.
DictReader
(
filteredfile
,
dialect
=
dialect
)
# now process CSV file contents here and load them into memory
reader
.
__next__
()
# python requires an actual read access before filling 'DictReader.fieldnames'
log
.
debug
(
"CSV file contains the header info: %s"
,
reader
.
fieldnames
)
try
:
reader
.
fieldnames
=
[
field
.
lower
()
for
field
in
reader
.
fieldnames
]
# convert to lower case keys to avoid confusion
...
...
@@ -153,7 +150,7 @@ def loadparamsfromcsv(csvfilename, runs):
log
.
info
(
"Successfully loaded csv file'"
+
csvfilename
+
"'."
)
# first: search through csv file to find corresponding runnumber entry line for every run
filteredfile
.
rewind
()
# back to beginning of file
reader
.
next
()
# .. and skip the header line
reader
.
__
next
__
()
# .. and skip the header line
missingRuns
=
list
(
runs
)
# list of runs to look for in csv file
cnt
=
0
...
...
Jens Kroeger
@jekroege
mentioned in commit
cb5bb83a
·
Apr 23, 2021
mentioned in commit
cb5bb83a
mentioned in commit cb5bb83a7343933597dacaffaf09c1e93fbfed1b
Toggle commit list
Write
Preview
Supports
Markdown
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