def source_directory_path(self): """ Path to the directory where source strings are stored. Paths are identified using a scoring system; more likely directory names get higher scores, as do directories with formats that only used for source strings. """ # If source repository explicitly marked source_repository = self.db_project.source_repository if source_repository.source_repo: return source_repository.checkout_path possible_sources = [] for root, dirnames, filenames in scandir.walk(self.checkout_path): for dirname in dirnames: if dirname in self.SOURCE_DIR_NAMES: score = self.SOURCE_DIR_SCORES[dirname] # Ensure the matched directory contains resources. directory_path = os.path.join(root, dirname) if directory_contains_resources(directory_path): # Extra points for source resources! if directory_contains_resources(directory_path, source_only=True): score += 3 possible_sources.append((directory_path, score)) if possible_sources: return max(possible_sources, key=lambda s: s[1])[0] else: raise MissingSourceDirectoryError( 'No source directory found for project {0}'.format(self.db_project.slug) )
def source_directory_path(self): """ Path to the directory where source strings are stored. Paths are identified using a scoring system; more likely directory names get higher scores, as do directories with formats that only used for source strings. """ possible_sources = [] for root, dirnames, filenames in os.walk(self.checkout_path): for dirname in dirnames: if dirname in self.SOURCE_DIR_NAMES: score = self.SOURCE_DIR_SCORES[dirname] # Ensure the matched directory contains resources. directory_path = os.path.join(root, dirname) if directory_contains_resources(directory_path): # Extra points for source resources! if directory_contains_resources(directory_path, source_only=True): score += 3 possible_sources.append((directory_path, score)) if possible_sources: return max(possible_sources, key=lambda s: s[1])[0] else: raise Exception('No source directory found for project {0}' .format(self.db_project.slug))
def source_directory_path(self): """ Path to the directory where source strings are stored. Paths are identified using a scoring system; more likely directory names get higher scores, as do directories with formats that only used for source strings. """ source_repository = self.db_project.source_repository # If project configuration provided, files could be stored in multiple # directories, so we just use the source repository checkout path if self.configuration: return source_repository.checkout_path # If source repository explicitly marked if source_repository.source_repo: return source_repository.checkout_path possible_sources = [] for root, dirnames, filenames in scandir.walk(self.checkout_path): for dirname in dirnames: if dirname in self.SOURCE_DIR_NAMES: score = self.SOURCE_DIR_SCORES[dirname] # Ensure the matched directory contains resources. directory_path = os.path.join(root, dirname) if directory_contains_resources(directory_path): # Extra points for source resources! if directory_contains_resources(directory_path, source_only=True): score += 3 possible_sources.append((directory_path, score)) if possible_sources: return max(possible_sources, key=lambda s: s[1])[0] else: raise MissingSourceDirectoryError( 'No source directory found for project {0}'.format(self.db_project.slug) )