From f885b4151b1ac25008cd6c201e9a1cc84d334400 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Tue, 14 Jul 2015 13:27:10 +0100 Subject: Add migration scripts for historical versions of the definitions format See README for more information on how the migrations are intended work. These migrations are probably not widely useful, as our definitions have already been migrated manually. However, I want to come up with a good pattern for writing migration scripts, and actually doing it seems like the best way. There is a 'migrations/indent' tool, which reformats a set of definitions according to how the ruamel.yaml program writes them out. This tool is nice if you like everything to have consistent indent and line wrapping, and you can run it before running the migrations to ensure that the migrations don't do any reformatting when writing the .moprh files back to disk. The migration scripts require the ruamel.yaml Python library. I have sent a separate change to add this to the 'build' and 'devel' reference systems. Change-Id: Ibd62ba140d3f7e8e638beed6d714f671405bdc79 --- run-all | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 run-all (limited to 'run-all') diff --git a/run-all b/run-all new file mode 100755 index 0000000..8df0007 --- /dev/null +++ b/run-all @@ -0,0 +1,72 @@ +#!/usr/bin/env python +# Copyright (C) 2015 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + + +'''Run a set of migration scripts. + +This script does exactly what `PYTHONPATH=. run-parts --exit-on-error` would +do. I avoided using 'run-parts' purely because the implementation in Fedora 22 +doesn't have an '--exit-on-error' option. The Busybox and Debian +implementations do have that option. + +Please fix run-parts in https://git.fedorahosted.org/cgit/crontabs.git/tree/ +so we can simplify this script :-) + +''' + + +import os +import subprocess +import sys + + +if len(sys.argv) == 2: + migration_dir = sys.argv[1] +elif len(sys.argv) == 1: + migration_dir = os.path.dirname(__file__) +else: + sys.stderr.write("Usage: %s [MIGRATION_DIR]\n" % sys.argv[0]) + sys.exit(1) + + +def is_executable(fpath): + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + +env = os.environ +if 'PYTHONPATH' in env: + env['PYTHONPATH'] = env['PYTHONPATH'] + ':' + migration_dir +else: + env['PYTHONPATH'] = migration_dir + +try: + migrations_found = 0 + for fname in sorted(os.listdir(migration_dir)): + migration_fpath = os.path.join(migration_dir, fname) + if is_executable(migration_fpath): + if not os.path.samefile(migration_fpath, __file__): + migrations_found += 1 + sys.stdout.write(migration_fpath + ":\n") + subprocess.check_call( + migration_fpath, env=env) + + if migrations_found == 0: + sys.stderr.write("No migration files found in '%s'\n" % migration_dir) + sys.exit(1) + else: + sys.exit(0) + +except (subprocess.CalledProcessError, RuntimeError) as e: + sys.stderr.write(str(e) + '\n') + sys.exit(1) -- cgit v1.2.1