doc/book/mode_plan.py
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Tue, 27 Jan 2009 18:46:49 +0100
changeset 485 0f830732be19
parent 127 ae611743f5c6
child 1977 606923dff11b
permissions -rw-r--r--
[tabs] provide a working tabs implementation, that lazy-loads tab content & should remember the current position
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
127
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     1
"""
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     2
>>> from mode_plan import *
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     3
>>> ls()
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     4
<list of directory content>
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     5
>>> ren('A01','A03')
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     6
rename A010-joe.en.txt to A030-joe.en.txt
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     7
accept [y/N]?
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     8
"""
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     9
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    10
def ren(a,b):
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    11
    names = glob.glob('%s*'%a)
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    12
    for name in names :
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    13
        print 'rename %s to %s' % (name, name.replace(a,b))
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    14
    if raw_input('accept [y/N]?').lower() =='y':
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    15
        for name in names:
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    16
            os.system('hg mv %s %s' % (name, name.replace(a,b)))
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    17
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    18
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    19
def ls(): print '\n'.join(sorted(os.listdir('.')))
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    20
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    21
def move():
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    22
    filenames = []
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    23
    for name in sorted(os.listdir('.')):
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    24
        num = name[:2]
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    25
        if num.isdigit():
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    26
            filenames.append( (int(num), name) )
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    27
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    28
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    29
    #print filenames
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    30
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    31
    for num, name in filenames:
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    32
        if num >= start:
ae611743f5c6 [doc] divided book in parts
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    33
            print 'hg mv %s %2i%s' %(name,num+1,name[2:])