Changeset 87

Show
Ignore:
Timestamp:
10/15/07 15:32:02 (15 months ago)
Author:
steadicat
Message:

Added proper trimming of blank lines and removal of control characters.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • django/trunk/contrib/evolve.py

    r85 r87  
    2323        self.name = self.getTableName(lines[0]) 
    2424        self.old_fields = {} 
    25         for line in lines[1:-1]: 
     25        for line in lines[1:-1]: # remove create table and closing bracket 
    2626            line = line.strip().strip(',') 
    2727            self.old_fields[self.getFieldName(line)] = line 
     
    2929 
    3030    def new(self, sql): 
    31         self.new_fields = [line.strip().strip(',') for line in sql.splitlines()[2:-1]] 
     31        self.new_fields = [line.strip().strip(',') for line in sql.splitlines()[1:-1]] # remove create table and closing bracket 
    3232 
    3333    def getTableName(self, sql): 
     
    8888 
    8989if __name__=='__main__': 
    90     new_tables_sql = os.popen('manage.py sql %s' % app).read().split(';')[1:-2] 
    91     old_tables_sql = os.popen('sqlite3 %s ".schema %s_%%"' % (database, app)).read().split(';')[:-1] 
     90    new_tables_sql = os.popen('manage.py sql %s' % app).read() 
     91    old_tables_sql = os.popen('sqlite3 %s ".schema %s_%%"' % (database, app)).read() 
    9292 
     93    # remove control characters 
     94    ctrl = re.compile(r'[\000-\011\013-\037]') 
     95    new_tables_sql = ctrl.sub('', new_tables_sql) 
     96    old_tables_sql = ctrl.sub('', old_tables_sql) 
     97 
     98    new_tables_sql = new_tables_sql.split(';')[1:-2] # remove begin, commit and empty ; at the end 
     99    old_tables_sql = old_tables_sql.split(';')[:-1] # remove empty ; at the end 
     100     
    93101    tables = {} 
    94102 
     
    99107    for sql in new_tables_sql: 
    100108        t = Table(sql.strip()) 
    101         tables[t.name].new(sql) 
     109        tables[t.name].new(sql.strip()) 
    102110 
    103111    for table in tables.values():