##// END OF EJS Templates
update copyright to 2011/20xx-2011...
update copyright to 2011/20xx-2011 Closes #1033 (rebased to prevent recursive merge). Closes #2. 459 *.py files in : 39 empty files 176 files without copyright 36 have copyright but don't cite the dev team 208 have copyright and cite the dev team ----------------------------------------- 0 not up to date (cite dev team but not right year) FYI, list of files that don't have copyright (and are not empty..) [ 'IPython/config/profile/cluster/ipython_config.py', 'IPython/config/profile/math/ipython_config.py', 'IPython/config/profile/pylab/ipython_config.py', 'IPython/config/profile/pysh/ipython_config.py', 'IPython/config/profile/python3/ipython_config.py', 'IPython/config/profile/sympy/ipython_config.py', 'IPython/core/shadowns.py', 'IPython/core/tests/refbug.py', 'IPython/core/tests/simpleerr.py', 'IPython/core/tests/tclass.py', 'IPython/core/tests/test_application.py', 'IPython/core/tests/test_autocall.py', 'IPython/core/tests/test_completer.py', 'IPython/core/tests/test_fakemodule.py', 'IPython/core/tests/test_formatters.py', 'IPython/core/tests/test_handlers.py', 'IPython/core/tests/test_history.py', 'IPython/core/tests/test_imports.py', 'IPython/core/tests/test_iplib.py', 'IPython/core/tests/test_logger.py', 'IPython/core/tests/test_magic.py', 'IPython/core/tests/test_plugin.py', 'IPython/core/tests/test_prefilter.py', 'IPython/core/tests/test_profile.py', 'IPython/core/tests/test_run.py', 'IPython/core/tests/test_splitinput.py', 'IPython/deathrow/astyle.py', 'IPython/deathrow/dtutils.py', 'IPython/deathrow/Gnuplot2.py', 'IPython/deathrow/GnuplotInteractive.py', 'IPython/deathrow/GnuplotRuntime.py', 'IPython/deathrow/gui/wx/ipshell_nonblocking.py', 'IPython/deathrow/gui/wx/ipython_history.py', 'IPython/deathrow/gui/wx/thread_ex.py', 'IPython/deathrow/ibrowse.py', 'IPython/deathrow/igrid.py', 'IPython/deathrow/ipipe.py', 'IPython/deathrow/ipy_defaults.py', 'IPython/deathrow/ipy_kitcfg.py', 'IPython/deathrow/ipy_legacy.py', 'IPython/deathrow/ipy_p4.py', 'IPython/deathrow/ipy_profile_none.py', 'IPython/deathrow/ipy_profile_numpy.py', 'IPython/deathrow/ipy_profile_scipy.py', 'IPython/deathrow/ipy_profile_sh.py', 'IPython/deathrow/ipy_traits_completer.py', 'IPython/deathrow/ipy_vimserver.py', 'IPython/deathrow/numeric_formats.py', 'IPython/deathrow/oldfrontend/process/__init__.py', 'IPython/deathrow/oldfrontend/wx/ipythonx.py', 'IPython/deathrow/scitedirector.py', 'IPython/deathrow/tests/test_prefilter.py', 'IPython/deathrow/twshell.py', 'IPython/extensions/__init__.py', 'IPython/extensions/autoreload.py', 'IPython/extensions/storemagic.py', 'IPython/extensions/tests/test_autoreload.py', 'IPython/external/__init__.py', 'IPython/external/argparse/__init__.py', 'IPython/external/decorator/__init__.py', 'IPython/external/decorators/__init__.py', 'IPython/external/decorators/_decorators.py', 'IPython/external/decorators/_numpy_testing_noseclasses.py', 'IPython/external/decorators/_numpy_testing_utils.py', 'IPython/external/guid/__init__.py', 'IPython/external/Itpl/__init__.py', 'IPython/external/mglob/__init__.py', 'IPython/external/mglob/_mglob.py', 'IPython/external/path/__init__.py', 'IPython/external/path/_path.py', 'IPython/external/pexpect/__init__.py', 'IPython/external/pyparsing/__init__.py', 'IPython/external/qt.py', 'IPython/external/qt_for_kernel.py', 'IPython/external/simplegeneric/__init__.py', 'IPython/external/simplegeneric/_simplegeneric.py', 'IPython/frontend/html/notebook/__init__.py', 'IPython/frontend/html/notebook/tests/test_kernelsession.py', 'IPython/frontend/qt/base_frontend_mixin.py', 'IPython/frontend/qt/console/ansi_code_processor.py', 'IPython/frontend/qt/console/bracket_matcher.py', 'IPython/frontend/qt/console/call_tip_widget.py', 'IPython/frontend/qt/console/completion_lexer.py', 'IPython/frontend/qt/console/completion_widget.py', 'IPython/frontend/qt/console/console_widget.py', 'IPython/frontend/qt/console/history_console_widget.py', 'IPython/frontend/qt/console/ipython_widget.py', 'IPython/frontend/qt/console/kill_ring.py', 'IPython/frontend/qt/console/mainwindow.py', 'IPython/frontend/qt/console/pygments_highlighter.py', 'IPython/frontend/qt/console/qtconsoleapp.py', 'IPython/frontend/qt/console/rich_ipython_widget.py', 'IPython/frontend/qt/console/styles.py', 'IPython/frontend/qt/console/tests/test_ansi_code_processor.py', 'IPython/frontend/qt/console/tests/test_completion_lexer.py', 'IPython/frontend/qt/console/tests/test_kill_ring.py', 'IPython/frontend/qt/kernelmanager.py', 'IPython/frontend/qt/rich_text.py', 'IPython/frontend/qt/svg.py', 'IPython/frontend/qt/util.py', 'IPython/kernel/__init__.py', 'IPython/lib/clipboard.py', 'IPython/lib/display.py', 'IPython/lib/irunner.py', 'IPython/lib/security.py', 'IPython/lib/tests/test_imports.py', 'IPython/lib/tests/test_irunner.py', 'IPython/lib/tests/test_irunner_pylab_magic.py', 'IPython/lib/tests/test_security.py', 'IPython/nbformat/v1/tests/nbexamples.py', 'IPython/nbformat/v1/tests/test_json.py', 'IPython/nbformat/v1/tests/test_nbbase.py', 'IPython/nbformat/v2/tests/nbexamples.py', 'IPython/nbformat/v2/tests/test_json.py', 'IPython/nbformat/v2/tests/test_nbbase.py', 'IPython/nbformat/v2/tests/test_nbpy.py', 'IPython/quarantine/clearcmd.py', 'IPython/quarantine/envpersist.py', 'IPython/quarantine/ext_rescapture.py', 'IPython/quarantine/ipy_app_completers.py', 'IPython/quarantine/ipy_completers.py', 'IPython/quarantine/ipy_editors.py', 'IPython/quarantine/ipy_exportdb.py', 'IPython/quarantine/ipy_extutil.py', 'IPython/quarantine/ipy_fsops.py', 'IPython/quarantine/ipy_gnuglobal.py', 'IPython/quarantine/ipy_jot.py', 'IPython/quarantine/ipy_lookfor.py', 'IPython/quarantine/ipy_profile_doctest.py', 'IPython/quarantine/ipy_pydb.py', 'IPython/quarantine/ipy_rehashdir.py', 'IPython/quarantine/ipy_render.py', 'IPython/quarantine/ipy_server.py', 'IPython/quarantine/ipy_signals.py', 'IPython/quarantine/ipy_synchronize_with.py', 'IPython/quarantine/ipy_system_conf.py', 'IPython/quarantine/ipy_which.py', 'IPython/quarantine/ipy_winpdb.py', 'IPython/quarantine/ipy_workdir.py', 'IPython/quarantine/jobctrl.py', 'IPython/quarantine/ledit.py', 'IPython/quarantine/win32clip.py', 'IPython/testing/mkdoctests.py', 'IPython/testing/plugin/dtexample.py', 'IPython/testing/plugin/ipdoctest.py', 'IPython/testing/plugin/iptest.py', 'IPython/testing/plugin/setup.py', 'IPython/testing/plugin/show_refs.py', 'IPython/testing/plugin/simple.py', 'IPython/testing/plugin/simplevars.py', 'IPython/testing/plugin/test_ipdoctest.py', 'IPython/testing/plugin/test_refs.py', 'IPython/testing/skipdoctest.py', 'IPython/testing/tests/test_decorators.py', 'IPython/utils/autoattr.py', 'IPython/utils/nested_context.py', 'IPython/utils/pickleshare.py', 'IPython/utils/py3compat.py', 'IPython/utils/PyColorize.py', 'IPython/utils/rlineimpl.py', 'IPython/utils/strdispatch.py', 'IPython/utils/tempdir.py', 'IPython/utils/tests/test_imports.py', 'IPython/utils/tests/test_wildcard.py', 'IPython/utils/upgradedir.py', 'IPython/zmq/completer.py', 'IPython/zmq/displayhook.py', 'IPython/zmq/entry_point.py', 'IPython/zmq/frontend.py', 'IPython/zmq/iostream.py', 'IPython/zmq/ipkernel.py', 'IPython/zmq/log.py', 'IPython/zmq/parentpoller.py', 'IPython/zmq/pykernel.py', 'IPython/zmq/pylab/backend_inline.py', 'IPython/zmq/zmqshell.py' ]

File last commit:

r4872:34c10438
r5390:c82649ea
Show More
ipy_fsops.py
245 lines | 6.3 KiB | text/x-python | PythonLexer
vivainio
crlf normalization
r851 """ File system operations
Contains: Simple variants of normal unix shell commands (icp, imv, irm,
imkdir, igrep).
Some "otherwise handy" utils ('collect' for gathering files to
~/_ipython/collect, 'inote' for collecting single note lines to
~/_ipython/note.txt)
Mostly of use for bare windows installations where cygwin/equivalent is not
installed and you would otherwise need to deal with dos versions of the
commands (that e.g. don't understand / as path separator). These can
do some useful tricks on their own, though (like use 'mglob' patterns).
Not to be confused with ipipe commands (ils etc.) that also start with i.
"""
Brian Granger
ipapi.py => core/ipapi.py and imports updated.
r2027 from IPython.core import ipapi
Brian Granger
Continuing a massive refactor of everything.
r2205 from IPython.core.error import TryNext
Brian Granger
ipapi.py => core/ipapi.py and imports updated.
r2027 ip = ipapi.get()
vivainio
crlf normalization
r851
import shutil,os,shlex
from IPython.external import mglob
vivainio
move path to external
r964 from IPython.external.path import path
Brian Granger
Continuing a massive refactor of everything.
r2205 from IPython.core.error import UsageError
Brian Granger
generics.py => utils/generics.py
r2022 import IPython.utils.generics
vivainio
crlf normalization
r851
def parse_args(args):
""" Given arg string 'CMD files... target', return ([files], target) """
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 tup = args.split(None, 1)
if len(tup) == 1:
vivainio
sprinkle around more UsageErrors, icp now works when src paths are directories
r860 raise UsageError("Expected arguments for " + tup[0])
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 tup2 = shlex.split(tup[1])
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 flist, trg = mglob.expand(tup2[0:-1]), tup2[-1]
if not flist:
vivainio
sprinkle around more UsageErrors, icp now works when src paths are directories
r860 raise UsageError("No files found:" + str(tup2[0:-1]))
vivainio
crlf normalization
r851 return flist, trg
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 def icp(ip,arg):
""" icp files... targetdir
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 Copy all files to target, creating dirs for target if necessary
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 icp srcdir dstdir
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 Copy srcdir to distdir
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 """
import distutils.dir_util
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 fs, targetdir = parse_args(arg)
vivainio
sprinkle around more UsageErrors, icp now works when src paths are directories
r860 if not os.path.isdir(targetdir) and len(fs) > 1:
vivainio
crlf normalization
r851 distutils.dir_util.mkpath(targetdir,verbose =1)
for f in fs:
vivainio
sprinkle around more UsageErrors, icp now works when src paths are directories
r860 if os.path.isdir(f):
shutil.copytree(f, targetdir)
else:
shutil.copy2(f,targetdir)
vivainio
crlf normalization
r851 return fs
Brian Granger
Continuing a massive refactor of everything.
r2205 ip.define_alias("icp",icp)
vivainio
crlf normalization
r851
def imv(ip,arg):
""" imv src tgt
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 Move source to target.
"""
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 fs, target = parse_args(arg)
if len(fs) > 1:
assert os.path.isdir(target)
Bernardo B. Marques
remove all trailling spaces
r4872 for f in fs:
vivainio
crlf normalization
r851 shutil.move(f, target)
return fs
Bernardo B. Marques
remove all trailling spaces
r4872 ip.define_alias("imv",imv)
vivainio
crlf normalization
r851
def irm(ip,arg):
""" irm path[s]...
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 Remove file[s] or dir[s] path. Dirs are deleted recursively.
"""
vivainio
sprinkle around more UsageErrors, icp now works when src paths are directories
r860 try:
paths = mglob.expand(arg.split(None,1)[1])
except IndexError:
raise UsageError("%irm paths...")
vivainio
crlf normalization
r851 import distutils.dir_util
for p in paths:
print "rm",p
if os.path.isdir(p):
distutils.dir_util.remove_tree(p, verbose = 1)
else:
os.remove(p)
Brian Granger
Continuing a massive refactor of everything.
r2205 ip.define_alias("irm",irm)
vivainio
crlf normalization
r851
def imkdir(ip,arg):
""" imkdir path
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 Creates dir path, and all dirs on the road
"""
import distutils.dir_util
targetdir = arg.split(None,1)[1]
Bernardo B. Marques
remove all trailling spaces
r4872 distutils.dir_util.mkpath(targetdir,verbose =1)
vivainio
crlf normalization
r851
Bernardo B. Marques
remove all trailling spaces
r4872 ip.define_alias("imkdir",imkdir)
vivainio
crlf normalization
r851
def igrep(ip,arg):
""" igrep PAT files...
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 Very dumb file scan, case-insensitive.
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 e.g.
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 igrep "test this" rec:*.py
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 """
elems = shlex.split(arg)
dummy, pat, fs = elems[0], elems[1], mglob.expand(elems[2:])
res = []
for f in fs:
found = False
for l in open(f):
if pat.lower() in l.lower():
if not found:
print "[[",f,"]]"
found = True
res.append(f)
print l.rstrip()
return res
Bernardo B. Marques
remove all trailling spaces
r4872 ip.define_alias("igrep",igrep)
vivainio
crlf normalization
r851
def collect(ip,arg):
""" collect foo/a.txt rec:bar=*.py
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 Copies foo/a.txt to ~/_ipython/collect/foo/a.txt and *.py from bar,
likewise
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 Without args, try to open ~/_ipython/collect dir (in win32 at least).
"""
vivainio
move path to external
r964 from IPython.external.path import path
Brian Granger
Lots of work on command line options and env vars....
r2322 basedir = path(ip.ipython_dir + '/collect')
Bernardo B. Marques
remove all trailling spaces
r4872 try:
vivainio
crlf normalization
r851 fs = mglob.expand(arg.split(None,1)[1])
except IndexError:
os.startfile(basedir)
return
for f in fs:
f = path(f)
trg = basedir / f.splitdrive()[1].lstrip('/\\')
if f.isdir():
print "mkdir",trg
trg.makedirs()
continue
dname = trg.dirname()
if not dname.isdir():
dname.makedirs()
print f,"=>",trg
shutil.copy2(f,trg)
Bernardo B. Marques
remove all trailling spaces
r4872 ip.define_alias("collect",collect)
vivainio
crlf normalization
r851
def inote(ip,arg):
""" inote Hello world
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 Adds timestamp and Hello world to ~/_ipython/notes.txt
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 Without args, opens notes.txt for editing.
"""
import time
Brian Granger
Lots of work on command line options and env vars....
r2322 fname = ip.ipython_dir + '/notes.txt'
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf normalization
r851 try:
entry = " === " + time.asctime() + ': ===\n' + arg.split(None,1)[1] + '\n'
Bernardo B. Marques
remove all trailling spaces
r4872 f= open(fname, 'a').write(entry)
vivainio
crlf normalization
r851 except IndexError:
Bernardo B. Marques
remove all trailling spaces
r4872 ip.hooks.editor(fname)
vivainio
crlf normalization
r851
Brian Granger
Continuing a massive refactor of everything.
r2205 ip.define_alias("inote",inote)
vivainio
Add PathObj and FileObj to ipy_fsops.py
r912
def pathobj_mangle(p):
return p.replace(' ', '__').replace('.','DOT')
def pathobj_unmangle(s):
return s.replace('__',' ').replace('DOT','.')
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
ipy_fsops: inherit pathobj from path
r915 class PathObj(path):
vivainio
Add PathObj and FileObj to ipy_fsops.py
r912 def __init__(self,p):
self.path = p
vivainio
ipy_fsops: remove FileObj (use normal 'path' objs instead), support for cwd (.) path obj
r914 if p != '.':
self.ents = [pathobj_mangle(ent) for ent in os.listdir(p)]
else:
vivainio
Add PathObj and FileObj to ipy_fsops.py
r912 self.ents = None
def __complete__(self):
vivainio
ipy_fsops: remove FileObj (use normal 'path' objs instead), support for cwd (.) path obj
r914 if self.path != '.':
vivainio
Add PathObj and FileObj to ipy_fsops.py
r912 return self.ents
vivainio
ipy_fsops: remove FileObj (use normal 'path' objs instead), support for cwd (.) path obj
r914 self.ents = [pathobj_mangle(ent) for ent in os.listdir('.')]
return self.ents
vivainio
Add PathObj and FileObj to ipy_fsops.py
r912 def __getattr__(self,name):
if name in self.ents:
if self.path.endswith('/'):
sep = ''
else:
sep = '/'
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
Add PathObj and FileObj to ipy_fsops.py
r912 tgt = self.path + sep + pathobj_unmangle(name)
#print "tgt",tgt
if os.path.isdir(tgt):
return PathObj(tgt)
if os.path.isfile(tgt):
vivainio
ipy_fsops: remove FileObj (use normal 'path' objs instead), support for cwd (.) path obj
r914 return path(tgt)
vivainio
Add PathObj and FileObj to ipy_fsops.py
r912
raise AttributeError, name # <<< DON'T FORGET THIS LINE !!
def __str__(self):
return self.path
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
Add PathObj and FileObj to ipy_fsops.py
r912 def __repr__(self):
return "<PathObj to %s>" % self.path
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
Add PathObj and FileObj to ipy_fsops.py
r912 def __call__(self):
print "cd:",self.path
os.chdir(self.path)
Bernardo B. Marques
remove all trailling spaces
r4872
def complete_pathobj(obj, prev_completions):
vivainio
Add PathObj and FileObj to ipy_fsops.py
r912 if hasattr(obj,'__complete__'):
vivainio
ipy_fsops: inherit pathobj from path
r915 res = obj.__complete__()
if res:
return res
# just return normal attributes of 'path' object if the dir is empty
Brian Granger
Continuing a massive refactor of everything.
r2205 raise TryNext
vivainio
Add PathObj and FileObj to ipy_fsops.py
r912
Brian Granger
generics.py => utils/generics.py
r2022 complete_pathobj = IPython.utils.generics.complete_object.when_type(PathObj)(complete_pathobj)
vivainio
Add PathObj and FileObj to ipy_fsops.py
r912
def test_pathobj():
#p = PathObj('c:/prj')
#p2 = p.cgi
#print p,p2
vivainio
ipy_fsops: inherit pathobj from path
r915 rootdir = PathObj("/")
vivainio
Add PathObj and FileObj to ipy_fsops.py
r912 startmenu = PathObj("d:/Documents and Settings/All Users/Start Menu/Programs")
vivainio
ipy_fsops: remove FileObj (use normal 'path' objs instead), support for cwd (.) path obj
r914 cwd = PathObj('.')
Brian Granger
Continuing a massive refactor of everything.
r2205 ip.push("rootdir startmenu cwd")
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
Add PathObj and FileObj to ipy_fsops.py
r912 #test_pathobj()