Table of Content

When you cannot install ipython , there is alternative way to write key ipython as module or package:

– TAB completion
– basic shell command (pwd,ls,cd,mkdir,cp,mv, you can add more ……)


util.py
-------

import os,sys,shutil
import rlcompleter, readline

def rl():
    readline.parse_and_bind('tab: complete')

def pwd(parameter_s=''):
    return os.getcwdu()

def ls(line=''):
    if line == '': dirs = [os.curdir]
    else: dirs = line.split()
    for dirname in dirs:
            print 'Listing of %s:' % dirname
            print '\n'.join(os.listdir(dirname))

def cd(dirname=''):
    # 'cd' by itself means 'go home'.
    if dirname == '': dirname = os.environ['HOME']
    os.chdir(dirname)

def mkdir(dirname):
    os.mkdir(dirname)

def cp(line):
    words = line.split()
    sourcefiles,target = words[:-1], words[-1] # target could be a dir
    for sourcefile in sourcefiles:
        shutil.copy(sourcefile, target)

def mv(line):
     source, target = line.split()
     os.rename(source, target)

def rm(line):
    [os.remove(arg) for arg in line.split()]