def os2posix(ospath: str) -> str: """Convert a local path description to a POSIX path description. Parameters ---------- ospath : `str` Path using the local path separator. Returns ------- posix : `str` Path using POSIX path separator """ if IS_POSIX: return ospath posix = PurePath(ospath).as_posix() # PurePath strips trailing "/" from paths such that you can no # longer tell if a path is meant to be referring to a directory # Try to fix this. if ospath.endswith(os.sep) and not posix.endswith(posixpath.sep): posix += posixpath.sep return posix
def make_output_filename(input_filename): name = PurePath(input_filename).name replaceable_suffixes = [".fastq.gz", ".fq.gz", ".fastq", ".fq"] for s in replaceable_suffixes: if name.endswith(s): name = name[:-len(s)] break new_name = name + ".umi.fastq" if os.path.exists(new_name): exit_with_error(f"Output filename already exists: {new_name}, will not overwrite", EXIT_FILE_IO_ERROR) else: return new_name
def load_metadata(self): # extract metadata self.temp_dir = Path(tempfile.mkdtemp()) print("Extracting tables to %s..." % self.temp_dir) if self.seg_path is not None: seg_file = tarfile.open(self.seg_path, "r|*") for tinfo in seg_file: if tinfo.name.endswith( "lidarseg.json") and self.phase in tinfo.name: seg_file.extract(tinfo, self.temp_dir) elif tinfo.name.endswith( "category.json") and self.phase in tinfo.name: seg_file.extract(tinfo, self.temp_dir) json_path = self.temp_dir / tinfo.path json_path.rename( json_path.with_name("lidarseg_category.json")) seg_file.close() meta_file = tarfile.open(self.meta_path, "r|*") for tinfo in meta_file: if tinfo.name.startswith('v'): version = PurePath(tinfo.name).parts[0] meta_file.extract(tinfo, self.temp_dir) elif tinfo.name.startswith('map'): # directly extract map to output directory meta_file.extract(tinfo, self.output_path) meta_file.close() # load tables print("Constructing tables...") assert version.endswith( self.phase), "Phase mismatch in loading nuscenes!" self.table_path = self.temp_dir / version self.sample_table = _load_table(self.table_path / "sample.json") self.sample_data_table = _load_table(self.table_path / "sample_data.json") self.scene_table = _load_table(self.table_path / "scene.json") self.sensor_table = _load_table(self.table_path / "sensor.json") self.calibrated_sensor_table = _load_table(self.table_path / "calibrated_sensor.json") self.ego_pose_table = _load_table(self.table_path / "ego_pose.json") if self.seg_path is not None: self.lidarseg_table = _load_table(self.table_path / "lidarseg.json") # parse tables self._parse_scenes() self._parse_sample_data()
def createExcel(self): #Erase label2 self.lblmsg2.config(text='') #Erase label1 self.lblmsg.config(text='') self.lblmsg2.config(text="Creating .xlsx file, please wait.", fg='Black') self.lblmsg2.update_idletasks() try: x = 1 wbLocation = self.fileLoc.get() fName = self.fileName.get() if os.path.exists(wbLocation) == False: self.lblmsg2.config(text="Please, check the path", fg='Red') return wbLocation = "%s\%s.xlsx" % (wbLocation, fName) sharedDir = self.dirPath.get() if os.path.isdir(sharedDir) == False: self.lblmsg2.config(text="Please, check the path.", fg='Red') return workbook = xlsxwriter.Workbook(wbLocation) worksheet = workbook.add_worksheet() worksheet.set_column('A:A', 70) worksheet.set_column('B:D', 20) worksheet.set_column('E:E', 25) worksheet.set_column('F:F', 40) worksheet.set_column('G:G', 50) worksheet.set_column('H:K', 20) for folder in os.listdir(sharedDir): print(folder) worksheet.write(x, 0, folder) lenght = len(folder) y = lenght - 4 folderxml = '%s.xml' % folder[0:y] filepath = r"%s\%s\%s" % (sharedDir, folder, folderxml) tree = ET.parse(filepath) root = tree.getroot() for measure_id in root.iter('measure_id'): measID = str(measure_id.text) print("Measure ID: %s" % (measID)) worksheet.write(x, 1, measID) for interval in root.iter('interval'): interv = str(interval.text) print("Interval: %s" % (interv)) worksheet.write(x, 2, interv) for maxruntime in root.iter('maxruntime'): maxRunt = str(maxruntime.text) print("Max run time: %s" % (maxRunt)) worksheet.write(x, 3, maxRunt) for resource in root.iter('resource'): resour = str(resource.text) print("Resource: %s" % (resour)) worksheet.write(x, 4, resour) for automatic in root.iter('automatic'): autom = str(automatic.text) print("Automatic: %s" % (autom)) worksheet.write(x, 5, autom) for block in root.iter('block'): blockID = str(block.text) print("BlockID: %s" % (blockID)) worksheet.write(x, 6, blockID) directory = self.taskDirPath.get() directory = (r'%s' % directory) if os.path.isdir(directory) == False: self.lblmsg2.config(text="Please, check the path.", fg='Red') return y = 1 z = 7 for path, subdirs, files in os.walk(directory): for name in files: if name.endswith('.xml'): pathxml = PurePath(path, name) tree = ET.parse(r'%s' % pathxml) root = tree.getroot() for block in root.findall('block'): blockIdxml = block.get('id') if blockIdxml == blockID: lenght = len(PurePath(path, name).parts) while (y < lenght): pathName = PurePath(path, name).parts[y] if pathName.endswith('.xml'): vn = len(pathName) - 4 newName = pathName[0:vn] worksheet.write(x, z, newName) else: worksheet.write(x, z, pathName) y += 1 z += 1 x = x + 1 worksheet.add_table( 'A1:K%i' % x, { 'header_row': True, 'banded_rows': True, 'columns': [ { 'header': 'TestCase' }, { 'header': 'MeasureID' }, { 'header': 'Interval' }, { 'header': 'MaxRunTime' }, { 'header': 'Resource[HDMI Input]' }, { 'header': 'IdStatus[1=Automatic; 0=Not Automatic]' }, { 'header': 'BlockID' }, { 'header': 'Directory' }, { 'header': 'sub' }, { 'header': 'sub2' }, { 'header': 'sub3' }, ] }) worksheet.data_validation('F1:F%i' % x, { 'validate': 'list', 'source': ['0', '1'], }) worksheet.data_validation( 'E1:E%i' % x, { 'validate': 'list', 'source': [ 'desktop', 'witbe-4hdmiv1-0/vid/hdmi0', 'witbe-4hdmiv1-0/vid/hdmi1', 'witbe-4hdmiv1-0/vid/hdmi2', 'witbe-4hdmiv1-0/vid/hdmi3', 'witbe-4hdmiv1-1/vid/hdmi0', 'witbe-4hdmiv1-1/vid/hdmi1', 'witbe-4hdmiv1-1/vid/hdmi2', 'witbe-4hdmiv1-1/vid/hdmi3' ] }) workbook.close() self.lblmsg2.config(text="File successfully created!", fg='Black') except PermissionError: self.lblmsg2.config(text="Please, close the excel file: %s.xlsx" % fName, fg='Red') return except: self.lblmsg2.config(text="There's no .xml file in folder: %s" % folder, fg='Red') return