mirror of
git://git.yoctoproject.org/layerindex-web.git
synced 2025-07-19 20:59:01 +02:00
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. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
parent
3df2b1c5d9
commit
3d6dc8f35a
|
@ -34,6 +34,10 @@ except ImportError:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
class DryRunRollbackException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def check_machine_conf(path, subdir_start):
|
def check_machine_conf(path, subdir_start):
|
||||||
subpath = path[len(subdir_start):]
|
subpath = path[len(subdir_start):]
|
||||||
res = conf_re.match(subpath)
|
res = conf_re.match(subpath)
|
||||||
|
@ -187,9 +191,8 @@ def main():
|
||||||
# why won't they just fix that?!)
|
# why won't they just fix that?!)
|
||||||
tinfoil.config_data.setVar('LICENSE', '')
|
tinfoil.config_data.setVar('LICENSE', '')
|
||||||
|
|
||||||
transaction.enter_transaction_management()
|
|
||||||
transaction.managed(True)
|
|
||||||
try:
|
try:
|
||||||
|
with transaction.atomic():
|
||||||
layer = utils.get_layer(options.layer)
|
layer = utils.get_layer(options.layer)
|
||||||
urldir = layer.get_fetch_dir()
|
urldir = layer.get_fetch_dir()
|
||||||
repodir = os.path.join(fetchdir, urldir)
|
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))
|
logger.error("Failed update of layer %s - branch %s no longer exists" % (layer.name, branchdesc))
|
||||||
else:
|
else:
|
||||||
logger.info("Skipping update of layer %s - branch %s doesn't exist" % (layer.name, branchdesc))
|
logger.info("Skipping update of layer %s - branch %s doesn't exist" % (layer.name, branchdesc))
|
||||||
transaction.rollback()
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
newbranch = False
|
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))
|
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:
|
else:
|
||||||
logger.error("Failed to get last revision for layer %s on branch %s" % (layer.name, branchdesc))
|
logger.error("Failed to get last revision for layer %s on branch %s" % (layer.name, branchdesc))
|
||||||
transaction.rollback()
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
layerdir = os.path.join(repodir, layerbranch.vcs_subdir)
|
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))
|
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:
|
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))
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
if not os.path.exists(os.path.join(layerdir, 'conf/layer.conf')):
|
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)
|
logger.error("conf/layer.conf not found for layer %s - is subdirectory set correctly?" % layer.name)
|
||||||
transaction.rollback()
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
logger.info("Collecting data for layer %s on branch %s" % (layer.name, branchdesc))
|
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)
|
config_data_copy = recipeparse.setup_layer(tinfoil.config_data, fetchdir, layerdir, layer, layerbranch)
|
||||||
except recipeparse.RecipeParseError as e:
|
except recipeparse.RecipeParseError as e:
|
||||||
logger.error(str(e))
|
logger.error(str(e))
|
||||||
transaction.rollback()
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if layerbranch.vcs_last_rev and not options.reload:
|
if layerbranch.vcs_last_rev and not options.reload:
|
||||||
|
@ -596,20 +594,19 @@ def main():
|
||||||
layerbranch.save()
|
layerbranch.save()
|
||||||
|
|
||||||
if options.dryrun:
|
if options.dryrun:
|
||||||
transaction.rollback()
|
raise DryRunRollbackException()
|
||||||
else:
|
|
||||||
transaction.commit()
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
transaction.rollback()
|
|
||||||
logger.warn("Update interrupted, changes to %s rolled back" % layer.name)
|
logger.warn("Update interrupted, changes to %s rolled back" % layer.name)
|
||||||
sys.exit(254)
|
sys.exit(254)
|
||||||
|
except SystemExit:
|
||||||
|
raise
|
||||||
|
except DryRunRollbackException:
|
||||||
|
pass
|
||||||
except:
|
except:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
transaction.rollback()
|
|
||||||
finally:
|
|
||||||
transaction.leave_transaction_management()
|
|
||||||
|
|
||||||
shutil.rmtree(tempdir)
|
shutil.rmtree(tempdir)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user