mirror of
git://git.yoctoproject.org/layerindex-web.git
synced 2025-07-19 20:59:01 +02:00
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>
This commit is contained in:
parent
072c7d6656
commit
45d307369f
|
@ -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,9 +158,8 @@ def main():
|
|||
# Clear the default value of HOMEPAGE ('unknown')
|
||||
tinfoil.config_data.setVar('HOMEPAGE', '')
|
||||
|
||||
transaction.enter_transaction_management()
|
||||
transaction.managed(True)
|
||||
try:
|
||||
with transaction.atomic():
|
||||
layerdir_start = os.path.normpath(oeclassicpath) + os.sep
|
||||
layerrecipes = Recipe.objects.filter(layerbranch=layerbranch)
|
||||
layermachines = Machine.objects.filter(layerbranch=layerbranch)
|
||||
|
@ -168,7 +171,6 @@ def main():
|
|||
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()
|
||||
|
@ -194,15 +196,13 @@ def main():
|
|||
layerbranch.save()
|
||||
|
||||
if options.dryrun:
|
||||
transaction.rollback()
|
||||
else:
|
||||
transaction.commit()
|
||||
raise DryRunRollbackException()
|
||||
except DryRunRollbackException:
|
||||
pass
|
||||
except:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
transaction.rollback()
|
||||
finally:
|
||||
transaction.leave_transaction_management()
|
||||
tinfoil.shutdown()
|
||||
|
||||
shutil.rmtree(tempdir)
|
||||
|
|
|
@ -21,6 +21,10 @@ import logging
|
|||
logger = utils.logger_create('LayerIndexImport')
|
||||
|
||||
|
||||
class DryRunRollbackException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def read_page(site, path):
|
||||
ret = {}
|
||||
import httplib
|
||||
|
@ -98,9 +102,8 @@ def main():
|
|||
recipes_ai = read_page("www.openembedded.org", "/wiki/OE-Classic_Recipes_A-I?action=raw")
|
||||
recipes_jz = read_page("www.openembedded.org", "/wiki/OE-Classic_Recipes_J-Z?action=raw")
|
||||
|
||||
transaction.enter_transaction_management()
|
||||
transaction.managed(True)
|
||||
try:
|
||||
with transaction.atomic():
|
||||
recipes = dict(list(recipes_ai.items()) + list(recipes_jz.items()))
|
||||
for pn, comment in recipes.items():
|
||||
newpn = ''
|
||||
|
@ -187,14 +190,9 @@ def main():
|
|||
sys.exit(1)
|
||||
|
||||
if options.dryrun:
|
||||
transaction.rollback()
|
||||
else:
|
||||
transaction.commit()
|
||||
except:
|
||||
transaction.rollback()
|
||||
raise
|
||||
finally:
|
||||
transaction.leave_transaction_management()
|
||||
raise DryRunRollbackException()
|
||||
except DryRunRollbackException:
|
||||
pass
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
|
|
@ -20,6 +20,10 @@ import utils
|
|||
logger = utils.logger_create('LayerIndexImport')
|
||||
|
||||
|
||||
class DryRunRollbackException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
parser = optparse.OptionParser(
|
||||
|
@ -45,9 +49,7 @@ def main():
|
|||
readme_re = re.compile(r';f=[a-zA-Z0-9/-]*README;')
|
||||
master_branch = utils.get_branch('master')
|
||||
core_layer = None
|
||||
transaction.enter_transaction_management()
|
||||
transaction.managed(True)
|
||||
try:
|
||||
with transaction.atomic():
|
||||
for line in data.splitlines():
|
||||
if line.startswith('{|'):
|
||||
in_table = True
|
||||
|
@ -140,12 +142,6 @@ def main():
|
|||
layerdep.layerbranch = layerbranch
|
||||
layerdep.dependency = core_layer
|
||||
layerdep.save()
|
||||
transaction.commit()
|
||||
except:
|
||||
transaction.rollback()
|
||||
raise
|
||||
finally:
|
||||
transaction.leave_transaction_management()
|
||||
else:
|
||||
logger.error('Fetch failed: %d: %s' % (resp.status, resp.reason))
|
||||
|
||||
|
|
|
@ -19,6 +19,9 @@ import logging
|
|||
|
||||
logger = utils.logger_create('LayerIndexClassicUpdate')
|
||||
|
||||
class DryRunRollbackException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
|
@ -62,9 +65,8 @@ def main():
|
|||
logger.error("Specified branch %s does not exist in database" % options.branch)
|
||||
sys.exit(1)
|
||||
|
||||
transaction.enter_transaction_management()
|
||||
transaction.managed(True)
|
||||
try:
|
||||
with transaction.atomic():
|
||||
def recipe_pn_query(pn):
|
||||
return Recipe.objects.filter(layerbranch__branch__name='master').filter(pn=pn).order_by('layerbranch__layer__index_preference')
|
||||
|
||||
|
@ -109,14 +111,9 @@ def main():
|
|||
|
||||
|
||||
if options.dryrun:
|
||||
transaction.rollback()
|
||||
else:
|
||||
transaction.commit()
|
||||
except:
|
||||
transaction.rollback()
|
||||
raise
|
||||
finally:
|
||||
transaction.leave_transaction_management()
|
||||
raise DryRunRollbackException()
|
||||
except DryRunRollbackException:
|
||||
pass
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user