Download:
child 1:4c512d0ecec5
0:4dcbaa8e310c
Anton Shestakov <av6@dwimlabs.net>, Sun, 12 Jun 2016 22:28:31 +0800
candolint: basic models and database management

4 файлов изменено, 81 вставок(+), 0 удалений(-) [+]
.hgignore file | annotate | diff | comparison | revisions
candolint/__init__.py file | annotate | diff | comparison | revisions
candolint/models.py file | annotate | diff | comparison | revisions
incoming.py file | annotate | diff | comparison | revisions
requirements.txt file | annotate | diff | comparison | revisions
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore Sun Jun 12 22:28:31 2016 +0800
@@ -0,0 +1,5 @@
+syntax: glob
+
+*.pyc
+venv/
+database.sqlite
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/candolint/models.py Sun Jun 12 22:28:31 2016 +0800
@@ -0,0 +1,58 @@
+import peewee as pw
+
+
+database = pw.SqliteDatabase(None, journal_mode='WAL')
+
+
+class BaseModel(pw.Model):
+ class Meta:
+ database = database
+
+
+class Project(BaseModel):
+ url = pw.CharField(unique=True)
+ domain = pw.CharField()
+ user = pw.CharField(null=True)
+ name = pw.CharField()
+
+ class Meta:
+ indexes = (
+ (('domain', 'user', 'name'), True),
+ )
+
+
+class Change(BaseModel):
+ rev = pw.IntegerField()
+ node = pw.CharField()
+ branch = pw.CharField()
+ date = pw.DateTimeField()
+ author = pw.CharField()
+ message = pw.CharField()
+
+ project = pw.ForeignKeyField(Project, related_name='changes')
+
+ class Meta:
+ indexes = (
+ (('rev', 'project'), True),
+ (('node', 'project'), True),
+ )
+
+
+class Check(BaseModel):
+ ordinal = pw.IntegerField()
+ errors = pw.IntegerField()
+ warnings = pw.IntegerField()
+ raw = pw.TextField()
+ lines = pw.TextField()
+ success = pw.BooleanField()
+ started = pw.DateTimeField()
+ finished = pw.DateTimeField()
+
+ project = pw.ForeignKeyField(Project, related_name='checks')
+ change = pw.ForeignKeyField(Change, related_name='checks')
+
+ class Meta:
+ order_by = ('-finished', '-ordinal')
+ indexes = (
+ (('ordinal', 'project'), True),
+ )
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/incoming.py Sun Jun 12 22:28:31 2016 +0800
@@ -0,0 +1,17 @@
+#!/usr/bin/env python
+import os
+from candolint.models import database, Project, Change, Check
+
+
+rel = lambda *x: os.path.abspath(os.path.join(os.path.dirname(__file__), *x))
+
+
+def main():
+ database.init(rel('database.sqlite'))
+ database.connect()
+ database.create_tables([Project, Change, Check], safe=True)
+ database.close()
+
+
+if __name__ == '__main__':
+ main()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/requirements.txt Sun Jun 12 22:28:31 2016 +0800
@@ -0,0 +1,1 @@
+peewee==2.8.1