home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import IPython.ipapi as IPython
- ip = IPython.ipapi.get()
- import shutil
- import os
- import shlex
- from IPython.external import mglob
- from IPython.external.path import path
- from IPython.ipapi import UsageError
-
- def parse_args(args):
- tup = args.split(None, 1)
- if len(tup) == 1:
- raise UsageError('Expected arguments for ' + tup[0])
- len(tup) == 1
- tup2 = shlex.split(tup[1])
- flist = mglob.expand(tup2[0:-1])
- trg = tup2[-1]
- if not flist:
- raise UsageError('No files found:' + str(tup2[0:-1]))
- flist
- return (flist, trg)
-
-
- def icp(ip, arg):
- import distutils.dir_util as distutils
- (fs, targetdir) = parse_args(arg)
- if not os.path.isdir(targetdir) and len(fs) > 1:
- distutils.dir_util.mkpath(targetdir, verbose = 1)
-
- for f in fs:
- if os.path.isdir(f):
- shutil.copytree(f, targetdir)
- continue
- shutil.copy2(f, targetdir)
-
- return fs
-
- ip.defalias('icp', icp)
-
- def imv(ip, arg):
- (fs, target) = parse_args(arg)
- if len(fs) > 1:
- pass
-
- for f in fs:
- shutil.move(f, target)
-
- return fs
-
- ip.defalias('imv', imv)
-
- def irm(ip, arg):
-
- try:
- paths = mglob.expand(arg.split(None, 1)[1])
- except IndexError:
- raise UsageError('%irm paths...')
-
- import distutils.dir_util as distutils
- for p in paths:
- print 'rm', p
- if os.path.isdir(p):
- distutils.dir_util.remove_tree(p, verbose = 1)
- continue
- os.remove(p)
-
-
- ip.defalias('irm', irm)
-
- def imkdir(ip, arg):
- import distutils.dir_util as distutils
- targetdir = arg.split(None, 1)[1]
- distutils.dir_util.mkpath(targetdir, verbose = 1)
-
- ip.defalias('imkdir', imkdir)
-
- def igrep(ip, arg):
- elems = shlex.split(arg)
- dummy = elems[0]
- pat = elems[1]
- fs = 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()
- continue
-
-
- return res
-
- ip.defalias('igrep', igrep)
-
- def collect(ip, arg):
- path = path
- import IPython.external.path
- basedir = path(ip.options.ipythondir + '/collect')
-
- try:
- fs = mglob.expand(arg.split(None, 1)[1])
- except IndexError:
- os.startfile(basedir)
- return None
-
- 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)
-
-
- ip.defalias('collect', collect)
-
- def inote(ip, arg):
- import time
- fname = ip.options.ipythondir + '/notes.txt'
-
- try:
- entry = ' === ' + time.asctime() + ': ===\n' + arg.split(None, 1)[1] + '\n'
- f = open(fname, 'a').write(entry)
- except IndexError:
- ip.IP.hooks.editor(fname)
-
-
- ip.defalias('inote', inote)
-
- def pathobj_mangle(p):
- return p.replace(' ', '__').replace('.', 'DOT')
-
-
- def pathobj_unmangle(s):
- return s.replace('__', ' ').replace('DOT', '.')
-
-
- class PathObj(path):
-
- def __init__(self, p):
- self.path = p
-
-
- def __complete__(self):
- if self.path != '.':
- return self.ents
- self.ents = [ pathobj_mangle(ent) for ent in os.listdir('.') ]
- return self.ents
-
-
- def __getattr__(self, name):
- raise AttributeError, name
-
-
- def __str__(self):
- return self.path
-
-
- def __repr__(self):
- return '<PathObj to %s>' % self.path
-
-
- def __call__(self):
- print 'cd:', self.path
- os.chdir(self.path)
-
-
-
- def complete_pathobj(obj, prev_completions):
- if hasattr(obj, '__complete__'):
- res = obj.__complete__()
- if res:
- return res
-
- raise IPython.ipapi.TryNext
-
- complete_pathobj = IPython.generics.complete_object.when_type(PathObj)(complete_pathobj)
-
- def test_pathobj():
- rootdir = PathObj('/')
- startmenu = PathObj('d:/Documents and Settings/All Users/Start Menu/Programs')
- cwd = PathObj('.')
- ip.to_user_ns('rootdir startmenu cwd')
-
-