def _validate_and_prepare(self, properties, arguments): """ Prepare the version list here. All other preparation is handled by the plugins in the chain. """ prepared_args = { 'default_version': properties.get('default_version'), 'update_versions': [], } target_version = arguments.get('version') # If the target version is the default, we stop here because create takes care of this if prepared_args['default_version'] == target_version: return prepared_args # Here we determine the initial version versions = Versions() version_loader = VersionLoader(versions) version_loader.load(properties) versions.sort() # retrieve all versions for version in versions.list(): # First add this version if it's not the default one, because that's handled by create if version.get_value() != prepared_args['default_version']: prepared_args['update_versions'].append(version.get_value()) # Then if we reached the target version, we break if version.get_value() == target_version: break return prepared_args
def execute(self, arguments, properties): properties.set_property('create.dir', os.path.join(properties.get_property('current.dir'), 'create')) properties.set_property('alter.dir', os.path.join(properties.get_property('current.dir'), 'alter')) # find the drop plugin. plugin = self.find_plugin(properties, 'drop') # create the drop arguments and execute the plugin parser = argparse.ArgumentParser(add_help=False) parser.add_argument('-h', type=str, help='host', required=False) parser.add_argument('-s', type=str, help='schema', required=False) parser.add_argument('-e', type=str, help='environment', required=False) parser.add_argument('-a', type=str, help='alias', required=False) commands = [] if arguments.h: commands.append('-h='+arguments.h) if arguments.s: commands.append('-s='+arguments.d) if arguments.e: commands.append('-e='+arguments.e) if arguments.a: commands.append('-a='+arguments.a) drop_arguments = parser.parse_args(commands) plugin.execute(drop_arguments, properties) # find the create plugin. plugin = self.find_plugin(properties, 'create') # create the drop arguments and execute the plugin parser = argparse.ArgumentParser(add_help=False) parser.add_argument('-h', type=str, help='host', required=False) parser.add_argument('-s', type=str, help='schema', required=False) parser.add_argument('-e', type=str, help='environment', required=False) parser.add_argument('-a', type=str, help='alias', required=False) commands = [] if arguments.h: commands.append('-h='+arguments.h) if arguments.s: commands.append('-s='+arguments.s) if arguments.e: commands.append('-e='+arguments.e) if arguments.a: commands.append('-a='+arguments.a) create_arguments = parser.parse_args(commands) plugin.execute(create_arguments, properties) versions = Versions() version_loader = VersionLoader(versions) version_loader.load(properties) versions.sort() # remove the default_version from the version list # by doing so, this reflects the present alters in the project folder alter_versions = [] for version in versions.list(): if version.get_value() != properties.get_property('default_version'): alter_versions.append(version.get_value()) # create a list of versions up to the given version # if no version is given, the last available version in the project folder is assumed. if arguments.v: update_versions = [] for version in alter_versions: update_versions.append(version) if version == arguments.v: break alter_versions = update_versions # find the update plugin. plugin = self.find_plugin(properties, 'update') # create the arguments and execute the plugin for version in alter_versions: parser = argparse.ArgumentParser(add_help=False) parser.add_argument('-h', type=str, help='host', required=False) parser.add_argument('-s', type=str, help='schema', required=False) parser.add_argument('-e', type=str, help='environment', required=False) parser.add_argument('-a', type=str, help='alias', required=False) parser.add_argument('-v', type=str, help='version', required=False) commands = [] if arguments.h: commands.append('-h='+arguments.h) if arguments.s: commands.append('-s='+arguments.s) if arguments.e: commands.append('-e='+arguments.e) if arguments.a: commands.append('-a='+arguments.a) commands.append('-v='+version) update_arguments = parser.parse_args(commands) plugin.execute(update_arguments, properties)
# print result # i = i + 1 # return result # # # print weight('1.0.3.2') versions = Versions() version = Version("1.0.2") versions.add(version) version = Version("1.0.3") versions.add(version) version = Version("1.0.3.1") versions.add(version) version = Version("1.0.3.2") versions.add(version) version = Version("1.0.4") versions.add(version) version = Version("1.0.1") versions.add(version) versions.sort() for version in versions.list(): print version.get_weight(), version.to_string()