Python os.path.splitext() Examples

The following are code examples for showing how to use os.path.splitext(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: GBVision   Author: GreenBlitz   File: recording_opencv_window.py    Apache License 2.0 14 votes vote down vote up
def __init__(self, window_name: str, file_name: str, fps=20.0, exit_button='qQ',
                 drawing_pipeline=EMPTY_PIPELINE, recording_pipeline=EMPTY_PIPELINE, width=0, height=0,
                 flags=cv2.WINDOW_FREERATIO):
        """
        initializes the stream window
        
        """
        OpenCVWindow.__init__(self, window_name, exit_button=exit_button, flags=flags)
        RecordingWindow.__init__(self, window_name=window_name, drawing_pipeline=drawing_pipeline,
                                 recording_pipeline=recording_pipeline)
        self.file_name = file_name

        _, file_ext = splitext(file_name)

        self.fourcc = cv2.VideoWriter_fourcc(*VIDEO_FILE_TYPE[file_ext.upper()])

        self.fps = fps

        self.video_writer = None
        self.width = width
        self.height = height 
Example 2
Project: PEAKachu   Author: tbischler   File: window.py    ISC License 6 votes vote down vote up
def init_libraries(self, paired_end, max_insert_size, ctr_libs,
                       exp_libs):
        self._paired_end = paired_end
        self._max_insert_size = max_insert_size
        self._ctr_lib_list = [splitext(basename(lib_file))[0]
                              for lib_file in ctr_libs]
        self._exp_lib_list = [splitext(basename(lib_file))[0]
                              for lib_file in exp_libs]
        # add libs to lib_dict
        for lib_file in exp_libs + ctr_libs:
            if not isfile(lib_file):
                sys.stderr.write("ERROR: The library file {} does not exist.\n"
                                 .format(lib_file))
                sys.exit(1)
            self._lib_dict[splitext(basename(lib_file))[0]] = Library(
                paired_end, max_insert_size, lib_file,
                deepcopy(self._replicon_dict))
        self._lib_names_list = list(self._lib_dict.keys())
        print("The following libraries were initialized:\n"
              "# Experiment libraries\n{0}\n"
              "# Control libraries\n{1}".format(
                  '\n'.join(self._exp_lib_list),
                  '\n'.join(self._ctr_lib_list))) 
Example 3
Project: PEAKachu   Author: tbischler   File: adaptive.py    ISC License 6 votes vote down vote up
def init_libraries(self, paired_end, max_insert_size, ctr_libs,
                       exp_libs):
        self._paired_end = paired_end
        self._max_insert_size = max_insert_size
        self._ctr_lib_list = [splitext(basename(lib_file))[0]
                              for lib_file in ctr_libs]
        self._exp_lib_list = [splitext(basename(lib_file))[0]
                              for lib_file in exp_libs]
        # add libs to lib_dict
        for lib_file in exp_libs + ctr_libs:
            if not isfile(lib_file):
                sys.stderr.write(
                    "ERROR: The library file {} does not exist.\n".format(
                        lib_file))
                sys.exit(1)
            self._lib_dict[splitext(basename(lib_file))[0]] = Library(
                paired_end, max_insert_size, lib_file,
                deepcopy(self._replicon_dict))
        self._lib_names_list = list(self._lib_dict.keys())
        print("The following libraries were initialized:\n"
              "# Experiment libraries\n{0}\n"
              "# Control libraries\n{1}".format(
                  '\n'.join(self._exp_lib_list),
                  '\n'.join(self._ctr_lib_list))) 
Example 4
Project: flasky   Author: RoseOu   File: _compat.py    MIT License 6 votes vote down vote up
def _check_if_pyc(fname):
    """Return True if the extension is .pyc, False if .py
    and None if otherwise"""
    from imp import find_module
    from os.path import realpath, dirname, basename, splitext

    # Normalize the file-path for the find_module()
    filepath = realpath(fname)
    dirpath = dirname(filepath)
    module_name = splitext(basename(filepath))[0]

    # Validate and fetch
    try:
        fileobj, fullpath, (_, _, pytype) = find_module(module_name, [dirpath])
    except ImportError:
        raise IOError("Cannot find config file. "
                      "Path maybe incorrect! : {0}".format(filepath))
    return pytype, fileobj, fullpath 
Example 5
Project: python-sii   Author: voipir   File: SectionEmitter.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def _logo_template(self):
        if self._logo_path:
            _, ext = path.splitext(self._logo_path)

            height    = '15mm'
            width     = '0.7\\textwidth'
            keepratio = 'true'

            return '\\includegraphics[height={h}, width={w}, keepaspectratio={r}]{{logo{ext}}}'.format(
                h   = height,
                w   = width,
                r   = keepratio,
                ext = ext
            )
        else:
            return '' 
Example 6
Project: rowgenerators   Author: Metatab   File: util.py    MIT License 6 votes vote down vote up
def file_ext(v):
    """Split of the extension of a filename, without throwing an exception of there is no extension. Does not
    return the leading '.'
    :param v: """

    from os.path import splitext

    if not v:
        return None

    try:
        try:
            v = splitext(v)[1][1:]
        except TypeError:
            v = splitext(v.fspath)[1][1:]

        if v == '*':  # Not a file name, probably a fragment regex
            return None

        return v.lower() if v else None
    except IndexError:
        return None 
Example 7
Project: mx   Author: graalvm   File: mx.py    GNU General Public License v2.0 6 votes vote down vote up
def importee_dir(self, importer_dir, suite_import, check_alternate=True):
        suitename = suite_import.name
        if suitename in self.suitenamemap:
            suitename = self.suitenamemap[suitename]

        # Try use the URL first so that a big repo is cloned to a local
        # directory whose named is based on the repo instead of a suite
        # nested in the big repo.
        base = None
        for urlinfo in suite_import.urlinfos:
            if urlinfo.abs_kind() == 'source':
                # 'https://github.com/graalvm/graal.git' -> 'graal'
                base, _ = os.path.splitext(basename(_urllib_parse.urlparse(urlinfo.url).path))
                if base: break
        if base:
            path = join(SiblingSuiteModel.siblings_dir(importer_dir), base)
        else:
            path = join(SiblingSuiteModel.siblings_dir(importer_dir), suitename)
        checked = self._check_exists(suite_import, path, check_alternate)
        return SuiteModel._checked_to_importee_tuple(checked, suite_import) 
Example 8
Project: mx   Author: graalvm   File: mx.py    GNU General Public License v2.0 6 votes vote down vote up
def get_file_extension(path):
    root, ext = os.path.splitext(path)
    if len(ext) > 0:
        ext = ext[1:]  # remove leading .
    if ext in _tar_compressed_extensions and os.path.splitext(root)[1] == ".tar":
        return "tar." + ext
    if ext == 'zip':
        _, pre_ext = os.path.splitext(root)
        if len(pre_ext) > 0:
            pre_ext = pre_ext[1:]  # remove leading .
        if pre_ext in _known_zip_pre_extensions:
            return pre_ext + ".zip"
    if ext == 'map':
        _, pre_ext = os.path.splitext(root)
        if len(pre_ext) > 0:
            pre_ext = pre_ext[1:]  # remove leading .
            return pre_ext + ".map"
    return ext 
Example 9
Project: mx   Author: graalvm   File: mx.py    GNU General Public License v2.0 6 votes vote down vote up
def suite_ci_files(suite, ci_path=None, extension=(".hocon", ".jsonnet", '.libsonnet')):
    """
    Get the list of ci files for the given suite

    :param suite: SourceSuite
    :param ci_path: str or None
    :param extension: str | tuple[str] | list[str] | set[str]
    :return:
    """
    assert isinstance(suite, SourceSuite), "suite must be a SourceSuite"
    assert extension is not None, "extension cannot be None, must be a string or iterable over strings like '.ext'."
    if isinstance(extension, str):
        extension = [extension]
    extension = set(extension)

    ci_files = os.listdir(join(suite.dir, ci_path)) if ci_path else os.listdir(suite.dir)
    return [join(ci_path, name) if ci_path else name
            for name in ci_files
            if os.path.splitext(name)[-1] in extension] 
Example 10
Project: tldr.py   Author: lord63   File: cli.py    MIT License 6 votes vote down vote up
def build_index():
    repo_directory = get_config()['repo_directory']
    index_path = path.join(repo_directory, 'pages', 'index.json')
    page_path = path.join(repo_directory, 'pages')

    tree_generator = os.walk(page_path)
    folders = next(tree_generator)[1]
    commands, new_index = {}, {}
    for folder in folders:
        pages = next(tree_generator)[2]
        for page in pages:
            command_name = path.splitext(page)[0]
            if command_name not in commands:
                commands[command_name] = {'name': command_name,
                                          'platform': [folder]}
            else:
                commands[command_name]['platform'].append(folder)
    command_list = [item[1] for item in
                    sorted(commands.items(), key=itemgetter(0))]
    new_index['commands'] = command_list

    with open(index_path, mode='w') as f:
        json.dump(new_index, f) 
Example 11
Project: Sigmedia-AVSR   Author: georgesterpu   File: extract_faces.py    GNU General Public License v3.0 6 votes vote down vote up
def main(argv):
    r'''
    Multithreaded face-alignment using OpenFace
    '''

    num_threads = int(argv[1]) if len(argv) > 1 else 1

    openface_bin = '/run/media/john_tukey/download/software/OpenFace/build/bin/FeatureExtraction'
    out_dir = '/run/media/john_tukey/download/datasets/tcdtimit/aligned_openface/'
    makedirs(out_dir, exist_ok=True)

    dataset_dir = '/run/media/john_tukey/download/datasets/adapt/work/tcdtimit/'
    train_list = './datasets/tcdtimit/splits/speaker-dependent/train.scp'
    test_list = './datasets/tcdtimit/splits/speaker-dependent/test.scp'

    train = get_files(train_list, dataset_dir)
    test = get_files(test_list, dataset_dir)

    label_map = dict()
    for file in train + test:
        label_map[file] = path.splitext(file.split('tcdtimit/')[-1])[0]

    with Pool(num_threads) as p:
        p.starmap(process_one_batch,
              zip(chunks(train+test, 1000), repeat(openface_bin), repeat(label_map), repeat(out_dir))) 
Example 12
Project: pytorch-segmentation-toolbox   Author: speedinghzl   File: datasets.py    MIT License 6 votes vote down vote up
def __getitem__(self, index):
        datafiles = self.files[index]
        image = cv2.imread(datafiles["img"], cv2.IMREAD_COLOR)
        size = image.shape
        name = osp.splitext(osp.basename(datafiles["img"]))[0]
        image = np.asarray(image, np.float32)
        image -= self.mean
        
        img_h, img_w, _ = image.shape
        pad_h = max(self.crop_h - img_h, 0)
        pad_w = max(self.crop_w - img_w, 0)
        if pad_h > 0 or pad_w > 0:
            image = cv2.copyMakeBorder(image, 0, pad_h, 0, 
                pad_w, cv2.BORDER_CONSTANT, 
                value=(0.0, 0.0, 0.0))
        image = image.transpose((2, 0, 1))
        return image, name, size 
Example 13
Project: pytorch-segmentation-toolbox   Author: speedinghzl   File: datasets.py    MIT License 6 votes vote down vote up
def __init__(self, root, list_path, crop_size=(505, 505), mean=(128, 128, 128)):
        self.root = root
        self.list_path = list_path
        self.crop_h, self.crop_w = crop_size
        self.mean = mean
        # self.mean_bgr = np.array([104.00698793, 116.66876762, 122.67891434])
        self.img_ids = [i_id.strip().split() for i_id in open(list_path)]
        self.files = [] 
        # for split in ["train", "trainval", "val"]:
        for item in self.img_ids:
            image_path, label_path = item
            name = osp.splitext(osp.basename(label_path))[0]
            img_file = osp.join(self.root, image_path)
            self.files.append({
                "img": img_file
            }) 
Example 14
Project: pytorch-segmentation-toolbox   Author: speedinghzl   File: datasets.py    MIT License 6 votes vote down vote up
def __getitem__(self, index):
        datafiles = self.files[index]
        image = cv2.imread(datafiles["img"], cv2.IMREAD_COLOR)
        size = image.shape
        name = osp.splitext(osp.basename(datafiles["img"]))[0]
        image = np.asarray(image, np.float32)
        image -= self.mean
        
        img_h, img_w, _ = image.shape
        pad_h = max(self.crop_h - img_h, 0)
        pad_w = max(self.crop_w - img_w, 0)
        if pad_h > 0 or pad_w > 0:
            image = cv2.copyMakeBorder(image, 0, pad_h, 0, 
                pad_w, cv2.BORDER_CONSTANT, 
                value=(0.0, 0.0, 0.0))
        image = image.transpose((2, 0, 1))
        return image, name, size 
Example 15
Project: pyqt5downloader   Author: mostafaabobakr7   File: index.py    GNU General Public License v3.0 6 votes vote down vote up
def search(self):
        try:
            # trying to get url info
            # first get pasted url from lineEdit_4
            mainurl = ur.urlopen(self.lineEdit_4.text())
            # use humanize lib to get size in MB from url.info()
            # note that (mainurl.info()['Content-Length']) because it is a dictionary
            file_size_mb = humanize.naturalsize(mainurl.info()['Content-Length'])
            self.textBrowser.setText(file_size_mb)
            # display file Name and type from a url
            disassembled = urlparse(self.lineEdit_4.text())
            filename, file_ext = splitext(basename(disassembled.path))
            name = urllib.parse.unquote(filename)
            self.textBrowser_5.setText(name + file_ext)
            self.textBrowser_2.setText(file_ext)
        except Exception:
            pass
        QApplication.processEvents() 
Example 16
Project: exoduscli   Author: cthlo   File: main.py    MIT License 6 votes vote down vote up
def _run_exodus(*args):
    '''Run a Exodus using runpy
    '''
    fullpath = path.join(config.addonsdir, config.exodus['id'], config.exodus['entryfile'])
    entrypath, entryfile = path.split(fullpath)
    if entrypath not in sys.path:
        sys.path.insert(0, entrypath)
    module, _ = path.splitext(entryfile)

    # Exodus assumes thread names start at 1
    # and gets provider names from the thread name
    c = threading._counter = count().next
    c() # consume 0

    sys.argv = list(args)
    # note: cannot use __import__ because Exodus spawns threads that do import
    # so that would cause deadlock
    old_modules = set(sys.modules.keys()) # unload the newly added modules after runpy
    runpy.run_module(module)
    for k in set(sys.modules.keys()) - old_modules:
        del sys.modules[k] 
Example 17
Project: smaslennikov.github.io   Author: smaslennikov   File: mpdnp.py    MIT License 6 votes vote down vote up
def np(data, buffer, args):
  """
    Send information about the currently
    played song to the channel.
  """
  host = wc.config_get_plugin("host")
  port = int(wc.config_get_plugin("port"))
  cont = mpd.MpdController(host=host, port=port)
  song = cont.getCurrentSong()
  pos, length, pct = cont.getSongPosition()
  
  # insert artist, title, album, track, path
  d = song.__dict__
  d.update({
      "title_or_file": song.title or splitext(basename(song.path))[0],
      "pos_sec": "%02d" % (pos / 60),
      "pos_min": str(pos / 60),
      "length_sec": "%02d" % (length % 60),
      "length_min": str(length / 60),
      "pct": "%2.0f" % pct,
  })
  
  wc.command(wc.current_buffer(), (subst(wc.config_get_plugin("format"), d)))
  return 0 
Example 18
Project: smaslennikov.github.io   Author: smaslennikov   File: mpdnp.py    MIT License 6 votes vote down vote up
def np(data, buffer, args):
  """
    Send information about the currently
    played song to the channel.
  """
  host = wc.config_get_plugin("host")
  port = int(wc.config_get_plugin("port"))
  cont = mpd.MpdController(host=host, port=port)
  song = cont.getCurrentSong()
  pos, length, pct = cont.getSongPosition()
  
  # insert artist, title, album, track, path
  d = song.__dict__
  d.update({
      "title_or_file": song.title or splitext(basename(song.path))[0],
      "pos_sec": "%02d" % (pos / 60),
      "pos_min": str(pos / 60),
      "length_sec": "%02d" % (length % 60),
      "length_min": str(length / 60),
      "pct": "%2.0f" % pct,
  })
  
  wc.command(wc.current_buffer(), (subst(wc.config_get_plugin("format"), d)))
  return 0 
Example 19
Project: seamseg   Author: mapillary   File: dataset.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self, in_dir, transform):
        super(ISSTestDataset, self).__init__()
        self.in_dir = in_dir
        self.transform = transform

        # Find all images
        self._images = []
        for img_path in chain(
                *(glob.iglob(path.join(self.in_dir, '**', ext), recursive=True) for ext in ISSTestDataset._EXTENSIONS)):
            _, name_with_ext = path.split(img_path)
            idx, _ = path.splitext(name_with_ext)

            with Image.open(img_path) as img_raw:
                size = (img_raw.size[1], img_raw.size[0])

            self._images.append({
                "idx": idx,
                "path": img_path,
                "size": size,
            }) 
Example 20
Project: seamseg   Author: mapillary   File: test_panoptic.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def save_prediction_raw(raw_pred, _, img_info, out_dir):
    # Prepare folders and paths
    folder, img_name = path.split(img_info["rel_path"])
    img_name, _ = path.splitext(img_name)
    out_dir = path.join(out_dir, folder)
    ensure_dir(out_dir)
    out_path = path.join(out_dir, img_name + ".pth.tar")

    out_data = {
        "sem_pred": raw_pred[0],
        "bbx_pred": raw_pred[1],
        "cls_pred": raw_pred[2],
        "obj_pred": raw_pred[3],
        "msk_pred": raw_pred[4]
    }
    torch.save(out_data, out_path) 
Example 21
Project: straditize   Author: Chilipp   File: menu_actions.py    GNU General Public License v3.0 6 votes vote down vote up
def _export(self):
        fname = self.txt_fname.text()
        ending = osp.splitext(fname)[1]
        self.stradi.set_attr('exported', str(dt.datetime.now()))
        meta = self.stradi.valid_attrs
        if ending in ['.xls', '.xlsx']:
            with pd.ExcelWriter(fname) as writer:
                self.df.to_excel(writer, 'Data')
                if self.cb_include_meta.isChecked() and len(meta):
                    meta.to_excel(writer, 'Metadata', header=False)
        else:
            with open(fname, 'w') as f:
                if self.cb_include_meta.isChecked():
                    for t in meta.iloc[:, 0].items():
                        f.write('# %s: %s\n' % t)
            self.df.to_csv(fname, mode='a')
        self.accept() 
Example 22
Project: straditize   Author: Chilipp   File: menu_actions.py    GNU General Public License v3.0 6 votes vote down vote up
def _start_directory(self):
        def check_current():
            dirname = osp.dirname(current)
            if osp.exists(dirname) and osp.isdir(dirname):
                return dirname
        if self.straditizer is not None:
            current = None
            for attr in 'project_file', 'image_file':
                try:
                    current = self.straditizer.get_attr(attr)
                except KeyError:
                    pass
                else:
                    start = check_current()
                    if start is not None:
                        break
            if current:
                return osp.splitext(current)[0]
        return os.getcwd() 
Example 23
Project: YAPyPy   Author: Xython   File: py_compile.py    MIT License 6 votes vote down vote up
def py_compile(node, filename='<unknown>', is_entrypoint=False):
    if isinstance(node, Tag):
        ctx = _non_ctx.enter_new(node.tag)
        ctx.bc.filename = filename
        ctx.bc.name = '__main__' if is_entrypoint else splitext(
            Path(filename).relative())[0]
        try:
            py_emit(node.it, ctx)
        except SyntaxError as exc:
            exc.filename = filename
            raise exc
        return ctx.bc.to_code()
        # try:
        #     return ctx.bc.to_code()
        # except Exception as e:
        #     dump_bytecode(ctx.bc)
        #     raise e
    else:
        tag = to_tagged_ast(node)
        return py_compile(tag, filename, is_entrypoint=is_entrypoint) 
Example 24
Project: platzi-hello-gae   Author: xertica-cloud   File: fileadmin.py    GNU General Public License v2.0 6 votes vote down vote up
def is_file_allowed(self, filename):
        """
            Verify if file can be uploaded.

            Override to customize behavior.

            :param filename:
                Source file name
        """
        ext = op.splitext(filename)[1].lower()

        if ext.startswith('.'):
            ext = ext[1:]

        if self.allowed_extensions and ext not in self.allowed_extensions:
            return False

        return True 
Example 25
Project: PEAKachu   Author: tbischler   File: library.py    ISC License 5 votes vote down vote up
def __init__(self, paired_end, max_insert_size, bam_file, replicon_dict):
        self.paired_end = paired_end
        self.bam_file = bam_file
        self.max_insert_size = max_insert_size
        self.lib_name = splitext(basename(bam_file))[0]
        self.replicon_dict = replicon_dict 
Example 26
Project: python-sii   Author: voipir   File: SectionEmitter.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def resources(self):
        ress = []

        if self._logo_path:
            _, ext = path.splitext(self._logo_path)
            ress.append(Resource('logo' + ext, self._logo_data))

        return ress 
Example 27
Project: BDCN   Author: wandoucao   File: ablation_test.py    MIT License 5 votes vote down vote up
def test(model, args):
    test_root = cfg.config_test[args.dataset]['data_root']
    test_lst = cfg.config_test[args.dataset]['data_lst']
    test_name_lst = os.path.join(test_root, test_lst)

    if 'Multicue' in args.dataset:
        test_lst = test_lst % args.k

    mean_bgr = np.array(cfg.config_test[args.dataset]['mean_bgr'])

    test_img = Data(test_root, test_lst, 0.5, mean_bgr=mean_bgr)
    testloader = torch.utils.data.DataLoader(
        test_img, batch_size=1, shuffle=False, num_workers=8)
    lst = np.loadtxt(test_name_lst, dtype=str)[:, 0]
    nm = [osp.splitext(osp.split(x)[-1])[0] for x in lst]
    save_dir = args.res_dir
    if not os.path.exists(save_dir):
        os.mkdir(save_dir)
    if args.cuda:
        model.cuda()
    model.eval()
    data_iter = iter(testloader)
    iter_per_epoch = len(testloader)
    start_time = time.time()
    all_t = 0
    for i, (data, _) in enumerate(testloader):
        if args.cuda:
            data = data.cuda()
        data = Variable(data, volatile=True)
        t1 = time.time()
        out = model(data)
        t = F.sigmoid(out[-1]).cpu().data.numpy()[0, 0, :, :]
        if not os.path.exists(os.path.join(save_dir, 'fuse')):
            os.mkdir(os.path.join(save_dir, 'fuse'))
        cv2.imwrite(os.path.join(save_dir, 'fuse', '%s.jpg'%nm[i]), 255-t*255)
        all_t += time.time() - t1

    print(all_t)
    print('Overall Time use: ', time.time() - start_time) 
Example 28
Project: MetrixReloaded   Author: Scrounger   File: MetrixReloadedCover.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def findCover(self, path):
		fpath = p1 = p2 = p3 = ""
		name, ext = os_path.splitext(path)
		ext = ext.lower()

		if os_path.isfile(path):
			dir = os_path.dirname(path)
			p1 = name
			p2 = os_path.join(dir, os_path.basename(dir))

		elif os_path.isdir(path):
			if path.lower().endswith("/bdmv"):
				dir = path[:-5]
				if dir.lower().endswith("/brd"): dir = dir[:-4]
			elif path.lower().endswith("video_ts"):
				dir = path[:-9]
				if dir.lower().endswith("/dvd"): dir = dir[:-4]
			else:
				dir = path
				p2 = os_path.join(dir, "folder")

			prtdir, dirname = os_path.split(dir)
			p1 = os_path.join(dir, dirname)
			p3 = os_path.join(prtdir, dirname)

		pathes = (p1, p2, p3)
		for p in pathes:
			for ext in self.exts:
				path = p + ext
				if os_path.exists(path): break
			if os_path.exists(path):
				fpath = path
				break
		return (p1, fpath) 
Example 29
Project: mx   Author: graalvm   File: mx.py    GNU General Public License v2.0 5 votes vote down vote up
def _find_packages(project, onlyPublic=True, included=None, excluded=None):
    """
    Finds the set of packages defined by a project.

    :param JavaProject project: the Java project to process
    :param bool onlyPublic: specifies if only packages containing a ``package-info.java`` file are to be considered
    :param set included: if not None or empty, only consider packages in this set
    :param set excluded: if not None or empty, do not consider packages in this set
    """
    sourceDirs = project.source_dirs()
    def is_visible(folder, names):
        for name in names:
            if onlyPublic:
                if name == 'package-info.java':
                    return True
            elif name.endswith('.java'):
                pubClassPattern = re.compile(r"^public\s+((abstract|final)\s+)?(class|(@)?interface|enum)\s*" + splitext(name)[0] + r"\W.*", re.MULTILINE)
                with open(join(folder, name)) as f:
                    for l in f.readlines():
                        if pubClassPattern.match(l):
                            return True
        return False
    packages = set()
    for sourceDir in sourceDirs:
        for root, _, files in os.walk(sourceDir):
            if is_visible(root, files):
                package = root[len(sourceDir) + 1:].replace(os.sep, '.')
                if not included or package in included:
                    if not excluded or package not in excluded:
                        packages.add(package)
    return packages 
Example 30
Project: PyTeCK   Author: pr-omethe-us   File: eval_model.py    MIT License 5 votes vote down vote up
def create_simulations(dataset, properties):
    """Set up individual simulations for each ignition delay value.

    Parameters
    ----------
    dataset :

    properties : pyked.chemked.ChemKED
        ChemKED object with full set of experimental properties

    Returns
    -------
    simulations : list
        List of :class:`Simulation` objects for each simulation

    """

    simulations = []
    for idx, case in enumerate(properties.datapoints):
        sim_meta = {}
        # Common metadata
        sim_meta['data-file'] = dataset
        sim_meta['id'] = splitext(basename(dataset))[0] + '_' + str(idx)

        simulations.append(Simulation(properties.experiment_type,
                                      properties.apparatus.kind,
                                      sim_meta,
                                      case
                                      )
                           )
    return simulations 
Example 31
Project: openhatch   Author: campbe13   File: genspider.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def _list_templates(self):
        print "Available templates:"
        for filename in sorted(os.listdir(self.templates_dir)):
            if filename.endswith('.tmpl'):
                print "  %s" % splitext(filename)[0] 
Example 32
Project: openhatch   Author: campbe13   File: eggstorage.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def list(self, project):
        eggdir = path.join(self.basedir, project)
        versions = [path.splitext(path.basename(x))[0] \
            for x in glob("%s/*.egg" % eggdir)]
        return sorted(versions, key=LooseVersion) 
Example 33
Project: gitautopush   Author: choldgraf   File: gitautopush.py    MIT License 5 votes vote down vote up
def _is_ipynb(path):
    return op.splitext(path)[-1] == '.ipynb' 
Example 34
Project: ICDAR-2019-SROIE   Author: zzzDavid   File: my_data.py    MIT License 5 votes vote down vote up
def get_files(data_path="data/"):
    json_files = sorted(
        (f for f in os.scandir(data_path) if f.name.endswith(".json")), key=lambda f: f.path
    )
    txt_files = sorted(
        (f for f in os.scandir(data_path) if f.name.endswith(".txt")), key=lambda f: f.path
    )

    assert len(json_files) == len(txt_files)
    for f1, f2 in zip(json_files, txt_files):
        assert path.splitext(f1)[0] == path.splitext(f2)[0]

    return json_files, txt_files 
Example 35
Project: ICDAR-2019-SROIE   Author: zzzDavid   File: my_data.py    MIT License 5 votes vote down vote up
def create_data(data_path="tmp/data/"):
    raise DeprecationWarning

    json_files, txt_files = get_files(data_path)
    keys = [path.splitext(f.name)[0] for f in json_files]

    data_dict = {}

    for key, json_file, txt_file in zip(keys, json_files, txt_files):
        with open(json_file, "r", encoding="utf-8") as json_opend:
            key_info = json.load(json_opend)

        text = sort_text(txt_file)
        text_space = regex.sub(r"[\t\n]", " ", text)

        text_class = numpy.zeros(len(text), dtype=int)

        for i, k in enumerate(iter(key_info)):
            if k == "total":
                continue

            v = key_info[k]
            if not v in text_space:
                s = None
                e = 0
                while s is None and e < 3:
                    e += 1
                    s = regex.search("(" + v + "){e<=" + str(e) + "}", text_space)
                v = s[0]

            pos = text_space.find(v)
            text_class[pos : pos + len(v)] = i + 1

        data_dict[key] = (text, text_class)

        print(txt_file.path)
        color_print(text, text_class)

    return keys, data_dict 
Example 36
Project: neural-style-docker   Author: albarji   File: utils.py    MIT License 5 votes vote down vote up
def filename(path):
    """Given a full path to a file, returns just its name, without path or extension"""
    return splitext(basename(path))[0] 
Example 37
Project: neural-style-docker   Author: albarji   File: utils.py    MIT License 5 votes vote down vote up
def fileext(path):
    """Given a full path to a file, returns just its extension"""
    return splitext(basename(path))[1] 
Example 38
Project: Sigmedia-AVSR   Author: georgesterpu   File: files.py    GNU General Public License v3.0 5 votes vote down vote up
def read_sentence_labels(filename, unit='viseme'):
    r"""Finds the labels associated with a sentence
    in a .mlf label file
    Parameters
    ----------
    filename : `str`
    unit : `viseme` or `phoneme`
        The modeled speech unit

    Returns
    -------
    label_seq : `list`
        A list of label symbols
    """
    file = path.splitext(path.split(filename)[1])[0]

    if unit == 'viseme':
        transcript = viseme_file
    elif unit == 'phoneme':
        transcript = phoneme_file
    elif unit == 'character':
        transcript = character_file
    else:
        raise Exception('only `viseme`, `phoneme` and `character` unit transcriptions are supported')

    with open(transcript, 'r') as f:
        contents = f.read()

    # start = contents.find(file)
    # end = contents.find('.\n', start)
    # sentence_transcript = contents[start:end].splitlines()[1:]
    #
    # label_seq = [item.split()[-1] for item in sentence_transcript]
    # return label_seq
    return _get_transcript_from_buffer(contents, file) 
Example 39
Project: Sigmedia-AVSR   Author: georgesterpu   File: files.py    GNU General Public License v3.0 5 votes vote down vote up
def read_all_sentences_labels(filenames, unit='viseme'):
    r"""
    Multi-file version of `read_sentence_labels`
    which prevents reading the ground truth file multiple times
    Parameters
    ----------
    filenames
    unit

    Returns
    -------

    """

    if unit == 'viseme':
        transcript = viseme_file
    elif unit == 'phoneme':
        transcript = phoneme_file
    elif unit == 'character':
        transcript = character_file
    else:
        raise Exception('only `viseme`, `phoneme` and `character` unit transcriptions are supported')

    with open(transcript, 'r') as f:
        contents = f.read()

    labels = {}
    for filename in filenames:
        file = path.splitext(path.split(filename)[1])[0]
        labels[filename] = _get_transcript_from_buffer(contents, file)

    return labels 
Example 40
Project: Sigmedia-AVSR   Author: georgesterpu   File: dataset_writer.py    GNU General Public License v3.0 5 votes vote down vote up
def _remove_extensions(filenames):
    return [path.splitext(file)[0] for file in filenames] 
Example 41
Project: pytorch-segmentation-toolbox   Author: speedinghzl   File: datasets.py    MIT License 5 votes vote down vote up
def __init__(self, root, list_path, max_iters=None, crop_size=(321, 321), mean=(128, 128, 128), scale=True, mirror=True, ignore_label=255):
        self.root = root
        self.list_path = list_path
        self.crop_h, self.crop_w = crop_size
        self.scale = scale
        self.ignore_label = ignore_label
        self.mean = mean
        self.is_mirror = mirror
        # self.mean_bgr = np.array([104.00698793, 116.66876762, 122.67891434])
        self.img_ids = [i_id.strip().split() for i_id in open(list_path)]
        if not max_iters==None:
                self.img_ids = self.img_ids * int(np.ceil(float(max_iters) / len(self.img_ids)))
        self.files = []
        # for split in ["train", "trainval", "val"]:
        for item in self.img_ids:
            image_path, label_path = item
            name = osp.splitext(osp.basename(label_path))[0]
            img_file = osp.join(self.root, image_path)
            label_file = osp.join(self.root, label_path)
            self.files.append({
                "img": img_file,
                "label": label_file,
                "name": name
            })
        self.id_to_trainid = {-1: ignore_label, 0: ignore_label, 1: ignore_label, 2: ignore_label,
                              3: ignore_label, 4: ignore_label, 5: ignore_label, 6: ignore_label,
                              7: 0, 8: 1, 9: ignore_label, 10: ignore_label, 11: 2, 12: 3, 13: 4,
                              14: ignore_label, 15: ignore_label, 16: ignore_label, 17: 5,
                              18: ignore_label, 19: 6, 20: 7, 21: 8, 22: 9, 23: 10, 24: 11, 25: 12, 26: 13, 27: 14,
                              28: 15, 29: ignore_label, 30: ignore_label, 31: 16, 32: 17, 33: 18}
        print('{} images are loaded!'.format(len(self.img_ids))) 
Example 42
Project: pytorch-segmentation-toolbox   Author: speedinghzl   File: datasets.py    MIT License 5 votes vote down vote up
def __init__(self, root, list_path, crop_size=(505, 505)):
        self.root = root
        self.list_path = list_path
        self.crop_h, self.crop_w = crop_size
        # self.mean_bgr = np.array([104.00698793, 116.66876762, 122.67891434])
        self.img_ids = [i_id.strip().split()[0] for i_id in open(list_path)]
        self.files = [] 
        # for split in ["train", "trainval", "val"]:
        for image_path in self.img_ids:
            name = osp.splitext(osp.basename(image_path))[0]
            img_file = osp.join(self.root, image_path)
            self.files.append({
                "img": img_file
            }) 
Example 43
Project: selfmailbot   Author: f213   File: helpers.py    MIT License 5 votes vote down vote up
def get_file(file: telegram.File) -> BytesIO:
    attachment = BytesIO()
    attachment.name = str(uuid.uuid4()) + '.' + path.splitext(file.file_path)[1]

    file.download(out=attachment)
    attachment.seek(0, 0)

    return attachment 
Example 44
Project: gpfsapi-examples   Author: arcapix   File: type_sizes_piechart.py    MIT License 5 votes vote down vote up
def type_sizes(file_list):
    c = Counter()

    for f in file_list:
        c.update({splitext(f.name): f.filesize})

    return c 
Example 45
Project: openstack-ops-middleware   Author: sapcc   File: statsd.py    Apache License 2.0 5 votes vote down vote up
def process_response(self, start, environ, response_wrapper,
                         exception=None):
        self.client.increment('responses_total')

        status = response_wrapper.get('status')
        if status:
            status_code = status.split()[0]
        else:
            status_code = 'none'

        method = environ['REQUEST_METHOD']

        # cleanse request path
        path = urlparse.urlparse(environ['SCRIPT_NAME'] +
                                 environ['PATH_INFO']).path
        # strip extensions
        path = splitext(path)[0]

        # replace parts of the path with constants based on strategy
        path = self.replace_strategy.apply(path)

        parts = path.rstrip('\/').split('/')
        if exception:
            parts.append(exception.__class__.__name__)
        api = '/'.join(parts)

        self.client.timing('latency_by_api',
                           time.time() - start,
                           tags=[
                               'method:%s' % method,
                               'api:%s' % api
                           ])

        self.client.increment('responses_by_api',
                              tags=[
                                  'method:%s' % method,
                                  'api:%s' % api,
                                  'status:%s' % status_code
                              ]) 
Example 46
Project: arriz   Author: MycroftAI   File: arriz.py    Apache License 2.0 5 votes vote down vote up
def write_image(cls, filename, arr):
        """Write png or jpg image"""
        ext = splitext(filename)[1]
        if ext not in ['.png', '.jpg', '.jpeg']:
            filename += '.png'
        try:
            from PIL import Image
        except ImportError:
            raise ValueError('Install pillow to use write_png! (pip install pillow)')
        arr = np.rot90(cls._normalize_arr(arr), 1)
        px_arr = np.array([[list(_calc_color(val)) for val in row] for row in arr], 'uint8')
        im = Image.fromarray(px_arr, 'RGB')
        im.save(filename) 
Example 47
Project: code-base-investigator   Author: intel   File: util.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def ensure_ext(fname, extensions):
    """Return true if the path passed in has specified extension"""
    if not isinstance(extensions, Iterable):
        extensions = [extensions]

    split = splitext(fname)
    return len(split) == 2 and split[1].lower() in extensions 
Example 48
Project: code-base-investigator   Author: intel   File: file_parser.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, _filename):
        self._filename = _filename
        self.full_line = ''

        split = splitext(_filename)
        if len(split) == 2:
            self._file_extension = split[1].lower()
        else:
            self._file_extension = None 
Example 49
Project: me-ica   Author: ME-ICA   File: mghformat.py    GNU Lesser General Public License v2.1 5 votes vote down vote up
def filespec_to_file_map(klass, filespec):
        """ Check for compressed .mgz format, then .mgh format """
        if splitext(filespec)[1] == '.mgz':
            return dict(image=FileHolder(filename=filespec))
        return super(MGHImage, klass).filespec_to_file_map(filespec) 
Example 50
Project: ncm2   Author: ncm2   File: ncm2_core.py    MIT License 5 votes vote down vote up
def load_subscope_detectors(self, paths):
        new_scope = False

        # auto find scopers
        for py in paths:
            if py in self._loaded_plugins:
                continue
            self._loaded_plugins[py] = True

            try:
                mod = path.splitext(path.basename(py))[0]
                mod = "ncm2_subscope_detector.%s" % mod
                m = import_module(mod)
            except Exception as ex:
                logger.exception('importing scoper <%s> failed', py)
                continue

            sd = m.SubscopeDetector(self.nvim)

            for scope in sd.scope:
                if scope not in self._subscope_detectors:
                    self._subscope_detectors[scope] = []
                    new_scope = True

                self._subscope_detectors[scope].append(sd)

            logger.info('subscope detector <%s> for %s', py, sd.scope)

        if not new_scope:
            return

        detectors_sync = {}
        for scope in self._subscope_detectors.keys():
            detectors_sync[scope] = 1

        self.notify('ncm2#_s', 'subscope_detectors', detectors_sync)
        self.notify('ncm2#_hook_for_subscope_detectors')