Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Charles Burton
Gaudi
Commits
7c2963dc
Commit
7c2963dc
authored
Mar 11, 2019
by
Marco Clemencic
Browse files
Python 2 & 3 compatibility, part 1 (!832)
parents
a6047069
aeada68b
Changes
22
Hide whitespace changes
Inline
Side-by-side
Gaudi/python/Gaudi/Main.py
View file @
7c2963dc
...
...
@@ -447,7 +447,7 @@ class gaudimain(object):
# It may not be 100% correct, but usually it means a segfault in C++
self
.
ip
.
setProperty
(
'ReturnCode'
,
str
(
128
+
11
))
statuscode
=
False
except
Exception
,
x
:
except
Exception
as
x
:
print
'Exception:'
,
x
# for other exceptions, just set a generic error code
self
.
ip
.
setProperty
(
'ReturnCode'
,
'1'
)
...
...
GaudiExamples/scripts/ExtendedProperties2.py
View file @
7c2963dc
...
...
@@ -67,18 +67,18 @@ if '__main__' == __name__:
try
:
xp2
.
SVector5
=
[
1
,
2
,
3
,
4
,
5
,
6
]
except
Exception
,
e
:
except
Exception
as
e
:
print
' Exception: '
,
e
try
:
xp2
.
Point3D
=
(
1
,
2
,
3
,
4
)
except
Exception
,
e
:
except
Exception
as
e
:
print
' Exception: '
,
e
if
not
isWin
:
try
:
xp2
.
Vector4D
=
(
1
,
2
,
3
)
except
Exception
,
e
:
except
Exception
as
e
:
print
' Exception: '
,
e
xp2
.
Vectors3D
=
[(
1
,
2
,
3
),
(
4
,
5
,
6
),
[
7
,
8
,
9
]]
...
...
GaudiExamples/tests/scripts/test_timing_histo_file.py
View file @
7c2963dc
...
...
@@ -52,7 +52,7 @@ def test():
if
__name__
==
'__main__'
:
try
:
test
()
except
AssertionError
,
a
:
except
AssertionError
as
a
:
print
"FAILURE:"
,
a
sys
.
exit
(
1
)
print
"SUCCESS"
GaudiKernel/python/GaudiKernel/Configurable.py
View file @
7c2963dc
...
...
@@ -514,7 +514,7 @@ class Configurable(object):
if
hasattr
(
cc
,
'setParent'
)
and
parent
:
try
:
cc
.
setParent
(
parent
)
except
RuntimeError
,
e
:
except
RuntimeError
as
e
:
# temporary backdoor resolution for compatibility
log
.
error
(
str
(
e
)
+
'%s'
,
error_explanation
)
ccbd
=
cc
.
configurables
[
cc
.
getJobOptName
()]
...
...
GaudiKernel/python/GaudiKernel/ConfigurableDb.py
View file @
7c2963dc
...
...
@@ -138,7 +138,7 @@ def loadConfigurableDb():
log
.
debug
(
"
\t
-loading [%s]..."
,
confDb
)
try
:
cfgDb
.
_loadModule
(
confDb
)
except
Exception
,
err
:
except
Exception
as
err
:
log
.
warning
(
"Could not load file [%s] !"
,
confDb
)
log
.
warning
(
"Reason: %s"
,
err
)
nFiles
+=
1
...
...
GaudiKernel/python/GaudiKernel/PropertyProxy.py
View file @
7c2963dc
...
...
@@ -146,7 +146,7 @@ class PropertyProxy(object):
except
AttributeError
:
# value not yet set
pass
except
ValueError
,
e
:
except
ValueError
as
e
:
if
allowcompat
:
log
.
error
(
'inconsistent value types for %s.%s (%s)'
%
(
obj
.
getName
(),
self
.
descr
.
__name__
,
str
(
e
)))
...
...
@@ -199,7 +199,7 @@ class GaudiHandlePropertyProxyBase(PropertyProxy):
default
=
self
.
convertDefaultToBeSet
(
obj
,
default
)
if
default
:
self
.
__set__
(
obj
,
default
)
except
AttributeError
,
e
:
except
AttributeError
as
e
:
# change type of exception to avoid false error message
raise
RuntimeError
(
*
e
.
args
)
...
...
@@ -266,7 +266,7 @@ class GaudiHandlePropertyProxyBase(PropertyProxy):
# print self.fullPropertyName(obj) + ": Setting default private configurable (from default handle): %r" % conf
except
AttributeError
,
e
:
except
AttributeError
as
e
:
# change type of exception to avoid false error message
raise
RuntimeError
(
*
e
.
args
)
if
conf
is
None
:
...
...
@@ -389,7 +389,7 @@ class DataObjectHandleBasePropertyProxy(PropertyProxy):
default
=
self
.
convertValueToBeSet
(
obj
,
default
)
if
default
:
self
.
__set__
(
obj
,
default
)
except
AttributeError
,
e
:
except
AttributeError
as
e
:
# change type of exception to avoid false error message
raise
RuntimeError
(
*
e
.
args
)
...
...
GaudiKernel/scripts/genconfuser.py
View file @
7c2963dc
...
...
@@ -17,7 +17,7 @@ from GaudiKernel.ConfigurableDb import cfgDb
logging
.
VERBOSE
=
(
logging
.
INFO
+
logging
.
DEBUG
)
/
2
logging
.
addLevelName
(
logging
.
VERBOSE
,
"VERBOSE"
)
logging
.
verbose
=
lambda
msg
,
*
args
,
**
kwargs
:
\
apply
(
logging
.
log
,
(
logging
.
VERBOSE
,
msg
)
+
args
,
kwargs
)
logging
.
log
(
logging
.
VERBOSE
,
msg
,
*
args
,
**
kwargs
)
def
_inheritsfrom
(
derived
,
basenames
):
...
...
@@ -68,7 +68,7 @@ def loadConfigurableDb():
log
.
debug
(
"
\t
-loading [%s]..."
%
confDb
)
try
:
cfgDb
.
_loadModule
(
confDb
)
except
Exception
,
err
:
except
Exception
as
err
:
# It may happen that the file is found but not completely
# written, usually during parallel builds, but we do not care.
log
.
warning
(
"Could not load file [%s] !"
,
confDb
)
...
...
@@ -278,7 +278,7 @@ def main():
try
:
logging
.
info
(
"Creating directory %r"
,
output_dir
)
os
.
makedirs
(
output_dir
,
0755
)
except
OSError
,
err
:
except
OSError
as
err
:
import
errno
if
err
.
errno
==
errno
.
EEXIST
:
# somebody already - perhaps concurrently - created that dir.
...
...
GaudiKernel/scripts/make_patch.py
View file @
7c2963dc
...
...
@@ -16,13 +16,13 @@ def command(cmd, *args, **kwargs):
d
.
update
(
kwargs
)
cmd
=
[
cmd
]
+
list
(
args
)
logging
.
debug
(
"Execute command: %r %r"
,
" "
.
join
(
cmd
),
kwargs
)
proc
=
apply
(
Popen
,
(
cmd
,
),
d
)
proc
=
Popen
(
cmd
,
**
d
)
return
proc
.
communicate
()
cmt
=
lambda
*
args
,
**
kwargs
:
apply
(
command
,
(
"cmt"
,
)
+
args
,
kwargs
)
cvs
=
lambda
*
args
,
**
kwargs
:
apply
(
command
,
(
"cvs"
,
)
+
args
,
kwargs
)
svn
=
lambda
*
args
,
**
kwargs
:
apply
(
command
,
(
"svn"
,
)
+
args
,
kwargs
)
cmt
=
lambda
*
args
,
**
kwargs
:
command
(
"cmt"
,
*
args
,
**
kwargs
)
cvs
=
lambda
*
args
,
**
kwargs
:
command
(
"cvs"
,
*
args
,
**
kwargs
)
svn
=
lambda
*
args
,
**
kwargs
:
command
(
"svn"
,
*
args
,
**
kwargs
)
def
broadcast_packages
():
...
...
GaudiKernel/tests/nose/test_Configurables.py
View file @
7c2963dc
...
...
@@ -53,7 +53,7 @@ def test_invalid_value():
raise
except
ValueError
:
pass
except
Exception
,
x
:
except
Exception
as
x
:
assert
False
,
'ValueError exception expected, got %s'
%
type
(
x
).
__name__
...
...
@@ -64,7 +64,7 @@ def test_invalid_value():
raise
except
ValueError
:
pass
except
Exception
,
x
:
except
Exception
as
x
:
assert
False
,
'ValueError exception expected, got %s'
%
type
(
x
).
__name__
...
...
@@ -89,7 +89,7 @@ def test_invalid_key():
raise
except
AttributeError
:
pass
except
Exception
,
x
:
except
Exception
as
x
:
assert
False
,
'AttributeError exception expected, got %s'
%
type
(
x
).
__name__
...
...
GaudiPolicy/python/GaudiTesting/BaseTest.py
View file @
7c2963dc
...
...
@@ -55,7 +55,7 @@ def kill_tree(ppid, sig):
try
:
log
.
debug
(
'killing process %d'
,
ppid
)
os
.
kill
(
ppid
,
sig
)
except
OSError
,
err
:
except
OSError
as
err
:
if
err
.
errno
!=
3
:
# No such process
raise
log
.
debug
(
'no such process %d'
,
ppid
)
...
...
GaudiPolicy/python/GaudiTesting/QMTTest.py
View file @
7c2963dc
...
...
@@ -77,7 +77,7 @@ class QMTTest(BaseTest):
# positional or keyword
if
a
not
in
positional
and
a
not
in
kwargs
:
kwargs
[
a
]
=
self
.
extra_args
[
a
]
return
apply
(
self
.
callable
,
args
,
kwargs
)
return
self
.
callable
(
*
args
,
**
kwargs
)
# local names to be exposed in the script
stdout_ref
=
self
.
_expandReferenceFileName
(
self
.
reference
)
...
...
GaudiPolicy/qmtest_classes/GaudiTest.py
View file @
7c2963dc
...
...
@@ -64,7 +64,7 @@ if sys.platform == "win32":
import
win32pipe
import
win32process
else
:
import
cPickle
from
six.moves
import
cPickle
import
fcntl
import
select
import
qm.sigmask
...
...
@@ -1540,7 +1540,7 @@ class GaudiExeTest(ExecTestBase):
# positional or keyword
if
a
not
in
positional
and
a
not
in
kwargs
:
kwargs
[
a
]
=
self
.
extra_args
[
a
]
return
apply
(
self
.
callable
,
args
,
kwargs
)
return
self
.
callable
(
*
args
,
**
kwargs
)
# local names to be exposed in the script
exported_symbols
=
{
...
...
GaudiPolicy/scripts/ZipPythonDir.py
View file @
7c2963dc
...
...
@@ -178,7 +178,7 @@ def zipdir(directory, no_pyc=False):
log
.
info
(
"File '%s' closed"
,
filename
)
else
:
log
.
info
(
"Nothing to do on '%s'"
,
filename
)
except
UnicodeDecodeError
,
x
:
except
UnicodeDecodeError
as
x
:
log
.
error
(
"Wrong encoding in file '%s':"
,
src
)
log
.
error
(
" %s"
,
x
)
log
.
error
(
"Probably you forgot the line '# -*- coding: utf-8 -*-'"
)
...
...
GaudiPolicy/scripts/createProjVersHeader.py
View file @
7c2963dc
#!/usr/bin/env python
from
__future__
import
print_function
import
os
import
sys
import
re
...
...
@@ -21,7 +21,7 @@ def main():
project
,
version
,
outputfile
=
args
if
not
opts
.
quiet
:
print
"Creating %s for %s %s"
%
(
outputfile
,
project
,
version
)
print
(
"Creating %s for %s %s"
%
(
outputfile
,
project
,
version
)
)
for
style
in
[
lhcb_ver_style
,
atlas_ver_style
,
plain_ver_style
]:
m
=
re
.
match
(
style
,
version
)
...
...
@@ -38,7 +38,7 @@ def main():
outdir
=
os
.
path
.
dirname
(
outputfile
)
if
not
os
.
path
.
exists
(
outdir
):
if
not
opts
.
quiet
:
print
"Creating directory"
,
outdir
print
(
"Creating directory"
,
outdir
)
os
.
makedirs
(
outdir
)
# Prepare data to be written
...
...
GaudiPython/python/GaudiPython/Bindings.py
View file @
7c2963dc
...
...
@@ -111,7 +111,7 @@ class InterfaceCast(object):
return
ip
else
:
print
"ERROR: queryInterface failed for"
,
obj
,
"interface:"
,
self
.
type
except
Exception
,
e
:
except
Exception
as
e
:
print
"ERROR: exception"
,
e
,
"caught when retrieving interface"
,
self
.
type
,
"for object"
,
obj
import
traceback
traceback
.
print_stack
()
...
...
@@ -358,7 +358,7 @@ class iProperty(object):
for
p
in
props
:
try
:
dct
[
p
.
name
()]
=
PropertyEntry
(
p
)
except
(
ValueError
,
TypeError
)
,
e
:
except
(
ValueError
,
TypeError
)
as
e
:
raise
ValueError
,
"gaudimodule.iProperty.properties(): %s%s processing property %s.%s = %s"
%
\
(
e
.
__class__
.
__name__
,
e
.
args
,
propsFrom
,
p
.
name
(),
p
.
value
())
...
...
@@ -720,7 +720,7 @@ class iHistogramSvc(iDataSvc):
>>> svc = ...
>>> histo = svc.book( .... )
"""
return
apply
(
self
.
_ihs
.
book
,
args
)
return
self
.
_ihs
.
book
(
*
args
)
def
bookProf
(
self
,
*
args
):
"""
...
...
@@ -728,7 +728,7 @@ class iHistogramSvc(iDataSvc):
>>> svc = ...
>>> histo = svc.bookProf( .... )
"""
return
apply
(
self
.
_ihs
.
bookProf
,
args
)
return
self
.
_ihs
.
bookProf
(
*
args
)
def
__getitem__
(
self
,
path
):
"""
...
...
@@ -774,7 +774,7 @@ class iNTupleSvc(iDataSvc):
iDataSvc
.
__init__
(
self
,
name
,
ints
)
def
book
(
self
,
*
args
):
return
apply
(
self
.
_ints
.
book
,
args
)
return
self
.
_ints
.
book
(
*
args
)
def
defineOutput
(
self
,
files
,
typ
=
"Gaudi::RootCnvSvc"
):
""" Defines the mapping between logical names and the output file
...
...
@@ -1443,7 +1443,7 @@ def getComponentProperties(name):
obj
=
factory
.
instantiate
(
dummysvc
)
else
:
obj
=
factory
.
instantiate
(
svcloc
)
except
RuntimeError
,
text
:
except
RuntimeError
as
text
:
print
'Error instantiating'
,
cname
,
' from '
,
name
print
text
continue
...
...
GaudiRelease/svn_tag_release.py
View file @
7c2963dc
...
...
@@ -18,7 +18,7 @@ from ConfigParser import ConfigParser
def
svn
(
*
args
,
**
kwargs
):
print
"> svn"
,
" "
.
join
(
args
)
return
apply
(
Popen
,
([
"svn"
]
+
list
(
args
),
),
kwargs
)
return
Popen
([
"svn"
]
+
list
(
args
),
**
kwargs
)
def
svn_ls
(
url
):
...
...
@@ -42,7 +42,7 @@ def svn_exists(url):
def
checkout_structure
(
url
,
proj
,
branch
):
def
checkout_level
(
base
):
dirs
=
[
"%s/%s"
%
(
base
,
d
)
for
d
in
svn_ls
(
base
)
if
d
.
endswith
(
"/"
)]
apply
(
svn
,
[
"up"
,
"-N"
]
+
dir
s
).
wait
()
svn
(
"up"
,
"-N"
,
*
arg
s
).
wait
()
return
dirs
root
=
basename
(
url
)
...
...
cmake/cmakeLogToCacheGrind.py
View file @
7c2963dc
...
...
@@ -5,12 +5,14 @@ Gaudi cmake process (See Instrument.cmake) and create an other file
understandable by kcachegrind for easy visualization of where we spend time in
cmake.
'''
from
__future__
import
print_function
import
sys
def
usage
():
print
"Invalid arguments
\n
Proper syntax is :
\n
%s <log file> <callgrind file>"
%
sys
.
argv
[
0
]
print
(
"Invalid arguments
\n
Proper syntax is :
\n
%s <log file> <callgrind file>"
%
sys
.
argv
[
0
])
if
len
(
sys
.
argv
)
!=
3
:
...
...
@@ -45,7 +47,7 @@ for line in open(sys.argv[1]).readlines():
elif
key
==
'ENDTIME'
:
sfunc
,
stime
=
callStack
.
pop
()
if
sfunc
!=
func
:
print
'Mismatch START/END for %s/%s'
%
(
sfunc
,
func
)
print
(
'Mismatch START/END for %s/%s'
%
(
sfunc
,
func
)
)
sys
.
exit
()
deltatime
=
int
(
time
)
-
stime
# add time spent to this function
...
...
cmake/extract_qmtest_metadata.py
View file @
7c2963dc
...
...
@@ -11,6 +11,7 @@ import platform
import
xml.etree.ElementTree
as
ET
import
collections
import
re
import
six
def
qmt_filename_to_name
(
path
):
...
...
@@ -111,11 +112,11 @@ def analyze_suites(pkg, rootdir):
# transpose the dictionary of lists
test_labels
=
collections
.
defaultdict
(
set
)
for
label
,
tests
in
labels
.
iteritems
():
for
label
,
tests
in
six
.
iteritems
(
labels
):
for
test
in
tests
:
test_labels
[
test
].
add
(
label
)
for
test
,
labels
in
test_labels
.
iteritems
(
):
for
test
,
labels
in
six
.
iteritems
(
test_labels
):
print
(
'set_property(TEST {0} APPEND PROPERTY LABELS {1})'
.
format
(
test
,
' '
.
join
(
labels
)))
...
...
cmake/modules/scan_dict_deps.py
View file @
7c2963dc
#!/usr/bin/env python
import
re
from
itertools
import
imap
,
ifilter
import
six
from
os.path
import
join
,
exists
,
isabs
...
...
@@ -16,8 +16,10 @@ def find_file(filename, searchpath):
if
isabs
(
filename
):
return
filename
if
exists
(
filename
)
else
None
try
:
return
ifilter
(
exists
,
imap
(
lambda
x
:
join
(
x
,
filename
),
searchpath
)).
next
()
return
six
.
next
(
six
.
moves
.
filter
(
exists
,
six
.
moves
.
map
(
lambda
x
:
join
(
x
,
filename
),
searchpath
)))
except
StopIteration
:
return
None
...
...
@@ -37,11 +39,11 @@ def find_deps(filename, searchpath, deps=None):
# Look for all "#include" lines in the file, then consider each of the
# included files, ignoring those already included in the recursion
for
included
in
i
filter
(
for
included
in
six
.
moves
.
filter
(
lambda
f
:
f
and
f
not
in
deps
,
i
map
(
six
.
moves
.
map
(
lambda
m
:
m
and
find_file
(
m
.
group
(
1
),
searchpath
),
i
map
(
six
.
moves
.
map
(
re
.
compile
(
r
'^\s*#\s*include\s*["<]([^">]*)[">]'
).
match
,
open
(
filename
)))):
deps
.
add
(
included
)
...
...
@@ -90,7 +92,9 @@ def main():
if
new_deps
!=
old_deps
:
# write it only if it has changed
open
(
output
,
'w'
).
write
(
new_deps
)
if
old_deps
and
not
opts
.
for_make
:
print
'info: dependencies changed: next build will trigger a reconfigure'
print
(
'info: dependencies changed: next build will trigger a reconfigure'
)
if
__name__
==
'__main__'
:
...
...
cmake/tests/cmake_coverage.py
View file @
7c2963dc
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from
__future__
import
print_function
import
os
import
re
import
atexit
import
cPickle
from
six.moves
import
cPickle
from
subprocess
import
Popen
,
PIPE
from
collections
import
defaultdict
...
...
@@ -22,7 +23,7 @@ def update_coverage():
else
:
data
=
{
'lines'
:
{}}
lines
=
data
[
'lines'
]
for
filename
,
linenumbers
in
coverage
.
iter
items
():
for
filename
,
linenumbers
in
coverage
.
items
():
lines
[
filename
]
=
sorted
(
linenumbers
.
union
(
lines
.
get
(
filename
,
[])))
with
open
(
COVERAGE_FILE
,
'w'
)
as
report
:
cPickle
.
dump
(
data
,
report
)
...
...
@@ -84,9 +85,9 @@ if __name__ == '__main__':
lines
=
data
[
'lines'
]
for
filename
in
sorted
(
lines
):
if
not
os
.
path
.
exists
(
filename
):
print
'Unknown file'
,
filename
print
(
'Unknown file'
,
filename
)
continue
print
filename
print
(
filename
)
active_lines
=
set
(
get_active_lines
(
filename
))
touched_lines
=
set
(
lines
[
filename
])
missed_lines
=
active_lines
.
difference
(
touched_lines
)
...
...
@@ -97,7 +98,8 @@ if __name__ == '__main__':
touched_count
=
len
(
touched_lines
)
active_count
=
len
(
active_lines
)
if
touched_count
==
active_count
:
print
' coverage 100%'
print
(
' coverage 100%'
)
else
:
print
(
' coverage %3d%%, missed: %s'
%
(
float
(
touched_count
)
/
active_count
*
100
,
', '
.
join
(
ranges
)))
print
(
' coverage %3d%%, missed: %s'
%
(
float
(
touched_count
)
/
active_count
*
100
,
', '
.
join
(
ranges
)))
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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