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
|
import logging
|
||||||
|
|
||||||
|
class DryRunRollbackException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def common_setup():
|
def common_setup():
|
||||||
import sys, os
|
import sys, os
|
||||||
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), '../../')))
|
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__))))
|
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__))))
|
||||||
from common import common_setup, update_repo, load_recipes, \
|
from common import common_setup, update_repo, load_recipes, \
|
||||||
get_pv_type, get_logger
|
get_pv_type, get_logger, DryRunRollbackException
|
||||||
common_setup()
|
common_setup()
|
||||||
from layerindex import utils
|
from layerindex import utils
|
||||||
|
|
||||||
|
@ -94,11 +94,16 @@ if __name__=="__main__":
|
||||||
help = "Enable debug output",
|
help = "Enable debug output",
|
||||||
action="store_const", const=logging.DEBUG, dest="loglevel", default=logging.INFO)
|
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)
|
options, args = parser.parse_args(sys.argv)
|
||||||
logger.setLevel(options.loglevel)
|
logger.setLevel(options.loglevel)
|
||||||
|
|
||||||
logger.debug("Starting recipe distros update ...")
|
logger.debug("Starting recipe distros update ...")
|
||||||
|
|
||||||
|
try:
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
for layerbranch in LayerBranch.objects.all():
|
for layerbranch in LayerBranch.objects.all():
|
||||||
(tinfoil, d, recipes) = load_recipes(layerbranch, bitbakepath,
|
(tinfoil, d, recipes) = load_recipes(layerbranch, bitbakepath,
|
||||||
|
@ -136,3 +141,7 @@ if __name__=="__main__":
|
||||||
str(layerbranch), distro, alias))
|
str(layerbranch), distro, alias))
|
||||||
|
|
||||||
tinfoil.shutdown()
|
tinfoil.shutdown()
|
||||||
|
if options.dry_run:
|
||||||
|
raise DryRunRollbackException
|
||||||
|
except DryRunRollbackException:
|
||||||
|
pass
|
||||||
|
|
|
@ -13,7 +13,7 @@ import optparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__))))
|
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()
|
common_setup()
|
||||||
from layerindex import utils, recipeparse
|
from layerindex import utils, recipeparse
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ def get_commit_info(info, logger):
|
||||||
"""
|
"""
|
||||||
Recreate Maintainership history from the beign of Yocto Project
|
Recreate Maintainership history from the beign of Yocto Project
|
||||||
"""
|
"""
|
||||||
def maintainer_history(logger):
|
def maintainer_history(options, logger):
|
||||||
layername = settings.CORE_LAYER_NAME
|
layername = settings.CORE_LAYER_NAME
|
||||||
branchname = "master"
|
branchname = "master"
|
||||||
|
|
||||||
|
@ -90,6 +90,7 @@ def maintainer_history(logger):
|
||||||
commits = utils.runcmd("git log --format='%H' --reverse --date=rfc " +
|
commits = utils.runcmd("git log --format='%H' --reverse --date=rfc " +
|
||||||
MAINTAINERS_INCLUDE_PATH, pokypath, logger=logger)
|
MAINTAINERS_INCLUDE_PATH, pokypath, logger=logger)
|
||||||
|
|
||||||
|
try:
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
for commit in commits.strip().split("\n"):
|
for commit in commits.strip().split("\n"):
|
||||||
if RecipeMaintainerHistory.objects.filter(sha1=commit):
|
if RecipeMaintainerHistory.objects.filter(sha1=commit):
|
||||||
|
@ -159,6 +160,10 @@ def maintainer_history(logger):
|
||||||
rm.save()
|
rm.save()
|
||||||
logger.debug("%s: New recipe not found maintainer set to 'No maintainer'." % \
|
logger.debug("%s: New recipe not found maintainer set to 'No maintainer'." % \
|
||||||
(recipe.pn))
|
(recipe.pn))
|
||||||
|
if options.dry_run:
|
||||||
|
raise DryRunRollbackException
|
||||||
|
except DryRunRollbackException:
|
||||||
|
pass
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
parser = optparse.OptionParser(usage = """%prog [options]""")
|
parser = optparse.OptionParser(usage = """%prog [options]""")
|
||||||
|
@ -168,8 +173,12 @@ if __name__=="__main__":
|
||||||
action="store_const", const=logging.DEBUG, dest="loglevel",
|
action="store_const", const=logging.DEBUG, dest="loglevel",
|
||||||
default=logging.INFO)
|
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)
|
logger = get_logger("MaintainerUpdate", settings)
|
||||||
options, args = parser.parse_args(sys.argv)
|
options, args = parser.parse_args(sys.argv)
|
||||||
logger.setLevel(options.loglevel)
|
logger.setLevel(options.loglevel)
|
||||||
|
|
||||||
maintainer_history(logger)
|
maintainer_history(options, logger)
|
||||||
|
|
|
@ -18,8 +18,9 @@ import optparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__))))
|
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, \
|
from common import common_setup, get_pv_type, load_recipes, \
|
||||||
get_logger
|
get_logger, DryRunRollbackException
|
||||||
|
|
||||||
common_setup()
|
common_setup()
|
||||||
from layerindex import utils, recipeparse
|
from layerindex import utils, recipeparse
|
||||||
from layerindex.update_layer import split_recipe_fn
|
from layerindex.update_layer import split_recipe_fn
|
||||||
|
@ -144,7 +145,7 @@ def _get_recipes_filenames(ct, repodir, layerdir, logger):
|
||||||
|
|
||||||
return ct_files
|
return ct_files
|
||||||
|
|
||||||
def do_initial(layerbranch, ct, logger):
|
def do_initial(layerbranch, ct, logger, dry_run):
|
||||||
layer = layerbranch.layer
|
layer = layerbranch.layer
|
||||||
urldir = str(layer.get_fetch_dir())
|
urldir = str(layer.get_fetch_dir())
|
||||||
repodir = os.path.join(fetchdir, urldir)
|
repodir = os.path.join(fetchdir, urldir)
|
||||||
|
@ -160,16 +161,21 @@ def do_initial(layerbranch, ct, logger):
|
||||||
(tinfoil, d, recipes) = load_recipes(layerbranch, bitbakepath,
|
(tinfoil, d, recipes) = load_recipes(layerbranch, bitbakepath,
|
||||||
fetchdir, settings, logger, nocheckout=True)
|
fetchdir, settings, logger, nocheckout=True)
|
||||||
|
|
||||||
|
try:
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
for recipe_data in recipes:
|
for recipe_data in recipes:
|
||||||
_create_upgrade(recipe_data, layerbranch, '', title,
|
_create_upgrade(recipe_data, layerbranch, '', title,
|
||||||
info, logger, initial=True)
|
info, logger, initial=True)
|
||||||
|
if dry_run:
|
||||||
|
raise DryRunRollbackException
|
||||||
|
except DryRunRollbackException:
|
||||||
|
pass
|
||||||
|
|
||||||
utils.runcmd("git checkout master -f", repodir, logger=logger)
|
utils.runcmd("git checkout master -f", repodir, logger=logger)
|
||||||
utils.runcmd("git branch -D %s" % (branch_name_tmp), repodir, logger=logger)
|
utils.runcmd("git branch -D %s" % (branch_name_tmp), repodir, logger=logger)
|
||||||
tinfoil.shutdown()
|
tinfoil.shutdown()
|
||||||
|
|
||||||
def do_loop(layerbranch, ct, logger):
|
def do_loop(layerbranch, ct, logger, dry_run):
|
||||||
layer = layerbranch.layer
|
layer = layerbranch.layer
|
||||||
urldir = str(layer.get_fetch_dir())
|
urldir = str(layer.get_fetch_dir())
|
||||||
repodir = os.path.join(fetchdir, urldir)
|
repodir = os.path.join(fetchdir, urldir)
|
||||||
|
@ -193,10 +199,15 @@ def do_loop(layerbranch, ct, logger):
|
||||||
repodir, logger=logger)
|
repodir, logger=logger)
|
||||||
info = utils.runcmd("git log --format='%an;%ae;%ad;%cd' --date=rfc -n 1 " \
|
info = utils.runcmd("git log --format='%an;%ae;%ad;%cd' --date=rfc -n 1 " \
|
||||||
+ ct, destdir=repodir, logger=logger)
|
+ ct, destdir=repodir, logger=logger)
|
||||||
|
try:
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
for recipe_data in recipes:
|
for recipe_data in recipes:
|
||||||
_create_upgrade(recipe_data, layerbranch, ct, title,
|
_create_upgrade(recipe_data, layerbranch, ct, title,
|
||||||
info, logger)
|
info, logger)
|
||||||
|
if dry_run:
|
||||||
|
raise DryRunRollbackException
|
||||||
|
except DryRunRollbackException:
|
||||||
|
pass
|
||||||
|
|
||||||
utils.runcmd("git checkout master -f", repodir, logger=logger)
|
utils.runcmd("git checkout master -f", repodir, logger=logger)
|
||||||
utils.runcmd("git branch -D %s" % (branch_name_tmp), 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 ....")
|
logger.debug("Adding initial upgrade history ....")
|
||||||
|
|
||||||
ct = commit_list.pop(0)
|
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))
|
logger.debug("Adding upgrade history from %s to %s ..." % (since, today))
|
||||||
for ct in commit_list:
|
for ct in commit_list:
|
||||||
if ct:
|
if ct:
|
||||||
logger.debug("Analysing commit %s ..." % ct)
|
logger.debug("Analysing commit %s ..." % ct)
|
||||||
do_loop(layerbranch, ct, logger)
|
do_loop(layerbranch, ct, logger, options.dry_run)
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
parser = optparse.OptionParser(usage = """%prog [options]""")
|
parser = optparse.OptionParser(usage = """%prog [options]""")
|
||||||
|
@ -262,6 +273,10 @@ if __name__=="__main__":
|
||||||
help = "Enable debug output",
|
help = "Enable debug output",
|
||||||
action="store_const", const=logging.DEBUG, dest="loglevel", default=logging.INFO)
|
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)
|
options, args = parser.parse_args(sys.argv)
|
||||||
logger.setLevel(options.loglevel)
|
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__))))
|
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__))))
|
||||||
from common import common_setup, update_repo, load_recipes, \
|
from common import common_setup, update_repo, load_recipes, \
|
||||||
get_pv_type, get_logger
|
get_pv_type, get_logger, DryRunRollbackException
|
||||||
common_setup()
|
common_setup()
|
||||||
from layerindex import utils
|
from layerindex import utils
|
||||||
|
|
||||||
|
@ -145,11 +145,16 @@ if __name__=="__main__":
|
||||||
help = "Enable debug output",
|
help = "Enable debug output",
|
||||||
action="store_const", const=logging.DEBUG, dest="loglevel", default=logging.INFO)
|
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)
|
options, args = parser.parse_args(sys.argv)
|
||||||
logger.setLevel(options.loglevel)
|
logger.setLevel(options.loglevel)
|
||||||
|
|
||||||
logger.debug("Starting upstream history...")
|
logger.debug("Starting upstream history...")
|
||||||
|
|
||||||
|
try:
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
for layerbranch in LayerBranch.objects.all():
|
for layerbranch in LayerBranch.objects.all():
|
||||||
layer = layerbranch.layer
|
layer = layerbranch.layer
|
||||||
|
@ -204,3 +209,7 @@ if __name__=="__main__":
|
||||||
str(layerbranch), recipe.pv, str(ru)))
|
str(layerbranch), recipe.pv, str(ru)))
|
||||||
|
|
||||||
tinfoil.shutdown()
|
tinfoil.shutdown()
|
||||||
|
if options.dry_run:
|
||||||
|
raise DryRunRollbackException
|
||||||
|
except DryRunRollbackException:
|
||||||
|
pass
|
||||||
|
|
Loading…
Reference in New Issue
Block a user