Пример #1
0
 def system(self, cmd):
     if self.background:
         try:
             proc = Popen(cmd, shell=True, executable=self.shell[0],
                          close_fds=True, preexec_fn=os.setsid, stdout=PIPE, stderr=PIPE)
             message.puts("Spawn: {0} ({1})".format(cmd.strip(), proc.pid))
             ProcessNotify(proc, cmd).start()
         except Exception as e:
             message.exception(e)
     else:
         try:
             widget.end_curses()
             os.system("clear")
             proc = Popen(cmd, shell=True, executable=self.shell[0],
                          close_fds=True, preexec_fn=os.setsid)
             proc.wait()
             if not self.quick:
                 util.wait_restore()
             message.puts("Spawn: {0} ({1})".format(cmd.strip(), proc.pid))
         except KeyboardInterrupt as e:
             message.error("KeyboardInterrupt: {0}".format(cmd))
         except Exception as e:
             message.exception(e)
         finally:
             widget.start_curses()
Пример #2
0
 def terminal(self, cmd):
     command = []
     command.extend(self.terminal_emulator)
     command.append(cmd)
     proc = Popen(command, stdout=PIPE, stderr=PIPE)
     message.puts("Spawn: {0} ({1})".format(cmd.strip(), self.terminal_emulator[0]))
     ProcessNotify(proc, cmd).start()
Пример #3
0
 def zipeach(self, src, dst, wrap):
     threadlist = []
     for f in src:
         path = os.path.join(dst, util.unix_basename(f))
         threadlist.append(ZipThread(f, path, wrap))
     for t in threadlist:
         self.thread_loop(t)
     message.puts("Finished 'zipeach'")
Пример #4
0
def link(src, dst):
    try:
        if os.path.isdir(dst):
            dst = os.path.join(dst, util.unix_basename(src))
        os.link(src, dst)
        message.puts("Created hard links: {0} -> {1}".format(src, dst))
    except Exception as e:
        message.exception(e)
Пример #5
0
 def tareach(self, src, dst, tarmode="gzip", wrap=""):
     threadlist = []
     for f in src:
         path = os.path.join(dst, util.unix_basename(f))
         threadlist.append(TarThread(f, path, tarmode, wrap))
     for t in threadlist:
         self.thread_loop(t)
     message.puts("Finished 'tareach'")
Пример #6
0
def _reload_rcfile():
    """Reload Pyful.environs["RCFILE"]"""
    try:
        path = Pyful.environs["RCFILE"]
        util.loadfile(path)
        message.puts("Reloaded: {0}".format(path))
    except Exception as e:
        message.exception(e)
Пример #7
0
 def run(self):
     with self.lock:
         try:
             self.main()
             message.puts("Finished: {0}".format(self.title))
         except FilectrlCancel as e:
             message.exception(e)
         finally:
             Filectrl.threads.remove(self)
Пример #8
0
 def notify_output(self, out):
     for line in out.splitlines():
         if not line:
             continue
         try:
             line = line.decode()
             message.puts("{0} - ({1})".format(line, self.name))
         except UnicodeError:
             line = "????? - Invalid encoding"
             message.error("{0} - ({1})".format(line, self.name))
Пример #9
0
def rename(src, dst):
    if os.path.exists(dst) and os.path.samefile(src, dst):
        return
    if os.path.exists(dst):
        ret = message.confirm(
            "{0}; Override? {{{1} -> {2}}}".format(os.strerror(errno.EEXIST), src, dst),
            ["Yes", "No", "Cancel"])
        if "Yes" != ret:
            return
    try:
        os.renames(src, dst)
        message.puts("Renamed: {0} -> {1}".format(src, dst))
    except Exception as e:
        message.exception(e)
Пример #10
0
 def python(self, cmd):
     cmd = self.parsemacro(cmd)
     try:
         widget.end_curses()
         os.system("clear")
         exec(cmd)
         if not self.quick:
             util.wait_restore()
         message.puts("Eval: {0}".format(cmd))
     except KeyboardInterrupt as e:
         message.error("KeyboardInterrupt: {0}".format(cmd))
     except Exception as e:
         message.exception(e)
     finally:
         widget.start_curses()
Пример #11
0
def chown(path, uid, gid):
    if not isinstance(uid, int):
        try:
            uid = pwd.getpwnam(uid)[2]
        except KeyError as e:
            message.exception(e)
            return
    if not isinstance(gid, int):
        try:
            gid = grp.getgrnam(gid)[2]
        except KeyError as e:
            message.exception(e)
            return
    try:
        os.chown(path, uid, gid)
        message.puts("Changed owner: {0}: uid -> {1}, gid -> {2}".format(path, uid, gid))
    except Exception as e:
        message.exception(e)
Пример #12
0
def replace(pattern, repstr):
    filer = widgets.filer
    files = filer.dir.get_mark_files()
    renamed = [pattern.sub(r""+repstr, f) for f in files]
    msg = []
    matched = []
    for i in range(0, len(files)):
        if files[i] != renamed[i]:
            msg.append("{0} -> {1}".format(files[i], renamed[i]))
            matched.append((files[i], renamed[i]))
    if not matched:
        return message.error("No pattern matched for mark files: {0} ".format(pattern.pattern))
    if "Start" != message.confirm("Replace:", ["Start", "Cancel"], msg):
        return

    ret = ""
    for member in matched:
        src, dst = member
        if os.path.exists(os.path.join(filer.dir.path, dst)):
            if ret == "No(all)":
                continue
            if ret != "Yes(all)":
                ret = message.confirm(
                    "{0}; Override? {{{1} -> {2}}}".format(os.strerror(errno.EEXIST), src, dst),
                    ["Yes", "No", "Yes(all)", "No(all)", "Cancel"])
                if ret == "Yes" or ret == "Yes(all)":
                    pass
                elif ret == "No" or ret == "No(all)":
                    continue
                elif ret is None or ret == "Cancel":
                    break
        try:
            os.renames(src, dst)
            message.puts("Renamed: {0} -> {1}".format(src, dst))
        except Exception as e:
            message.exception(e)
            break
    filer.dir.mark_clear()
Пример #13
0
 def screen(self, cmd, title):
     if not self.quick:
         cmd = "{0}; {1} -e".format(cmd, sys.argv[0])
     command = [arg.format(TITLE=title, COMMAND=cmd) for arg in self.screen_command]
     Popen(command)
     message.puts("Spawn: {0} (screen)".format(cmd.strip()))
Пример #14
0
def mknod(path, mode=0o644):
    try:
        os.mknod(path, mode)
        message.puts("Created file: {0} ({1:#o})".format(path, mode))
    except Exception as e:
        message.exception(e)
Пример #15
0
def mkdir(path, mode=0o755):
    try:
        os.makedirs(path, mode)
        message.puts("Created directory: {0} ({1:#o})".format(path, mode))
    except Exception as e:
        message.exception(e)
Пример #16
0
def chmod(path, mode):
    try:
        os.chmod(path, int(mode, 8))
        message.puts("Changed mode: {0} -> {1}".format(path, mode))
    except Exception as e:
        message.exception(e)
Пример #17
0
 def notify(self, notice):
     message.puts(notice)