def guess(self, version): versions = self.__versions properties = self.__properties if version: return Version(version) if versions.next(): return versions.next() return Version(properties.get_property("default_version"))
def load(self, properties): alter = File(properties.get_property("alter.dir")) if alter.exists(): files = Files() for version in files.list(alter): self.__versions.add(Version(version.tail())) create = File(properties.get_property("create.dir")) if create.exists(): self.__versions.add( Version(properties.get_property("default_version")))
def load(self, properties): """ Find all versions on the current project and add them to the list. :param properties: An instance of ``noora.system.Properties.Properties``. """ alter = File(properties.get("alter.dir")) if alter.exists(): files = Files() for version in files.list(alter): self.__versions.add(Version(version.tail())) create = File(properties.get("create.dir")) if create.exists(): self.__versions.add(Version(properties.get("default_version")))
def guess(self, version=None): """ Do some guessing based on the current version. :param version (optional): if provided, find the version in the list. If not provided, find the next version on the project; :return: The current (if found) or next version, or the default version if all else fails. """ versions = self.__versions properties = self.__properties if version: return Version(version) if versions.next(): return versions.next() return Version(properties.get("default_version"))
def next(self): last = self.last() if last: level = self.get_part(last) mayor = last.get_mayor() minor = last.get_minor() revision = last.get_revision() patch = last.get_patch() if level == 1: mayor = str(int(mayor) + 1) if level == 2: minor = str(int(minor) + 1) if level == 3: revision = str(int(revision) + 1) if level == 4: patch = str(int(patch) + 1) if level == 1: version = mayor if level == 2: version = mayor + "." + minor if level == 3: version = mayor + "." + minor + "." + revision if level == 4: version = mayor + "." + minor + "." + revision + "." + revision return Version(version)
def fail_on_unknown_version(version, properties): versions = Versions() version_loader = VersionLoader(versions) version_loader.load(properties) versions.sort() if not versions.exists(Version(version)): message = "the given version is not valid for this project" raise PluginException(message)
def fail_on_unknown_version(version, properties): """Verify that ``version`` is valid for this project""" versions = Versions() version_loader = VersionLoader(versions) version_loader.load(properties) versions.sort() if not versions.exists(Version(version)): raise UnknownVersionException( "version {} is not valid for this project".format(version))
def testCheckVersion(self): properties = Properties() properties.set_property("current.dir", os.path.abspath('.')) 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')) properties.set_property('default_version', '1.0.0') versions = Versions() version_loader = VersionLoader(versions) version_loader.load(properties) versions.sort() previous = versions.previous(Version('1.0.2')) self.assertEqual(previous.get_value(), '1.0.1', 'invalid version') previous = versions.previous(Version('1.0.1')) self.assertEqual(previous.get_value(), '1.0.0', 'invalid version') # this is the odd one. Given is the first version, because off the fact that there is no previous version, # the first version is returned. previous = versions.previous(Version('1.0.0')) self.assertEqual(previous.get_value(), '1.0.0', 'invalid version')
def fail_on_invalid_version(self, connector, executor, version, properties): plugin_dir = properties.get('plugin.dir') versions = Versions() version_loader = VersionLoader(versions) version_loader.load(properties) versions.sort() v = Version(version) previous = versions.previous(v).get_value() properties['previous'] = previous script = File(os.path.join(plugin_dir, 'mysql', 'update', 'checkversion.sql')) executor['script'] = script connector.execute(executor, properties) if "(Code 1329)" in connector.get_result(): raise InvalidVersionException("invalid version: {}".format(previous))
def fail_on_invalid_version(self, properties, connector, executor, version): plugin_dir = properties.get('plugin.dir') versions = Versions() version_loader = VersionLoader(versions) version_loader.load(properties) versions.sort() v = Version(version) previous = versions.previous(v).get_value() properties['previous'] = previous script = File( os.path.join(plugin_dir, 'mssql', 'update', 'checkversion.sql')) executor['script'] = script connector.execute(executor, properties)
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')) version = arguments.v Fail.fail_on_no_version(version) Fail.fail_on_unknown_version(version, properties) default_databases = properties.get_property('databases') databases = Ora.nvl(arguments.d, default_databases) Fail.fail_on_invalid_database(arguments.d, properties) current_dir = properties.get_property('current.dir') component_name = properties.get_property('component_name') target_dir = os.path.join(current_dir, properties.get_property('component_target_folder')) objects = properties.get_property('create_objects') build_dir = App.build_dir(version, properties) # exclude the file 'version.sql', this file is excluded from the dat listing below. component_excluded_files = properties.get_property('component_excluded_files') excluded_files = properties.get_property('excluded_files') excluded_files.extend(component_excluded_files) # create the target folder, if not present. if not File(target_dir).exists(): os.makedirs(target_dir) print "building component with version '" + version + "'" zip_file = os.path.join(target_dir, component_name + '_' + version + '.zip') zip_handle = ZipFile(zip_file, 'w') for database in databases: for object in objects: if not object == 'lib': # global ddl objects folder = File(os.path.join(build_dir, database, 'ddl', object)) zip_dir = File(os.path.join(component_name + '_' + version, 'ddl', object)) files = Files.list_filtered(folder, properties) for file in files: print file.get_url() target_file = File(os.path.join(zip_dir.get_url(), file.tail())) zip_handle.write(file.get_url(), target_file.get_url(), ZIP_DEFLATED) # global dat files folder = File(os.path.join(build_dir, database, 'dat')) zip_dir = File(os.path.join(component_name + '_' + version, 'dat')) files = Files.list_filtered(folder, properties) for file in files: print file.get_url() target_file = File(os.path.join(zip_dir.get_url(), file.tail())) zip_handle.write(file.get_url(), target_file.get_url(), ZIP_DEFLATED) # create the version script in the dat folder version_statement = self.version_statement(version, properties) version_statement = version_statement.replace('<version>', version) version_statement = version_statement.replace('<name>', component_name) f = open('version.sql', 'w') f.write(version_statement) f.close() zip_dir = File(os.path.join(component_name + '_' + version, 'dat')) target_file = File(os.path.join(zip_dir.get_url(), 'version.sql')) zip_handle.write('version.sql', target_file.get_url()) # remove the version.sql file. os.remove('version.sql') # create the checkversion script in the root folder # first retrieve the previous version for the checkversion script versions = Versions() version_loader = VersionLoader(versions) version_loader.load(properties) versions.sort() previous = versions.previous(Version(version)) component_select_statement = properties.get_property("component_select_statement") component_select_statement = component_select_statement.replace('<name>', component_name) component_select_statement = component_select_statement.replace('<previous>', previous.get_value()) print component_select_statement f = open('checkversion.sql', 'w') f.write(component_select_statement) f.close() zip_dir = File(os.path.join(component_name + '_' + version)) target_file = File(os.path.join(zip_dir.get_url(), 'checkversion.sql')) zip_handle.write('checkversion.sql', target_file.get_url()) # remove the version.sql file. os.remove('checkversion.sql') zip_handle.close() print "component with version " + version + " created."
def execute(self, properties, arguments): """ Build the package after verifying version is valid, and database, if provided. :param properties: The project properties :param arguments: A dict of { 'version': 'The version to package for' 'database': 'The database to package for (optional)' } """ prepared_args = self._validate_and_prepare(properties, arguments) version = prepared_args['version'] databases = prepared_args['databases'] current_dir = properties.get('current.dir') component_name = properties.get('component_name') target_dir = os.path.join(current_dir, properties.get('component_target_folder')) objects = properties.get('create_objects') if version == properties.get("default_version"): build_dir = properties.get("create.dir") else: build_dir = os.path.join(properties.get("alter.dir"), version) # exclude the file 'version.sql', this file is excluded from the dat listing below. component_excluded_files = properties.get('component_excluded_files') excluded_files = properties.get('excluded_files') excluded_files.extend(component_excluded_files) # create the target folder, if not present. if not File(target_dir).exists(): os.makedirs(target_dir) print("building component with version '{}'".format(version)) zip_file = os.path.join(target_dir, component_name + '_' + version + '.zip') zip_handle = ZipFile(zip_file, 'w') for database in databases: for obj in objects: if not obj == 'lib': # global ddl objects folder = File(os.path.join(build_dir, database, 'ddl', obj)) zip_dir = File(os.path.join(component_name + '_' + version, 'ddl', obj)) files = Files.list_filtered(folder, properties) for file in files: print(file.get_url()) target_file = File(os.path.join(zip_dir.get_url(), file.tail())) zip_handle.write(file.get_url(), target_file.get_url(), ZIP_DEFLATED) # global dat files folder = File(os.path.join(build_dir, database, 'dat')) zip_dir = File(os.path.join(component_name + '_' + version, 'dat')) files = Files.list_filtered(folder, properties) for file in files: print(file.get_url()) target_file = File(os.path.join(zip_dir.get_url(), file.tail())) zip_handle.write(file.get_url(), target_file.get_url(), ZIP_DEFLATED) # create the version script in the dat folder if version == properties.get("default_version"): version_statement = properties.get("component_insert_statement") else: version_statement = properties.get("component_update_statement") version_statement = version_statement.replace('<version>', version) version_statement = version_statement.replace('<name>', component_name) f = open('version.sql', 'w') f.write(version_statement) f.close() zip_dir = File(os.path.join(component_name + '_' + version, 'dat')) target_file = File(os.path.join(zip_dir.get_url(), 'version.sql')) zip_handle.write('version.sql', target_file.get_url()) # remove the version.sql file. os.remove('version.sql') # create the checkversion script in the root folder # first retrieve the previous version for the checkversion script versions = Versions() version_loader = VersionLoader(versions) version_loader.load(properties) versions.sort() previous = versions.previous(Version(version)) component_select_statement = properties.get("component_select_statement") component_select_statement = component_select_statement.replace('<name>', component_name) component_select_statement = component_select_statement.replace( '<previous>', previous.get_value()) print(component_select_statement) f = open('checkversion.sql', 'w') f.write(component_select_statement) f.close() zip_dir = File(os.path.join(component_name + '_' + version)) target_file = File(os.path.join(zip_dir.get_url(), 'checkversion.sql')) zip_handle.write('checkversion.sql', target_file.get_url()) # remove the version.sql file. os.remove('checkversion.sql') zip_handle.close() print("component with version {} created.".format(version))
# i = 0 # result = 0 # print value.split('.') # for item in value.split('.'): # # result = result + float(item) / 1000**i # 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")