doc/book/mode_plan.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 26 May 2009 11:23:39 +0200
branchstable
changeset 1940 2565aae48d48
parent 127 ae611743f5c6
child 1977 606923dff11b
permissions -rw-r--r--
fix so that one can edit an entity with a Bytes field without specifying a new file
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:])