diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2017-01-16 11:35:57 +1300 |
---|---|---|
committer | Paul Eggleton <paul.eggleton@linux.intel.com> | 2017-01-16 13:14:01 +1300 |
commit | 45d307369fb8a7c833b601283a37d668b74a2bc1 (patch) | |
tree | f0836e9a883d1bbdee528fd7427d905a681aca44 /layerindex/tools/import_classic.py | |
parent | 072c7d66562d4632364a5ad640c202962220940f (diff) | |
download | openembedded-core-contrib-45d307369fb8a7c833b601283a37d668b74a2bc1.tar.gz |
tools: fix for Django 1.8
Fix the transaction handling code to work with Django 1.8 in most of the
tools scripts. (Some of these are no longer used, but still serve as
examples of how to import data and update the database.)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Diffstat (limited to 'layerindex/tools/import_classic.py')
-rwxr-xr-x | layerindex/tools/import_classic.py | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/layerindex/tools/import_classic.py b/layerindex/tools/import_classic.py index 61f5f90443..c006e24e51 100755 --- a/layerindex/tools/import_classic.py +++ b/layerindex/tools/import_classic.py @@ -27,6 +27,10 @@ import recipeparse logger = utils.logger_create('LayerIndexUpdate') +class DryRunRollbackException(Exception): + pass + + def update_recipe_file(tinfoil, data, path, recipe, layerdir_start, repodir): fn = str(os.path.join(path, recipe.filename)) try: @@ -154,55 +158,51 @@ def main(): # Clear the default value of HOMEPAGE ('unknown') tinfoil.config_data.setVar('HOMEPAGE', '') - transaction.enter_transaction_management() - transaction.managed(True) try: - layerdir_start = os.path.normpath(oeclassicpath) + os.sep - layerrecipes = Recipe.objects.filter(layerbranch=layerbranch) - layermachines = Machine.objects.filter(layerbranch=layerbranch) - layerdistros = Distro.objects.filter(layerbranch=layerbranch) - layerappends = BBAppend.objects.filter(layerbranch=layerbranch) - layerclasses = BBClass.objects.filter(layerbranch=layerbranch) - - try: - config_data_copy = recipeparse.setup_layer(tinfoil.config_data, fetchdir, oeclassicpath, layer, layerbranch) - except recipeparse.RecipeParseError as e: - logger.error(str(e)) - transaction.rollback() - sys.exit(1) - - layerrecipes.delete() - layermachines.delete() - layerdistros.delete() - layerappends.delete() - layerclasses.delete() - for root, dirs, files in os.walk(oeclassicpath): - if '.git' in dirs: - dirs.remove('.git') - for f in files: - fullpath = os.path.join(root, f) - (typename, filepath, filename) = recipeparse.detect_file_type(fullpath, layerdir_start) - if typename == 'recipe': - recipe = ClassicRecipe() - recipe.layerbranch = layerbranch - recipe.filename = filename - recipe.filepath = filepath - update_recipe_file(tinfoil, config_data_copy, root, recipe, layerdir_start, oeclassicpath) - recipe.save() - - layerbranch.vcs_last_fetch = datetime.now() - layerbranch.save() - - if options.dryrun: - transaction.rollback() - else: - transaction.commit() + with transaction.atomic(): + layerdir_start = os.path.normpath(oeclassicpath) + os.sep + layerrecipes = Recipe.objects.filter(layerbranch=layerbranch) + layermachines = Machine.objects.filter(layerbranch=layerbranch) + layerdistros = Distro.objects.filter(layerbranch=layerbranch) + layerappends = BBAppend.objects.filter(layerbranch=layerbranch) + layerclasses = BBClass.objects.filter(layerbranch=layerbranch) + + try: + config_data_copy = recipeparse.setup_layer(tinfoil.config_data, fetchdir, oeclassicpath, layer, layerbranch) + except recipeparse.RecipeParseError as e: + logger.error(str(e)) + sys.exit(1) + + layerrecipes.delete() + layermachines.delete() + layerdistros.delete() + layerappends.delete() + layerclasses.delete() + for root, dirs, files in os.walk(oeclassicpath): + if '.git' in dirs: + dirs.remove('.git') + for f in files: + fullpath = os.path.join(root, f) + (typename, filepath, filename) = recipeparse.detect_file_type(fullpath, layerdir_start) + if typename == 'recipe': + recipe = ClassicRecipe() + recipe.layerbranch = layerbranch + recipe.filename = filename + recipe.filepath = filepath + update_recipe_file(tinfoil, config_data_copy, root, recipe, layerdir_start, oeclassicpath) + recipe.save() + + layerbranch.vcs_last_fetch = datetime.now() + layerbranch.save() + + if options.dryrun: + raise DryRunRollbackException() + except DryRunRollbackException: + pass except: import traceback traceback.print_exc() - transaction.rollback() finally: - transaction.leave_transaction_management() tinfoil.shutdown() shutil.rmtree(tempdir) |