예제 #1
0
def run_dir(d):
    d = d.split("/")
    d = "/".join(d[:-1])
    print(d)
    posix.chdir(d)
    run()
    posix.chdir(_O.dirini)
예제 #2
0
def Cd(argv, mem, dir_stack):
    arg, i = CD_SPEC.Parse(argv)
    # TODO: error checking, etc.
    # TODO: ensure that if multiple flags are provided, the *last* one overrides
    # the others.

    try:
        dest_dir = argv[i]
    except IndexError:
        val = mem.GetVar('HOME')
        if val.tag == value_e.Undef:
            util.error("$HOME isn't defined")
            return 1
        elif val.tag == value_e.Str:
            dest_dir = val.s
        elif val.tag == value_e.StrArray:
            util.error("$HOME shouldn't be an array.")
            return 1

    if dest_dir == '-':
        old = mem.GetVar('OLDPWD', scope_e.GlobalOnly)
        if old.tag == value_e.Undef:
            log('OLDPWD not set')
            return 1
        elif old.tag == value_e.Str:
            dest_dir = old.s
            print(dest_dir)  # Shells print the directory
        elif old.tag == value_e.StrArray:
            # TODO: Prevent the user from setting OLDPWD to array (or maybe they
            # can't even set it at all.)
            raise AssertionError('Invalid OLDPWD')

    pwd = mem.GetVar('PWD')
    assert pwd.tag == value_e.Str, pwd  # TODO: Need a general scheme to avoid

    # Calculate new directory, chdir() to it, then set PWD to it.  NOTE: We can't
    # call posix.getcwd() because it can raise OSError if the directory was
    # removed (ENOENT.)
    abspath = os_path.join(pwd.s, dest_dir)  # make it absolute, for cd ..
    if arg.P:
        # -P means resolve symbolic links, then process '..'
        real_dest_dir = libc.realpath(abspath)
    else:
        # -L means process '..' first.  This just does string manipulation.  (But
        # realpath afterward isn't correct?)
        real_dest_dir = os_path.normpath(abspath)

    try:
        posix.chdir(real_dest_dir)
    except OSError as e:
        # TODO: Add line number, etc.
        util.error("cd %r: %s", real_dest_dir, posix.strerror(e.errno))
        return 1

    state.ExportGlobalString(mem, 'OLDPWD', pwd.s)
    state.ExportGlobalString(mem, 'PWD', real_dest_dir)
    dir_stack.Reset()  # for pushd/popd/dirs
    return 0
예제 #3
0
파일: sunny.py 프로젝트: ooici/ape
 def start_nodes(self):
     """ invoke cloudinitd to start nodes """
     if self.state!=CONFIGURED:
         raise ApeException('cannot start nodes when troop state is ' + self.state)
     chdir(self.target_directory)
     try:
         cloudinitd(argv=['boot', 'troop-launch.conf', '-n', self.launch_name])
         self.state=RUNNING
     except:
         self.state=FAILED
예제 #4
0
def split_passages():
    chdir('passages')
    passages = glob('*.xml')
    for split in 'train', 'dev', 'test':
        if not path.exists(split):
            mkdir(split)
    for f in passages[:TRAIN_SIZE]:
        rename(f, 'train/'+f)
    for f in passages[TRAIN_SIZE:TRAIN_SIZE+DEV_SIZE]:
        rename(f, 'dev/'+f)
    for f in passages[TRAIN_SIZE+DEV_SIZE:]:
        rename(f, 'test/'+f)
예제 #5
0
def user_apply(uid, root, f, args):

    pid = os.fork()
    if (pid == 0):
        posix.chdir(root)
        posixmodule.chroot(root)
        posix.setuid(uid)
        apply(f, args)
        os._exit(0)
    pid, status = os.waitpid(pid, 0)
    if (status != 0):
        raise ValueError, 'command %s (%s) returned error status %s' % (
            f, str(args), str(ret))
예제 #6
0
파일: builtin.py 프로젝트: gnprice/oil
def Popd(argv, home_dir, dir_stack):
    dest_dir = dir_stack.Pop()
    if dest_dir is None:
        util.error('popd: directory stack is empty')
        return 1

    try:
        posix.chdir(dest_dir)
    except OSError as e:
        util.error("popd: %r: %s", dest_dir, posix.strerror(e.errno))
        return 1

    _PrintDirStack(dir_stack, SINGLE_LINE, home_dir)
    return 0
예제 #7
0
def Popd(argv, mem, dir_stack):
    dest_dir = dir_stack.Pop()
    if dest_dir is None:
        util.error('popd: directory stack is empty')
        return 1

    try:
        posix.chdir(dest_dir)
    except OSError as e:
        util.error("popd: %r: %s", dest_dir, posix.strerror(e.errno))
        return 1

    _PrintDirStack(dir_stack, SINGLE_LINE, mem.GetVar('HOME'))
    state.SetGlobalString(mem, 'PWD', dest_dir)
    return 0
예제 #8
0
def doenvuser(cmd, argv, env, uid, root, dry_run, verbose, prefix=''):
    if (verbose):
        print prefix + string.join(argv, ' ')
    if (dry_run):
        return
    pid = os.fork()
    if (pid == 0):
        posix.chdir(root)
        posixmodule.chroot(root)
        posix.setuid(uid)
        os.execve(prog, argv, env)
    pid, status = os.waitpid(pid, 0)
    if (status != 0):
        raise ValueError, 'command %s returned error status %s' % (string.join(
            argv, ' '), str(ret))
예제 #9
0
파일: builtin.py 프로젝트: gnprice/oil
def Pushd(argv, home_dir, dir_stack):
    num_args = len(argv)
    if num_args <= 0:
        util.error('pushd: no other directory')
        return 1
    elif num_args > 1:
        util.error('pushd: too many arguments')
        return 1

    dest_dir = os_path.abspath(argv[0])
    try:
        posix.chdir(dest_dir)
    except OSError as e:
        util.error("pushd: %r: %s", dest_dir, posix.strerror(e.errno))
        return 1

    dir_stack.Push(dest_dir)
    _PrintDirStack(dir_stack, SINGLE_LINE, home_dir)
    return 0
예제 #10
0
 def test_chdir(self):
     if hasattr(posix, 'chdir'):
         posix.chdir(os.curdir)
         self.assertRaises(OSError, posix.chdir, test_support.TESTFN)
예제 #11
0
파일: sunny.py 프로젝트: ooici/ape
 def stop_nodes(self):
     """ invoke cloudinitd to stop all nodes """
     if self.state!=RUNNING and self.state!=FAILED:
         raise ApeException('cannot stop nodes when troop state is ' + self.state)
     chdir(self.target_directory)
     cloudinitd(argv=['terminate', self.launch_name])