Skip to content

Commit

Permalink
Fix for handling of empty popcon files
Browse files Browse the repository at this point in the history
  • Loading branch information
ggovi committed Jun 3, 2020
1 parent e34b5f4 commit 98ead29
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CondCore/PopCon/src/PopCon.cc
Expand Up @@ -37,6 +37,7 @@ namespace popcon {
if (!m_dbService.isAvailable())
throw Exception("DBService not available");
const std::string& connectionStr = m_dbService->session().connectionString();
m_dbService->forceInit();
m_tag = m_dbService->tag(m_record);
m_tagInfo.name = m_tag;
if (m_targetConnectionString.empty())
Expand Down
13 changes: 10 additions & 3 deletions CondCore/Utilities/python/popcon2dropbox.py
Expand Up @@ -36,20 +36,24 @@ def checkFile( dbName ):
# exit code = 0 => skip
# exit code = 1 => import
if not os.path.exists( dbFileName ):
logger.error('The file expected as an input %s has not been found.'%dbFileName )
logger.error('The file generated by PopCon with the data to be imported %s has not been found.'%dbFileName )
return -1

empty = True
try:
dbcon = sqlite3.connect( dbFileName )
dbcur = dbcon.cursor()
dbcur.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='IOV'");
if dbcur.fetchone() is None:
logger.error('The condition database with the data to be imported has not been found in the file generated by PopCon: %s'%dbFileName )
return -1
dbcur.execute('SELECT * FROM IOV')
rows = dbcur.fetchall()
for r in rows:
empty = False
dbcon.close()
if empty:
logger.warning('The file expected as an input %s contains no data. The import will be skipped.'%dbFileName )
logger.warning('The data set generated by PopCon contains no data to be imported. The import will be skipped.')
return 0
return 1
except Exception as e:
Expand Down Expand Up @@ -174,6 +178,7 @@ def run( args ):
command += ' destinationDatabase=%s' %args.destDb
command += ' destinationTag=%s' %args.destTag
command += ' 2>&1'
logger.info( 'Executing command: %s' %command )
pipe = subprocess.Popen( command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
stdout = pipe.communicate()[0]
retCode = pipe.returncode
Expand All @@ -189,5 +194,7 @@ def run( args ):
ret = copy( args, dbName )
else:
ret = upload( args, dbName )
os.remove( '%s.db' %dbName )
if ret >=0:
logger.info('Deleting local file %s.db' %dbName )
os.remove( '%s.db' %dbName )
return ret

0 comments on commit 98ead29

Please sign in to comment.