def deprecared_read_from_filesystem(self, req_input_dir): '''Read all the needed (and configured) TopicSets into memory.''' tracer.debug("called: req_input_dir [%s]" % req_input_dir) for k in self.config.get_value('topics').get_dict().keys(): tracer.debug("create TopicSet [" + k + "]") self.topic_sets[k] = \ TopicSet(self.config, k, 'topics.' + k, req_input_dir)
def __read_topic_sets(self, ts_config): '''Reads in all the topic sets from the specified sources.''' tracer.debug("called") for source in ts_config['sources']: input_handler = Factory.create(source[0], source[1]) commits = input_handler.get_commits() self.__read_commits(input_handler, commits) assert False
def create_hashable(oid): '''If the oid is a list, the oid is converted into a string.''' tracer.debug("called: oid [%s]" % oid) if type(oid) == ListType: if len(oid) == 1: return oid[0] return '-'.join(oid) return oid
def get_fd(self, commit, filename): '''Return the file descriptor to read in filename from the given commit.''' tracer.debug("called: commit [%s] filename [%s]" % (commit, filename)) filename_split = filename.split("/") return self.__get_blob_with_filename_split( commit, filename_split).data_stream
def DEPRECATED_read_topics(self, tdir, initial_topic): '''Read all topics from the given directory starting with the initial topic.''' tracer.debug("called: directory [%s] initial topic [%s]" % (tdir, initial_topic)) txtioconfig = TxtIOConfig(self.config, "topics") Topic(tdir, initial_topic, self, txtioconfig, self.config) self.read_all_topic_names(tdir)
def __get_blob_direct(self, tree, name): '''Return the blob of the tree with the given name. If name is not available, an exception is thrown.''' tracer.debug("called: name [%s]" % name) for blob in tree.blobs: if blob.name == name: return blob raise RMTException(109, "blob entry [%s] not found in tree." % name)
def __check_if_dir_is_in_repo(self, directory): '''Checks if all the directories are the in repository. The absolute path is computed if the path is relative and then compared to the repository base directory.''' tracer.debug("called: directory [%s]" % directory) if self.__repo_base_dir == None: self.__setup_repo(directory) if not directory.startswith(self.__repo_base_dir): raise RMTException(28, "directory [%s] not in repository")
def get_vcs_id_with_type(self, commit, dir_type): '''Return the vcs id from the base directories of the given dir_type.''' tracer.debug("called: commit [%s] directory type [%s]" % (commit, dir_type)) result = [] for directory in self.__dirs[dir_type]: dir_split = directory.split("/") ltree = self.__get_tree(commit.tree, dir_split) result.append(ltree.hexsha) return ObjectCache.create_hashable(result)
def get(self, object_type, oid): '''Tries to receive an object with the given id. If found, the object is returned, if not found None is returned.''' tracer.debug("called: object type [%s] oid [%s]" % (object_type, oid)) self.__stats_cnt_get += 1 if self.__objects.has_key(object_type) \ and self.__objects[object_type].has_key(oid): self.__stats_cnt_get_found += 1 return self.__objects[object_type][oid] return None
def __get_file_names_from_tree(self, tree, directory): '''Returns all the file names (i.e. the blob names) recursive starting with the given directory.''' tracer.debug("called: directory [%s]" % directory) dir_split = directory.split("/") ltree = self.__get_tree(tree, dir_split) result = [] for blob in ltree.blobs: result.append(os.path.join(directory, blob.name)) return result
def get_file_names(self, commit, dir_type): '''Return all filenames of the given commit and of the given directory type.''' tracer.debug("called: commit [%s] directory type [%s]" % (commit, dir_type)) result = [] for directory in self.__dirs[dir_type]: # TODO: Do something like return a list of pairs # 1. element: pathname # 2. element: rid (pathname without the __dirs[dir_type] part assert False result.extend(self.__get_file_names_from_tree( commit.tree, directory)) return result
def __setup_directories(self, cfg): '''Cleans up and unifies the directories.''' tracer.debug("called") for dir_type in ["requirements", "topics", "constraints"]: dirs = map(self.__abs_path, cfg.get_value(dir_type + "_dirs")) self.__check_list_of_strings(dir_type, dirs) new_directories = [] for directory in dirs: self.__check_if_dir_is_in_repo(directory) new_directories.append(self.__cut_off_repo_dir(directory)) self.__dirs[dir_type] = new_directories for dir_type, directory in self.__dirs.iteritems(): tracer.debug("[%s] directories [%s]" % (dir_type, directory))
def add(self, oid, object_type, obj): '''Adds the given object to the cache using the given object id. Checks of the object is of the correct type and if the object is already in the cache.''' tracer.debug("adding object with object type [%s] oid [%s]" % (object_type, oid)) if not self.__objects.has_key(object_type): self.__stats_cnt_object_types += 1 self.__objects[object_type] = {} if oid in self.__objects[object_type]: assert False raise RMTException(106, "object with oid [%s] already in cache." % oid) self.__stats_cnt_objects += 1 self.__objects[object_type][oid] = obj
def __init__(self, config): tracer.info("called") cfg = Cfg(config) self.__start_vers = cfg.get_value("start_vers") self.__end_vers = cfg.get_value("end_vers") self.__topic_root_node = cfg.get_value("topic_root_node") tracer.debug("start version [%s] end version [%s] " "topic root node [%s]" % (self.__start_vers, self.__end_vers, self.__topic_root_node)) # When the directory is not absolute, convert it to an # absolute path that it can be compared to the outcome of the # git.Repo. self.__dirs = {} self.__repo_base_dir = None self.__repo = None self.__setup_directories(cfg)
def __init_continuum_set(self): '''Initialize the continuum: Check the configuration for the appropriate interval parameters and read in the TopicSetCollections.''' tracer.debug("called") # Step through all the available topic sets. for ts_name, ts_config in \ self.__config.get_value("topics").get_dict().iteritems(): self.__continuum[ts_name] = \ TopicContinuum(ts_name, self.__config, ts_config, self.__object_cache, self.__input_mods) assert False sources = self.config() versint = self.internal_get_interval() self.internal_check_repo(versint) self.internal_read_continuum(versint)
def __read_requirements(self, input_handler, commit): '''Reads in all the requirements from the input_handler.''' tracer.debug("called") filenames = input_handler.get_file_names(commit, "requirements") print("FILENAMES [%s]" % filenames) for filename in filenames: # Check for correct filename m = re.match("^.*\.req$", filename) if m == None: tracer.info("skipping file [%s]" % filename) continue # Handle caching. vcs_id = input_handler.get_vcs_id(commit, filename) rid = filename[:-4] print("RID [%s]" % rid) assert False req = self.__object_cache.get("Requirement", vcs_id) if req != None: # Double check the id if req.get_id() != rid: # TODO: exception assert False else: fd = input_handler.get_fd(commit, filename) req = Requirement(fd, rid, self, self.__input_mods, self.__config) # Add the requirement to the cache. self.__object_cache.add(vcs_id, "Requirement", req) if req.ok(): # Store in the map, so that it is easy to access the # node by id. self.__requirements[req.get_id()] = req # Also store it in the digraph's node list for simple # access to the digraph algorithms. # TODO: self.nodes.append(req) else: self.error(45, "could not be parsed", req.id) everythings_fine = False
def __setup_repo(self, directory): '''Sets up the repository.''' tracer.debug("called") # Get one sample directory and create the repository from this. # Check all if they are in the same repository. # Note: because every directory list must contain at least one # directory, use just one. tracer.debug("using [%s] as sample directory" % directory) self.__repo = git.Repo(directory) # :-4: cut off the '/.git'. self.__repo_base_dir = self.__repo.git_dir[:-5] tracer.debug("repository base directory [%s]" % self.__repo_base_dir)
def __read_commits(self, input_handler, commits): '''Creates a TopicSet for each commit with the help of the input_handler.''' tracer.debug("called") for commit in commits: topic_set_vcs_id = \ input_handler.get_vcs_id_with_type(commit, "topics") tracer.debug("read topics with oid [%s]" % topic_set_vcs_id) topic_set = self.__object_cache.get("TopicSet", topic_set_vcs_id) if topic_set == None: tracer.debug("TopicSet with ID [%s] not in cache" % topic_set_vcs_id) topic_set = TopicSet(self.config, input_handler, commit, self.__object_cache, self.__input_mods) self.__object_cache.add(topic_set_vcs_id, "TopicSet", topic_set) self.__continuum_add(topic_set_vcs_id, topic_set) self.__object_cache.log_stats()
def get_vcs_id(self, commit, filename): '''Returns the vcs id of the given filename.''' tracer.debug("called: commit [%s] filename [%s]" % (commit, filename)) filename_split = filename.split("/") return self.__get_blob_with_filename_split(commit, filename_split).hexsha