externing.py (pymol-v1.8.6.0.tar.bz2) | : | externing.py (pymol-v2.1.0.tar.bz2) | ||
---|---|---|---|---|
skipping to change at line 32 | skipping to change at line 32 | |||
from . import parsing | from . import parsing | |||
import threading | import threading | |||
cmd = __import__("sys").modules["pymol.cmd"] | cmd = __import__("sys").modules["pymol.cmd"] | |||
import traceback | import traceback | |||
from glob import glob | from glob import glob | |||
from .cmd import _cmd,lock,unlock,Shortcut,QuietException, \ | from .cmd import _cmd,lock,unlock,Shortcut,QuietException, \ | |||
_feedback,fb_module,fb_mask, exp_path, \ | _feedback,fb_module,fb_mask, exp_path, \ | |||
DEFAULT_ERROR, DEFAULT_SUCCESS, _raising, is_ok, is_error | DEFAULT_ERROR, DEFAULT_SUCCESS, _raising, is_ok, is_error | |||
try: | ||||
from os import getcwdu | ||||
except ImportError: | ||||
from os import getcwd as getcwdu | ||||
def cd(dir="~",complain=1,quiet=1): | def cd(dir="~",complain=1,quiet=1): | |||
''' | ''' | |||
DESCRIPTION | DESCRIPTION | |||
"cd" changes the current working directory. | "cd" changes the current working directory. | |||
USAGE | USAGE | |||
cd <path> | cd <path> | |||
SEE ALSO | SEE ALSO | |||
pwd, ls, system | pwd, ls, system | |||
''' | ''' | |||
dir = exp_path(dir) | dir = exp_path(dir) | |||
try: | try: | |||
os.chdir(dir) # raises on error | os.chdir(dir) # raises on error | |||
if not quiet: | if not quiet: | |||
print(" cd: now in %s"%os.getcwd()) | print(" cd: now in %s" % getcwdu()) | |||
except: | except: | |||
if complain: | if complain: | |||
traceback.print_exc() | traceback.print_exc() | |||
return DEFAULT_SUCCESS | return DEFAULT_SUCCESS | |||
def pwd(): | def pwd(): | |||
''' | ''' | |||
DESCRIPTION | DESCRIPTION | |||
Print current working directory. | Print current working directory. | |||
USAGE | USAGE | |||
pwd | pwd | |||
SEE ALSO | SEE ALSO | |||
cd, ls, system | cd, ls, system | |||
''' | ''' | |||
print(os.getcwd()) | print(getcwdu()) | |||
return DEFAULT_SUCCESS | return DEFAULT_SUCCESS | |||
def ls(pattern=None): | def ls(pattern=None): | |||
''' | ''' | |||
DESCRIPTION | DESCRIPTION | |||
List contents of the current working directory. | List contents of the current working directory. | |||
USAGE | USAGE | |||
skipping to change at line 94 | skipping to change at line 99 | |||
EXAMPLES | EXAMPLES | |||
ls | ls | |||
ls *.pml | ls *.pml | |||
SEE ALSO | SEE ALSO | |||
cd, pwd, system | cd, pwd, system | |||
''' | ''' | |||
if pattern==None: | if pattern==None: | |||
pattern = "*" | pattern = u"*" | |||
else: | else: | |||
pattern = exp_path(pattern) | pattern = exp_path(pattern) | |||
if '*' not in pattern: | if '*' not in pattern: | |||
lst = glob(os.path.join(pattern, '*')) | lst = glob(os.path.join(pattern, '*')) | |||
else: | else: | |||
lst = [] | lst = [] | |||
if not len(lst): | if not len(lst): | |||
lst = glob(pattern) | lst = glob(pattern) | |||
if len(lst): | if len(lst): | |||
lst.sort() | lst.sort() | |||
lst = parsing.list_to_str_list(lst) | lst = parsing.list_to_str_list(lst) | |||
for a in lst: | for a in lst: | |||
print(a) | print(a) | |||
else: | else: | |||
print(" ls: Nothing found. Is that a valid path?") | print(" ls: Nothing found. Is that a valid path?") | |||
return DEFAULT_SUCCESS | return DEFAULT_SUCCESS | |||
def system(command,async=0,_self=cmd): | def system(command, async_=0, _self=cmd, **kwargs): | |||
''' | ''' | |||
DESCRIPTION | DESCRIPTION | |||
"system" executes a command in a subshell under Unix or Windows. | "system" executes a command in a subshell under Unix or Windows. | |||
USAGE | USAGE | |||
system command | system command | |||
PYMOL API | PYMOL API | |||
skipping to change at line 139 | skipping to change at line 144 | |||
if async is 0 (default), then the result code from "system" is returned in r | if async is 0 (default), then the result code from "system" is returned in r | |||
if async is 1, then the command is run in a separate thread whose object is | if async is 1, then the command is run in a separate thread whose object is | |||
returned | returned | |||
SEE ALSO | SEE ALSO | |||
ls, cd, pwd | ls, cd, pwd | |||
''' | ''' | |||
async_ = int(kwargs.pop('async', async_)) | ||||
if kwargs: | ||||
raise pymol.CmdException('unknown argument: ' + ', '.join(kwargs)) | ||||
r = None | r = None | |||
if async: | if async_: | |||
r = threading.Thread(target=_cmd.system,args=(str(command),1)) | r = threading.Thread(target=_cmd.system,args=(str(command),1)) | |||
r.start() | r.start() | |||
else: | else: | |||
r = _cmd.system(_self._COb,str(command),0) | r = _cmd.system(_self._COb,str(command),0) | |||
return r # special meaning | return r # special meaning | |||
def paste(_self=cmd): # INTERNAL | def paste(_self=cmd): # INTERNAL | |||
r=DEFAULT_SUCCESS | r=DEFAULT_SUCCESS | |||
lst = [] | lst = [] | |||
if hasattr(pymol,"machine_get_clipboard"): | if hasattr(pymol,"machine_get_clipboard"): | |||
End of changes. 7 change blocks. | ||||
5 lines changed or deleted | 15 lines changed or added |