--- a/tools.py Sun Feb 03 23:39:27 2008 +0100 +++ b/tools.py Mon Feb 04 19:02:42 2008 +0100 @@ -1,3 +1,22 @@ +# +""" +Helper functions and classes +""" +import re + +def str_num_cmp(s1,s2): + """ + string comparator function that will put 'toto_10' after 'toto_2' + Also works for strings like 'toto_1_et_23er25'. + """ + r = re.compile(r'((?<=\d)\D+|(?<=\D)\d+)') + r1= r.split(s1) + r2= r.split(s2) + r1=[not x.isdigit() and x or int(x) for x in r1 if x!=''] + r2=[not x.isdigit() and x or int(x) for x in r2 if x!=''] + return cmp(r1,r2) + + class AbstractRegister(object): _instance = None _registered_type = None