mirror of
git://git.yoctoproject.org/layerindex-web.git
synced 2025-07-19 20:59:01 +02:00
rrs/tools: add dry-run option to each script
Add the ability to run the scripts without writing changes back to the database, for debugging purposes. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
parent
6ca3d6649e
commit
fd786875c3
|
@ -7,6 +7,10 @@
|
|||
|
||||
import logging
|
||||
|
||||
class DryRunRollbackException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def common_setup():
|
||||
import sys, os
|
||||
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), '../../')))
|
||||
|
|
|
@ -15,7 +15,7 @@ from datetime import datetime
|
|||
|
||||
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__))))
|
||||
from common import common_setup, update_repo, load_recipes, \
|
||||
get_pv_type, get_logger
|
||||
get_pv_type, get_logger, DryRunRollbackException
|
||||
common_setup()
|
||||
from layerindex import utils
|
||||
|
||||
|
@ -94,11 +94,16 @@ if __name__=="__main__":
|
|||
help = "Enable debug output",
|
||||
action="store_const", const=logging.DEBUG, dest="loglevel", default=logging.INFO)
|
||||
|
||||
parser.add_option("--dry-run",
|
||||
help = "Do not write any data back to the database",
|
||||
action="store_true", dest="dry_run", default=False)
|
||||
|
||||
options, args = parser.parse_args(sys.argv)
|
||||
logger.setLevel(options.loglevel)
|
||||
|
||||
logger.debug("Starting recipe distros update ...")
|
||||
|
||||
try:
|
||||
with transaction.atomic():
|
||||
for layerbranch in LayerBranch.objects.all():
|
||||
(tinfoil, d, recipes) = load_recipes(layerbranch, bitbakepath,
|
||||
|
@ -136,3 +141,7 @@ if __name__=="__main__":
|
|||
str(layerbranch), distro, alias))
|
||||
|
||||
tinfoil.shutdown()
|
||||
if options.dry_run:
|
||||
raise DryRunRollbackException
|
||||
except DryRunRollbackException:
|
||||
pass
|
||||
|
|
|
@ -13,7 +13,7 @@ import optparse
|
|||
import logging
|
||||
|
||||
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__))))
|
||||
from common import common_setup, update_repo, get_logger
|
||||
from common import common_setup, update_repo, get_logger, DryRunRollbackException
|
||||
common_setup()
|
||||
from layerindex import utils, recipeparse
|
||||
|
||||
|
@ -67,7 +67,7 @@ def get_commit_info(info, logger):
|
|||
"""
|
||||
Recreate Maintainership history from the beign of Yocto Project
|
||||
"""
|
||||
def maintainer_history(logger):
|
||||
def maintainer_history(options, logger):
|
||||
layername = settings.CORE_LAYER_NAME
|
||||
branchname = "master"
|
||||
|
||||
|
@ -90,6 +90,7 @@ def maintainer_history(logger):
|
|||
commits = utils.runcmd("git log --format='%H' --reverse --date=rfc " +
|
||||
MAINTAINERS_INCLUDE_PATH, pokypath, logger=logger)
|
||||
|
||||
try:
|
||||
with transaction.atomic():
|
||||
for commit in commits.strip().split("\n"):
|
||||
if RecipeMaintainerHistory.objects.filter(sha1=commit):
|
||||
|
@ -159,6 +160,10 @@ def maintainer_history(logger):
|
|||
rm.save()
|
||||
logger.debug("%s: New recipe not found maintainer set to 'No maintainer'." % \
|
||||
(recipe.pn))
|
||||
if options.dry_run:
|
||||
raise DryRunRollbackException
|
||||
except DryRunRollbackException:
|
||||
pass
|
||||
|
||||
if __name__=="__main__":
|
||||
parser = optparse.OptionParser(usage = """%prog [options]""")
|
||||
|
@ -168,8 +173,12 @@ if __name__=="__main__":
|
|||
action="store_const", const=logging.DEBUG, dest="loglevel",
|
||||
default=logging.INFO)
|
||||
|
||||
parser.add_option("--dry-run",
|
||||
help = "Do not write any data back to the database",
|
||||
action="store_true", dest="dry_run", default=False)
|
||||
|
||||
logger = get_logger("MaintainerUpdate", settings)
|
||||
options, args = parser.parse_args(sys.argv)
|
||||
logger.setLevel(options.loglevel)
|
||||
|
||||
maintainer_history(logger)
|
||||
maintainer_history(options, logger)
|
||||
|
|
|
@ -18,8 +18,9 @@ import optparse
|
|||
import logging
|
||||
|
||||
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__))))
|
||||
from common import common_setup, update_repo, get_pv_type, load_recipes, \
|
||||
get_logger
|
||||
from common import common_setup, get_pv_type, load_recipes, \
|
||||
get_logger, DryRunRollbackException
|
||||
|
||||
common_setup()
|
||||
from layerindex import utils, recipeparse
|
||||
from layerindex.update_layer import split_recipe_fn
|
||||
|
@ -144,7 +145,7 @@ def _get_recipes_filenames(ct, repodir, layerdir, logger):
|
|||
|
||||
return ct_files
|
||||
|
||||
def do_initial(layerbranch, ct, logger):
|
||||
def do_initial(layerbranch, ct, logger, dry_run):
|
||||
layer = layerbranch.layer
|
||||
urldir = str(layer.get_fetch_dir())
|
||||
repodir = os.path.join(fetchdir, urldir)
|
||||
|
@ -160,16 +161,21 @@ def do_initial(layerbranch, ct, logger):
|
|||
(tinfoil, d, recipes) = load_recipes(layerbranch, bitbakepath,
|
||||
fetchdir, settings, logger, nocheckout=True)
|
||||
|
||||
try:
|
||||
with transaction.atomic():
|
||||
for recipe_data in recipes:
|
||||
_create_upgrade(recipe_data, layerbranch, '', title,
|
||||
info, logger, initial=True)
|
||||
if dry_run:
|
||||
raise DryRunRollbackException
|
||||
except DryRunRollbackException:
|
||||
pass
|
||||
|
||||
utils.runcmd("git checkout master -f", repodir, logger=logger)
|
||||
utils.runcmd("git branch -D %s" % (branch_name_tmp), repodir, logger=logger)
|
||||
tinfoil.shutdown()
|
||||
|
||||
def do_loop(layerbranch, ct, logger):
|
||||
def do_loop(layerbranch, ct, logger, dry_run):
|
||||
layer = layerbranch.layer
|
||||
urldir = str(layer.get_fetch_dir())
|
||||
repodir = os.path.join(fetchdir, urldir)
|
||||
|
@ -193,10 +199,15 @@ def do_loop(layerbranch, ct, logger):
|
|||
repodir, logger=logger)
|
||||
info = utils.runcmd("git log --format='%an;%ae;%ad;%cd' --date=rfc -n 1 " \
|
||||
+ ct, destdir=repodir, logger=logger)
|
||||
try:
|
||||
with transaction.atomic():
|
||||
for recipe_data in recipes:
|
||||
_create_upgrade(recipe_data, layerbranch, ct, title,
|
||||
info, logger)
|
||||
if dry_run:
|
||||
raise DryRunRollbackException
|
||||
except DryRunRollbackException:
|
||||
pass
|
||||
|
||||
utils.runcmd("git checkout master -f", repodir, logger=logger)
|
||||
utils.runcmd("git branch -D %s" % (branch_name_tmp), repodir, logger=logger)
|
||||
|
@ -243,13 +254,13 @@ def upgrade_history(options, logger):
|
|||
logger.debug("Adding initial upgrade history ....")
|
||||
|
||||
ct = commit_list.pop(0)
|
||||
do_initial(layerbranch, ct, logger)
|
||||
do_initial(layerbranch, ct, logger, options.dry_run)
|
||||
|
||||
logger.debug("Adding upgrade history from %s to %s ..." % (since, today))
|
||||
for ct in commit_list:
|
||||
if ct:
|
||||
logger.debug("Analysing commit %s ..." % ct)
|
||||
do_loop(layerbranch, ct, logger)
|
||||
do_loop(layerbranch, ct, logger, options.dry_run)
|
||||
|
||||
if __name__=="__main__":
|
||||
parser = optparse.OptionParser(usage = """%prog [options]""")
|
||||
|
@ -262,6 +273,10 @@ if __name__=="__main__":
|
|||
help = "Enable debug output",
|
||||
action="store_const", const=logging.DEBUG, dest="loglevel", default=logging.INFO)
|
||||
|
||||
parser.add_option("--dry-run",
|
||||
help = "Do not write any data back to the database",
|
||||
action="store_true", dest="dry_run", default=False)
|
||||
|
||||
options, args = parser.parse_args(sys.argv)
|
||||
logger.setLevel(options.loglevel)
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ from datetime import datetime
|
|||
|
||||
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__))))
|
||||
from common import common_setup, update_repo, load_recipes, \
|
||||
get_pv_type, get_logger
|
||||
get_pv_type, get_logger, DryRunRollbackException
|
||||
common_setup()
|
||||
from layerindex import utils
|
||||
|
||||
|
@ -145,11 +145,16 @@ if __name__=="__main__":
|
|||
help = "Enable debug output",
|
||||
action="store_const", const=logging.DEBUG, dest="loglevel", default=logging.INFO)
|
||||
|
||||
parser.add_option("--dry-run",
|
||||
help = "Do not write any data back to the database",
|
||||
action="store_true", dest="dry_run", default=False)
|
||||
|
||||
options, args = parser.parse_args(sys.argv)
|
||||
logger.setLevel(options.loglevel)
|
||||
|
||||
logger.debug("Starting upstream history...")
|
||||
|
||||
try:
|
||||
with transaction.atomic():
|
||||
for layerbranch in LayerBranch.objects.all():
|
||||
layer = layerbranch.layer
|
||||
|
@ -204,3 +209,7 @@ if __name__=="__main__":
|
|||
str(layerbranch), recipe.pv, str(ru)))
|
||||
|
||||
tinfoil.shutdown()
|
||||
if options.dry_run:
|
||||
raise DryRunRollbackException
|
||||
except DryRunRollbackException:
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue
Block a user