Comment 1 for bug 560324

Revision history for this message
Viper (viper-sovsem) wrote :

Proposed fix:
{num} - starts from 1, as described, and this equivalent to {num+1}
{num+10} - starts from 10.

Also reduced number exceptions raised during work, previous code generates exception for every file when {num} pattern isn't used. Using if should get better performance in such cases.

pyrenamer_filefuncs.py
330,332c330,331
< count = `count`
< cr = re.compile("{(num)([0-9]*)}"
< "|{(num)([0-9]*)(\+)([0-9]*)}")
---
> cr = re.compile("{num([0-9]*)}"
> "|{num([0-9]*) ?\+ ?([0-9]+)}")
334,337c333,338
< cg = cr.search(newname).groups()
< if len(cg) == 6:
<
< if cg[0] == 'num':
---
> cg = cr.search(newname)
> if cg:
> cg = cg.groups()
> fn = 0
> sn = 1
> if cg[0] or cg[1]:
339,342c340,341
< if cg[1] != '': count = count.zfill(int(cg[1]))
< newname = cr.sub(count, newname)
<
< elif cg[2] == 'num' and cg[4] == '+':
---
> fn = int(cg[0] or cg[1])
> if cg[2]:
344,347c343,344
< if cg[5] != '': count = str(int(count)+int(cg[5]))
< if cg[3] != '': count = count.zfill(int(cg[3]))
<
< newname = cr.sub(count, newname)
---
> sn = int(cg[2])
> newname = cr.sub(str(count + sn).zfill(fn), newname)