def get_updates(url, last_rev, username = None, password = None): log = logging.getLogger('django_vcs_watch.backend.svn') command = ['svn', 'log', '--non-interactive'] if last_rev: command += ['-r', 'HEAD:%s' % last_rev] command += ['--limit', '%s' % REVISION_LIMIT] if username: command += ['--username', username] if password: command += ['--password', password] command += ['--xml', url] log.debug(re.sub(r"--password '.*'", "--password 'xxxxx'", ' '.join(command))) svn = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) xml, stderr = svn.communicate() if svn.returncode != 0 or stderr or not xml: log.error('svn command failed with code %d and message %r' % (svn.returncode, stderr)) raise Exception(' '.join(stderr.splitlines())) xml_e = ET.fromstring(xml) commits = [] diff_processor = DiffProcessor() for entry_e in xml_e.findall('logentry'): revision = entry_e.attrib['revision'] if revision == last_rev: continue author = entry_e.find('author').text msg = entry_e.find('msg').text date = parse_date(entry_e.find('date').text).astimezone(tzutc()) command = ['svn', 'diff', '-c', str(revision), url] log.debug('fetching diff: %r' % ' '.join(command)) svn = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) diff, stderr = svn.communicate() commits.insert(0, dict( revision = revision, changes = diff_processor.process(guess_encoding(diff)), message = msg or u'', date = strip_timezone(date), author = author ) ) return commits
def testSeparate(self): diff = """ Index: django/db/backends/oracle/introspection.py =================================================================== --- django/db/backends/oracle/introspection.py (revision 11474) +++ django/db/backends/oracle/introspection.py (revision 11475) @@ -26,6 +26,14 @@ except AttributeError: pass + def get_field_type(self, data_type, description): + # If it's a NUMBER with scale == 0, consider it an IntegerField + if data_type == cx_Oracle.NUMBER and description[5] == 0: + return 'IntegerField' + else: + return super(DatabaseIntrospection, self).get_field_type( + data_type, description) + def get_table_list(self, cursor): \"Returns a list of table names in the current database.\" cursor.execute(\"SELECT TABLE_NAME FROM USER_TABLES\") Index: django/db/backends/__init__.py =================================================================== --- django/db/backends/__init__.py (revision 11474) +++ django/db/backends/__init__.py (revision 11475) @@ -470,6 +470,14 @@ def __init__(self, connection): self.connection = connection + def get_field_type(self, data_type, description): + \"\"\"Hook for a database backend to use the cursor description to + match a Django field type to a database column. + + For Oracle, the column data_type on its own is insufficient to + distinguish between a FloatField and IntegerField, for example.\"\"\" + return self.data_types_reverse[data_type] + def table_name_converter(self, name): \"\"\"Apply a conversion to the name for the purposes of comparison. @@ -560,4 +568,3 @@ def validate_field(self, errors, opts, f): \"By default, there is no backend-specific validation\" pass - Index: django/core/management/commands/inspectdb.py =================================================================== --- django/core/management/commands/inspectdb.py (revision 11474) +++ django/core/management/commands/inspectdb.py (revision 11475) @@ -73,7 +73,7 @@ extra_params['db_column'] = column_name else: try: - field_type = connection.introspection.data_types_reverse[row[1]] + field_type = connection.introspection.get_field_type(row[1], row) except KeyError: field_type = 'TextField' comment_notes.append('This field type is a guess.') """ processor = DiffProcessor() result = processor.process(diff) self.assertEqual(3, len(result['changed'])) self.assertEqual([ 'django/db/backends/oracle/introspection.py', 'django/db/backends/__init__.py', 'django/core/management/commands/inspectdb.py', ], [file['filename'] for file in result['changed']]) self.assertEqual(17, result['stats']['added']) self.assertEqual(-2, result['stats']['removed']) self.assert_(unicode, type(result['changed'][0]['diff'])) self.assertEqual(8, result['changed'][0]['stats']['added']) self.assertEqual(0, result['changed'][0]['stats']['removed']) self.assertEqual(8, result['changed'][1]['stats']['added']) self.assertEqual(-1, result['changed'][1]['stats']['removed']) self.assertEqual(1, result['changed'][2]['stats']['added']) self.assertEqual(-1, result['changed'][2]['stats']['removed'])
def get_updates(url, last_rev, username=None, password=None): log = logging.getLogger('django_vcs_watch.backend.svn') command = ['svn', 'log', '--non-interactive'] if last_rev: command += ['-r', 'HEAD:%s' % last_rev] command += ['--limit', '%s' % REVISION_LIMIT] if username: command += ['--username', username] if password: command += ['--password', password] command += ['--xml', url] log.debug( re.sub(r"--password '.*'", "--password 'xxxxx'", ' '.join(command))) svn = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) xml, stderr = svn.communicate() if svn.returncode != 0 or stderr or not xml: log.error('svn command failed with code %d and message %r' % (svn.returncode, stderr)) raise Exception(' '.join(stderr.splitlines())) xml_e = ET.fromstring(xml) commits = [] diff_processor = DiffProcessor() for entry_e in xml_e.findall('logentry'): revision = entry_e.attrib['revision'] if revision == last_rev: continue author = entry_e.find('author').text msg = entry_e.find('msg').text date = parse_date(entry_e.find('date').text).astimezone(tzutc()) command = ['svn', 'diff', '-c', str(revision), url] log.debug('fetching diff: %r' % ' '.join(command)) svn = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) diff, stderr = svn.communicate() commits.insert( 0, dict(revision=revision, changes=diff_processor.process(guess_encoding(diff)), message=msg or u'', date=strip_timezone(date), author=author)) return commits