def read_group_file(path): """Reads group file, returns list of repos and their levels Group file is a CSV file containing a list of DDR collection repo IDs and and indicator of which binaries should be present (see LEVELS). >>> from DDR import organization >>> p = '/var/www/media/base/ddr-testing/WD5000BMV-2.csv' >>> organization.read_group_file(p) [{'id': 'ddr-testing-100', 'level': 'full'}, {'id': 'ddr-testing-101', 'level': 'access'}, ...] @param path: Absolute path to group file. @returns: List of dicts (id, level) """ repos = [] with open(path, "rb") as f: reader = fileio.csv_reader(f) for id, level in reader: repos.append({"id": id, "level": level}) return repos
def read_group_file( path ): """Reads group file, returns list of repos and their levels Group file is a CSV file containing a list of DDR collection repo IDs and and indicator of which binaries should be present (see LEVELS). >>> from DDR import organization >>> p = '/var/www/media/base/ddr-testing/WD5000BMV-2.csv' >>> organization.read_group_file(p) [{'id': 'ddr-testing-100', 'level': 'full'}, {'id': 'ddr-testing-101', 'level': 'access'}, ...] @param path: Absolute path to group file. @returns: List of dicts (id, level) """ repos = [] with open(path, 'rb') as f: reader = fileio.csv_reader(f) for id,level in reader: repos.append({'id':id, 'level':level}) return repos
def load_csv(self, text: str): """Load terms from a CSV file. id, topics title, Topics description,"DDR Topics" id,_title,title,parent_id,weight,encyc_urls,description,created,modified 120,"Activism and involvement [120]","Activism and involvement",0,0,"","","1969-12-31T00:00:00-0800","1969-12-31T00:00:00-0800" @param text: str Raw contents of CSV file @returns: Index object with terms """ pseudofile = io.StringIO(text) reader = fileio.csv_reader(pseudofile) terms = [] for n, row in enumerate(reader): if (n == 0): self.id = row[1].strip() elif (n == 1): self.title = row[1].strip() elif (n == 2): self.description = row[1].strip() elif (n == 3): if (row != CSV_HEADERS): print('Expected these headers:') print(' %s' % CSV_HEADERS) print('Got these:') print(' %s' % row) raise Exception( "Sorry not smart enough to rearrange the headers myself... (;-_-)" ) else: # convert row to dict t = {} for c, col in enumerate(CSV_HEADERS): t[col] = row[c].strip() # special processing for certain columns if col == 'encyc_urls': t[col] = self._parse_csv_urls(t[col]) term = Term.from_dict(t) terms.append(term) self._build(terms)
def load_csv(self, text): """Load terms from a CSV file. id, topics title, Topics description,"DDR Topics" id,_title,title,parent_id,weight,encyc_urls,description,created,modified 120,"Activism and involvement [120]","Activism and involvement",0,0,"","","1969-12-31T00:00:00-0800","1969-12-31T00:00:00-0800" @param text: str Raw contents of CSV file @returns: Index object with terms """ pseudofile = StringIO.StringIO(text) reader = fileio.csv_reader(pseudofile) terms = [] for n,row in enumerate(reader): if (n == 0): self.id = row[1].strip() elif (n == 1): self.title = row[1].strip() elif (n == 2): self.description = row[1].strip() elif (n == 3): if (row != CSV_HEADERS): print('Expected these headers:') print(' %s' % CSV_HEADERS) print('Got these:') print(' %s' % row) raise Exception("Sorry not smart enough to rearrange the headers myself... (;-_-)") else: # convert row to dict t = {} for c,col in enumerate(CSV_HEADERS): t[col] = row[c].strip() # special processing for certain columns if col == 'encyc_urls': t[col] = self._parse_csv_urls(t[col]) term = Term.from_dict(t) terms.append(term) self._build(terms)