Skip to content
Browse files

Adding basic model for packages

  • Loading branch information...
1 parent a112fff commit 7dfccf4fdf61ff10ffabc27f25bc34254abff453 @carlio committed
View
44 pihub/packages/metadata.py
@@ -0,0 +1,44 @@
+# taken from https://github.com/perone/stallion/blob/master/stallion/metadata.py
+
+# Tuple metadata format
+# (Field Name, lowered field name, Optional)
+
+# Based on the PEP-0241
+HEADER_META_1_0 = (
+ 'metadata-version',
+ 'name',
+ 'version',
+ 'platform',
+ 'supported-platform',
+ 'summary',
+ 'description',
+ 'keywords',
+ 'home-page',
+ 'author',
+ 'author-email',
+ 'license',
+ # Not part of PEP, but PEP-0314 (everyone uses anyway in 1.0)
+ 'classifier'
+)
+
+# Based on the PEP-0314
+HEADER_META_1_1 = HEADER_META_1_0 + (
+ 'download-url',
+ 'requires',
+ 'provides',
+ 'obsoletes',
+)
+
+# Based on the PEP-0345
+HEADER_META_1_2 = HEADER_META_1_1 + (
+ 'maintainer',
+ 'maintainer-email',
+ 'requires-python',
+ 'requires-external',
+ 'requires-dist',
+ 'provides-dist',
+ 'obsoletes-dist',
+ 'project-url',
+)
+
+HEADER_META_ALL = HEADER_META_1_2
View
64 pihub/packages/migrations/0001_initial.py
@@ -0,0 +1,64 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding model 'Pkg'
+ db.create_table('packages_pkg', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('name', self.gf('django.db.models.fields.CharField')(max_length=100)),
+ ))
+ db.send_create_signal('packages', ['Pkg'])
+
+ # Adding model 'ReleaseData'
+ db.create_table('packages_releasedata', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('pkg', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['packages.Pkg'])),
+ ('version', self.gf('django.db.models.fields.CharField')(max_length=40)),
+ ('summary', self.gf('django.db.models.fields.TextField')(null=True)),
+ ))
+ db.send_create_signal('packages', ['ReleaseData'])
+
+ # Adding model 'ReleaseUrl'
+ db.create_table('packages_releaseurl', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ))
+ db.send_create_signal('packages', ['ReleaseUrl'])
+
+
+ def backwards(self, orm):
+ # Deleting model 'Pkg'
+ db.delete_table('packages_pkg')
+
+ # Deleting model 'ReleaseData'
+ db.delete_table('packages_releasedata')
+
+ # Deleting model 'ReleaseUrl'
+ db.delete_table('packages_releaseurl')
+
+
+ models = {
+ 'packages.pkg': {
+ 'Meta': {'object_name': 'Pkg'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'packages.releasedata': {
+ 'Meta': {'object_name': 'ReleaseData'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'pkg': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['packages.Pkg']"}),
+ 'summary': ('django.db.models.fields.TextField', [], {'null': 'True'}),
+ 'version': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+ },
+ 'packages.releaseurl': {
+ 'Meta': {'object_name': 'ReleaseUrl'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
+ }
+ }
+
+ complete_apps = ['packages']
View
0 pihub/packages/migrations/__init__.py
No changes.
View
18 pihub/packages/models.py
@@ -1,14 +1,30 @@
from django.db import models
+from pihub.packages.metadata import HEADER_META_ALL
+import re
class Pkg(models.Model):
# named Pkg to avoid conflicts with the 'package' keyword...
- pass
+ name = models.CharField(max_length=100)
class ReleaseData(models.Model):
pkg = models.ForeignKey(Pkg)
version = models.CharField(max_length=40)
+ summary = models.TextField(null=True)
+
+ def __init__(self, *args, **kwargs):
+ super(ReleaseData, self).__init__(*args, **kwargs)
+ for metadata_field in HEADER_META_ALL:
+ field_name = re.sub('-', '_', metadata_field)
+ if field_name in self.fields:
+ # don't use the default definition if we have already
+ # written something specifically
+ continue
+ self.fields[field_name] = models.CharField(max_length=200, null=True)
+
+
+
class ReleaseUrl(models.Model):
pass

0 comments on commit 7dfccf4

Please sign in to comment.
Something went wrong with that request. Please try again.