Python os.path.curdir() Examples

The following are code examples for showing how to use os.path.curdir(). 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: tox-debian-plugin   Author: balabit   File: install.py    MIT License 6 votes vote down vote up
def install_debian_deps(path, deps, opts, action):
    if not deps:
        return

    __ensure_commands(['apt-get', 'dpkg', 'cp'])

    tmp_dir = mkdtemp(prefix='dpkg-')

    try:
        action.setactivity('apt-get download', ', '.join(deps))
        action.popen(['apt-get', 'download'] + opts + deps, cwd=tmp_dir)
        packages = fnmatch.filter(listdir(tmp_dir), '*.deb')

        for package in packages:
            action.setactivity('dpkg extract', package)
            action.popen(['dpkg', '--vextract', package, curdir], cwd=tmp_dir)

        tmp_usr = path_join(tmp_dir, 'usr')
        if isdir(tmp_usr):
            action.setactivity('copy', ', '.join(__iter_files(tmp_usr)))
            action.popen(['cp', '-r'] + listdir(tmp_usr) + [path], cwd=tmp_usr)

    finally:
        rmtree(tmp_dir) 
Example 2
Project: channel-pruning   Author: yihui-he   File: builder.py    MIT License 6 votes vote down vote up
def resnet(n=3, num_output = 16):
    """6n+2, n=3 9 18 coresponds to 20 56 110 layers"""    
    net_name = "resnet-"    
    pt_folder = osp.join(osp.abspath(osp.curdir), net_name +str(6*n+2))
    name = net_name+str(6*n+2)+'-cifar10'

    if n > 18:
        # warm up
        solver = Solver(solver_name="solver_warm.prototxt", folder=pt_folder, lr_policy=Solver.policy.fixed)
        solver.p.base_lr = 0.01
        solver.set_max_iter(500)
        solver.write()
        del solver
    
    solver = Solver(folder=pt_folder)
    solver.write()
    del solver

    builder = Net(name)
    builder.Data('cifar-10-batches-py/train', phase='TRAIN', crop_size=32)
    builder.Data('cifar-10-batches-py/test', phase='TEST')
    builder.resnet_cifar(n, num_output=num_output)
    builder.write(folder=pt_folder) 
Example 3
Project: channel-pruning   Author: yihui-he   File: builder.py    MIT License 6 votes vote down vote up
def resnet_orth(n=3):
    """6n+2, n=3 9 18 coresponds to 20 56 110 layers"""    
    net_name = "resnet-orth-"    
    pt_folder = osp.join(osp.abspath(osp.curdir), net_name +str(6*n+2))
    name = net_name+str(6*n+2)+'-cifar10'

    if n > 18:
        # warm up
        solver = Solver(solver_name="solver_warm.prototxt", folder=pt_folder, lr_policy=Solver.policy.fixed)
        solver.p.base_lr = 0.01
        solver.set_max_iter(500)
        solver.write()
        del solver
    
    solver = Solver(folder=pt_folder)
    solver.write()
    del solver

    builder = Net(name)
    builder.Data('cifar-10-batches-py/train', phase='TRAIN', crop_size=32)
    builder.Data('cifar-10-batches-py/test', phase='TEST')
    builder.resnet_cifar(n, orth=True)
    builder.write(folder=pt_folder) 
Example 4
Project: channel-pruning   Author: yihui-he   File: builder.py    MIT License 6 votes vote down vote up
def resnet_orth_v2(n=3):
    """6n+2, n=3 9 18 coresponds to 20 56 110 layers"""    
    net_name = "resnet-orth-v2"    
    pt_folder = osp.join(osp.abspath(osp.curdir), net_name +str(6*n+2))
    name = net_name+str(6*n+2)+'-cifar10'

    if n > 18:
        # warm up
        solver = Solver(solver_name="solver_warm.prototxt", folder=pt_folder, lr_policy=Solver.policy.fixed)
        solver.p.base_lr = 0.01
        solver.set_max_iter(500)
        solver.write()
        del solver
    
    solver = Solver(folder=pt_folder)
    solver.write()
    del solver

    builder = Net(name)
    builder.Data('cifar-10-batches-py/train', phase='TRAIN', crop_size=32)
    builder.Data('cifar-10-batches-py/test', phase='TEST')
    builder.resnet_cifar(n, orth=True, v2=True)
    builder.write(folder=pt_folder) 
Example 5
Project: potranslator   Author: SekouD   File: pycompat.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def relpath(path, start=curdir):
        """Return a relative version of a path"""
        from os.path import sep, abspath, commonprefix, join, pardir

        if not path:
            raise ValueError("no path specified")

        start_list = abspath(start).split(sep)
        path_list = abspath(path).split(sep)

        # Work out how much of the filepath is shared by start and path.
        i = len(commonprefix([start_list, path_list]))

        rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
        if not rel_list:
            return start
        return join(*rel_list) 
Example 6
Project: codev   Author: basecue   File: __init__.py    Apache License 2.0 5 votes vote down vote up
def project(self):
        return self.data.get('project', path.basename(path.abspath(path.curdir))) 
Example 7
Project: taker_v0   Author: taker-project   File: commands.py    GNU General Public License v3.0 5 votes vote down vote up
def command_name(self, repo, work_dir):
        result = fspath(self.relative_to(repo, work_dir))
        if path.basename(result) == result:
            result = path.join(path.curdir, result)
        return result 
Example 8
Project: taker_v0   Author: taker-project   File: commands.py    GNU General Public License v3.0 5 votes vote down vote up
def shell_str(self):
        if fspath(self.work_dir) == path.curdir:
            return '{}{}'.format(command_flags_to_str(self.flags),
                                 self._shell_str_internal())
        return '{}cd {} && {}'.format(command_flags_to_str(self.flags),
                                      shlex.quote(fspath(self.work_dir)),
                                      self._shell_str_internal()) 
Example 9
Project: taker_v0   Author: taker-project   File: test_repository.py    GNU General Public License v3.0 5 votes vote down vote up
def test_repo(tmpdir, monkeypatch):
    tmpdir = Path(str(tmpdir))
    task_dir = tmpdir / 'task'
    Path.mkdir(task_dir)

    repo = TaskRepository(Path(task_dir))
    repo.init_task()

    assert repo.relpath(Path(path.pardir) / path.curdir) == Path(path.pardir)
    assert repo.relpath(tmpdir) == Path(path.pardir)
    assert repo.abspath(Path(path.pardir) / path.curdir) == tmpdir
    assert repo.abspath(tmpdir) == tmpdir

    del repo

    with pytest.raises(TaskDirNotFoundError):
        find_task_dir()

    new_dir = task_dir / 'parent' / 'subparent'
    Path.mkdir(new_dir, parents=True)
    Path.mkdir(tmpdir / '42')
    monkeypatch.chdir(str(new_dir))

    assert find_task_dir(task_dir) == task_dir
    assert find_task_dir(new_dir) == task_dir

    repo = TaskRepository(find_task_dir())
    assert repo.directory.samefile(task_dir)
    assert (repo.relpath(task_dir.parent / '42') ==
            Path(path.pardir) / '42')
    assert (repo.abspath(Path(path.pardir) / '42') ==
            task_dir.parent / '42')

    with mock.patch('os.chdir'):
        repo.to_task_dir()
        os.chdir.assert_called_once_with(str(task_dir)) 
Example 10
Project: channel-pruning   Author: yihui-he   File: builder.py    MIT License 5 votes vote down vote up
def plain(n=3):
    """6n+2, n=3 9 18 coresponds to 20 56 110 layers"""
    net_name = "plain"
    pt_folder = osp.join(osp.abspath(osp.curdir), net_name +str(6*n+2))
    name = net_name+str(6*n+2)+'-cifar10'

    solver = Solver(folder=pt_folder)
    solver.write()
    del solver

    builder = Net(name)
    builder.Data('cifar-10-batches-py/train', phase='TRAIN', crop_size=32)
    builder.Data('cifar-10-batches-py/test', phase='TEST')
    builder.plain_cifar(n, num_output = 16)
    builder.write(folder=pt_folder) 
Example 11
Project: channel-pruning   Author: yihui-he   File: builder.py    MIT License 5 votes vote down vote up
def plain_orth(n=3):
    """6n+2, n=3 5 7 9 18 coresponds to 20 56 110 layers"""
    net_name = "plain-orth"
    pt_folder = osp.join(osp.abspath(osp.curdir), net_name +str(6*n+2))
    name = net_name+str(6*n+2)+'-cifar10'

    solver = Solver(folder=pt_folder)
    solver.write()
    del solver

    builder = Net(name)
    builder.Data('cifar-10-batches-py/train', phase='TRAIN', crop_size=32)
    builder.Data('cifar-10-batches-py/test', phase='TEST')
    builder.plain_cifar(n, orth=True)
    builder.write(folder=pt_folder) 
Example 12
Project: channel-pruning   Author: yihui-he   File: builder.py    MIT License 5 votes vote down vote up
def acc(n=3):
    """6n+2, n=3 9 18 coresponds to 20 56 110 layers"""
    net_name = "plain"
    pt_folder = osp.join(osp.abspath(osp.curdir), net_name +str(6*n+2))
    name = net_name+str(6*n+2)+'-cifar10'

    solver = Solver(folder=pt_folder)
    solver.write()
    del solver

    builder = Net(name)
    builder.Data('cifar-10-batches-py/train', phase='TRAIN', crop_size=32)
    builder.Data('cifar-10-batches-py/test', phase='TEST')
    builder.plain_cifar(n, num_output = 16, inplace=False)
    builder.write(folder=pt_folder) 
Example 13
Project: django-kaio   Author: APSL   File: options.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _conf_path(self):
        """Search .ini file from current directory (included) up to "/" (excluded)"""
        current = abspath(curdir)
        while current != "/":
            filename = join(current, DEFAULT_CONF_NAME)
            if isfile(filename):
                return filename
            current = abspath(join(current, pardir))
        # If the .ini file doesn't exist returns an empty filename so default values are used
        return '' 
Example 14
Project: django-kaio   Author: APSL   File: options.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _read_config(self):
        try:
            self.config_file = self.config.read(self._conf_path())[0]
        except IndexError:
            self.config_file = abspath(join(curdir, DEFAULT_CONF_NAME)) 
Example 15
Project: sign_language_datasets   Author: midusi   File: __init__.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def get_humans_from_dataset(dataset, path=None):
    videos_processed = {}
    outfile = osp.curdir() if path is None else path
    print('processing videos wait...')
    process_dataset(dataset, videos_processed, outfile)
    outfile = osp.join(outfile, 'positions.npz')
    np.savez(outfile, **videos_processed)
    print('the file is saved in ', outfile) 
Example 16
Project: EasyClangComplete   Author: niosus   File: tools.py    MIT License 5 votes vote down vote up
def run_command(command, shell=False, cwd=path.curdir, env=environ,
                    stdin=None, default=None):
        """Run a generic command in a subprocess.

        Args:
            command (str): command to run
            stdin: The standard input channel for the started process.
            default (andy): The default return value in case run fails.

        Returns:
            str: raw command output or default value
        """
        output_text = default
        try:
            startupinfo = None
            if sublime.platform() == "windows":
                # Don't let console window pop-up briefly.
                startupinfo = subprocess.STARTUPINFO()
                startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
                startupinfo.wShowWindow = subprocess.SW_HIDE
                if stdin is None:
                    stdin = subprocess.PIPE
            output = subprocess.check_output(command,
                                             stdin=stdin,
                                             stderr=subprocess.STDOUT,
                                             shell=shell,
                                             cwd=cwd,
                                             env=env,
                                             startupinfo=startupinfo)
            output_text = ''.join(map(chr, output))
        except subprocess.CalledProcessError as e:
            output_text = e.output.decode("utf-8")
            _log.debug("Command finished with code: %s", e.returncode)
            _log.debug("Command output: \n%s", output_text)
        except OSError:
            _log.debug(
                "Executable file not found executing: {}".format(command))
        return output_text 
Example 17
Project: calmjs   Author: calmjs   File: utils.py    GNU General Public License v2.0 4 votes vote down vote up
def which(cmd, mode=os.F_OK | os.X_OK, path=None):
    """
    Given cmd, check where it is on PATH.

    Loosely based on the version in python 3.3.
    """

    if os.path.dirname(cmd):
        if os.path.isfile(cmd) and os.access(cmd, mode):
            return cmd

    if path is None:
        path = os.environ.get('PATH', defpath)
    if not path:
        return None

    paths = path.split(pathsep)

    if sys.platform == 'win32':
        # oh boy
        if curdir not in paths:
            paths = [curdir] + paths

        # also need to check the fileexts...
        pathext = os.environ.get('PATHEXT', '').split(pathsep)

        if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
            files = [cmd]
        else:
            files = [cmd + ext for ext in pathext]
    else:
        # sanity
        files = [cmd]

    seen = set()
    for p in paths:
        normpath = normcase(p)
        if normpath in seen:
            continue
        seen.add(normpath)
        for f in files:
            fn = os.path.join(p, f)
            if os.path.isfile(fn) and os.access(fn, mode):
                return fn

    return None