aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2016-08-08 14:46:02 +1200
committerPaul Eggleton <paul.eggleton@linux.intel.com>2016-08-08 14:46:02 +1200
commit3e1f6379c19347f47f6e916b156fbdb3f513b0d7 (patch)
treee1a79bf8886e5b262582afc14cd81f2f05f31f71
parent646d78cacd6e2fbfe79822e57c2cdae16ee17f1d (diff)
downloadbuildhistory-web-3e1f6379c19347f47f6e916b156fbdb3f513b0d7.tar.gz
buildhistory-web-3e1f6379c19347f47f6e916b156fbdb3f513b0d7.tar.bz2
buildhistory-web-3e1f6379c19347f47f6e916b156fbdb3f513b0d7.zip
import.py: fix transaction handlingHEADmaster
The import script had not been updated to work properly with Django 1.8; in particular the transaction handling code needed some adaptation. The script will also now return an exit code of 1 on error instead of always returning 0. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
-rwxr-xr-xwarningmgr/import.py87
1 files changed, 44 insertions, 43 deletions
diff --git a/warningmgr/import.py b/warningmgr/import.py
index 99aa47e..c980ae9 100755
--- a/warningmgr/import.py
+++ b/warningmgr/import.py
@@ -2,7 +2,7 @@
# Report significant differences in the buildhistory repository since a specific revision
#
-# Copyright (C) 2012-2015 Intel Corporation
+# Copyright (C) 2012-2016 Intel Corporation
# Author: Paul Eggleton <paul.eggleton@linux.intel.com>
#
# Licensed under the MIT license, see COPYING.MIT for details
@@ -21,6 +21,10 @@ except ImportError:
sys.exit(1)
+class DryRunRollbackException(Exception):
+ pass
+
+
def main():
parser = argparse.ArgumentParser(description="buildhistory-web import tool")
parser.add_argument('corebasepath', help='Path to OE-Core base directory')
@@ -86,54 +90,51 @@ def main():
for commit in repo.iter_commits(args.torevision):
sincerevision = commit.hexsha
- transaction.enter_transaction_management()
- transaction.managed(True)
try:
- # Create a build
- b = Build()
- b.created_date = datetime.now()
- b.vcs_branch = repo.head.reference
- b.vcs_rev = repo.commit(args.torevision).hexsha
- if args.build_name:
- b.name = args.build_name
- if args.build_url:
- b.build_url = args.build_url
- b.save()
- # Import items
- def process_changes(proc_start, proc_end):
- print('Processing changes from %s to %s...' % (proc_start, proc_end))
- changes = oe.buildhistory_analysis.process_changes(args.buildhistorypath, proc_start, proc_end)
- for chg in changes:
- wi = WarningItem()
- wi.build = b
- wi.package = 'unknown'
- desc = str(chg)
- wi.description = desc
- wi.summary = desc.split('\n', 1)[0]
- print("Creating: %s" % wi.summary)
- wi.vcs_rev = b.vcs_rev
- wi.save()
-
- if args.iterate:
- for commit in repo.iter_commits("%s..%s" % (sincerevision, args.torevision), reverse=True):
- print("Processing revision %s..." % commit.hexsha)
- process_changes("%s^" % commit, commit)
- else:
- process_changes(sincerevision, args.torevision)
-
- if args.dry_run:
- transaction.rollback()
- else:
- transaction.commit()
+ with transaction.atomic():
+ # Create a build
+ b = Build()
+ b.created_date = datetime.now()
+ b.vcs_branch = repo.head.reference
+ b.vcs_rev = repo.commit(args.torevision).hexsha
+ if args.build_name:
+ b.name = args.build_name
+ if args.build_url:
+ b.build_url = args.build_url
+ b.save()
+ # Import items
+ def process_changes(proc_start, proc_end):
+ print('Processing changes from %s to %s...' % (proc_start, proc_end))
+ changes = oe.buildhistory_analysis.process_changes(args.buildhistorypath, proc_start, proc_end)
+ for chg in changes:
+ wi = WarningItem()
+ wi.build = b
+ wi.package = 'unknown'
+ desc = str(chg)
+ wi.description = desc
+ wi.summary = desc.split('\n', 1)[0]
+ print("Creating: %s" % wi.summary)
+ wi.vcs_rev = b.vcs_rev
+ wi.save()
+
+ if args.iterate:
+ for commit in repo.iter_commits("%s..%s" % (sincerevision, args.torevision), reverse=True):
+ print("Processing revision %s..." % commit.hexsha)
+ process_changes("%s^" % commit, commit)
+ else:
+ process_changes(sincerevision, args.torevision)
+
+ if args.dry_run:
+ raise DryRunRollbackException()
+ except DryRunRollbackException:
+ pass
except KeyboardInterrupt:
- transaction.rollback()
print("Update interrupted, changes rolled back")
+ sys.exit(1)
except:
import traceback
traceback.print_exc()
- transaction.rollback()
- finally:
- transaction.leave_transaction_management()
+ sys.exit(1)
sys.exit(0)