def get_class_by_name(name): """ Get a Python class specified by it's fully qualified name. NOTE: Does not actually create an instance of the object, only returns a Class object. """ # Split name into module and class name: tokens = name.split(".") class_name = tokens[-1] module = "" for s in tokens[0:-1]: if len(module) > 0: module = module + "." module = module + s mod = __import__(tokens[0]) components = name.split('.') for comp in components[1:-1]: mod = getattr(mod, comp) debug("Importing %s" % name) c = getattr(mod, class_name) return c
def _create_builder(self, package_name, build_tag, build_version, options, pkg_config, build_dir): """ Create (but don't run) the builder class. Builder object may be used by other objects without actually having run() called. """ builder_class = None if pkg_config.has_option("buildconfig", "builder"): builder_class = get_class_by_name(pkg_config.get("buildconfig", "builder")) else: builder_class = get_class_by_name(self.global_config.get( GLOBALCONFIG_SECTION, DEFAULT_BUILDER)) debug("Using builder class: %s" % builder_class) # Instantiate the builder: builder = builder_class( name=package_name, version=build_version, tag=build_tag, build_dir=build_dir, pkg_config=pkg_config, global_config=self.global_config, user_config=self.user_config, dist=options.dist, test=options.test, offline=options.offline) return builder
def main(self): BaseCliModule.main(self) if self.global_config.has_option(GLOBALCONFIG_SECTION, "block_tagging"): debug("block_tagging defined in tito.props") error_out("Tagging has been disabled in this git branch.") build_dir = lookup_build_dir(self.user_config) package_name = get_project_name(tag=None) self.pkg_config = self._read_project_config(package_name, build_dir, None, None) tagger_class = None if self.pkg_config.has_option("buildconfig", "tagger"): tagger_class = get_class_by_name(self.pkg_config.get("buildconfig", "tagger")) else: tagger_class = get_class_by_name(self.global_config.get( GLOBALCONFIG_SECTION, DEFAULT_TAGGER)) debug("Using tagger class: %s" % tagger_class) tagger = tagger_class(global_config=self.global_config, keep_version=self.options.keep_version) tagger.run(self.options)
def _read_project_config(self, project_name, build_dir, tag, no_cleanup): """ Read and return project build properties if they exist. This is done by checking for a build.py.props in the projects directory at the time the tag was made. To accomodate older tags prior to build.py, we also check for the presence of a Makefile with NO_TAR_GZ, and include a hack to assume build properties in this scenario. If no project specific config can be found, use the global config. """ debug("Determined package name to be: %s" % project_name) properties_file = None wrote_temp_file = False # Use the properties file in the current project directory, if it # exists: current_props_file = os.path.join(os.getcwd(), BUILD_PROPS_FILENAME) if (os.path.exists(current_props_file)): properties_file = current_props_file # Check for a build.py.props back when this tag was created and use it # instead. (if it exists) if tag: relative_dir = get_relative_project_dir(project_name, tag) cmd = "git show %s:%s%s" % (tag, relative_dir, BUILD_PROPS_FILENAME) debug(cmd) (status, output) = commands.getstatusoutput(cmd) temp_filename = "%s-%s" % (random.randint(1, 10000), BUILD_PROPS_FILENAME) temp_props_file = os.path.join(build_dir, temp_filename) if status == 0: properties_file = temp_props_file f = open(properties_file, 'w') f.write(output) f.close() wrote_temp_file = True else: # HACK: No build.py.props found, but to accomodate packages # tagged before they existed, check for a Makefile with # NO_TAR_GZ defined and make some assumptions based on that. cmd = "git show %s:%s%s | grep NO_TAR_GZ" % \ (tag, relative_dir, "Makefile") debug(cmd) (status, output) = commands.getstatusoutput(cmd) if status == 0 and output != "": properties_file = temp_props_file debug("Found Makefile with NO_TAR_GZ") f = open(properties_file, 'w') f.write(ASSUMED_NO_TAR_GZ_PROPS) f.close() wrote_temp_file = True config = ConfigParser.ConfigParser() if properties_file != None: debug("Using build properties: %s" % properties_file) config.read(properties_file) else: debug("Unable to locate custom build properties for this package.") debug(" Using global.build.py.props") # TODO: Not thrilled with this: if wrote_temp_file and not no_cleanup: # Delete the temp properties file we created. run_command("rm %s" % properties_file) return config