update_layer.py: use new-style transaction API

The old transaction API has been removed in Django 1.8 and was
deprecated at 1.6. There's no explicit open transaction, commit or
rollback now - we just wrap the layer operations in
"with transaction.atomic()"; if we need to roll back we just raise a
"dummy" exception.

Part of the implementation for [YOCTO #9620].

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2016-06-07 23:15:46 +12:00
parent 8c50585728
commit 5e6a50c07d

View File

@ -34,6 +34,10 @@ except ImportError:
sys.exit(1)
class DryRunRollbackException(Exception):
pass
def check_machine_conf(path, subdir_start):
subpath = path[len(subdir_start):]
res = conf_re.match(subpath)
@ -187,9 +191,8 @@ def main():
# why won't they just fix that?!)
tinfoil.config_data.setVar('LICENSE', '')
transaction.enter_transaction_management()
transaction.managed(True)
try:
with transaction.atomic():
layer = utils.get_layer(options.layer)
urldir = layer.get_fetch_dir()
repodir = os.path.join(fetchdir, urldir)
@ -216,7 +219,6 @@ def main():
logger.error("Failed update of layer %s - branch %s no longer exists" % (layer.name, branchdesc))
else:
logger.info("Skipping update of layer %s - branch %s doesn't exist" % (layer.name, branchdesc))
transaction.rollback()
sys.exit(1)
newbranch = False
@ -258,7 +260,6 @@ def main():
logger.error("Subdirectory for layer %s does not exist on branch %s - if this is legitimate, the layer branch record should be deleted" % (layer.name, branchdesc))
else:
logger.error("Failed to get last revision for layer %s on branch %s" % (layer.name, branchdesc))
transaction.rollback()
sys.exit(1)
layerdir = os.path.join(repodir, layerbranch.vcs_subdir)
@ -278,12 +279,10 @@ def main():
logger.info("Skipping update of layer %s for branch %s - subdirectory %s does not exist on this branch" % (layer.name, branchdesc, layerbranch.vcs_subdir))
else:
logger.error("Subdirectory for layer %s does not exist on branch %s - if this is legitimate, the layer branch record should be deleted" % (layer.name, branchdesc))
transaction.rollback()
sys.exit(1)
if not os.path.exists(os.path.join(layerdir, 'conf/layer.conf')):
logger.error("conf/layer.conf not found for layer %s - is subdirectory set correctly?" % layer.name)
transaction.rollback()
sys.exit(1)
logger.info("Collecting data for layer %s on branch %s" % (layer.name, branchdesc))
@ -292,7 +291,6 @@ def main():
config_data_copy = recipeparse.setup_layer(tinfoil.config_data, fetchdir, layerdir, layer, layerbranch)
except recipeparse.RecipeParseError as e:
logger.error(str(e))
transaction.rollback()
sys.exit(1)
if layerbranch.vcs_last_rev and not options.reload:
@ -596,20 +594,19 @@ def main():
layerbranch.save()
if options.dryrun:
transaction.rollback()
else:
transaction.commit()
raise DryRunRollbackException()
except KeyboardInterrupt:
transaction.rollback()
logger.warn("Update interrupted, changes to %s rolled back" % layer.name)
sys.exit(254)
except SystemExit:
raise
except DryRunRollbackException:
pass
except:
import traceback
traceback.print_exc()
transaction.rollback()
finally:
transaction.leave_transaction_management()
shutil.rmtree(tempdir)
sys.exit(0)