damned-lies r1122 - in branches/djamnedlies: . docs stats stats/management/commands
- From: claudep svn gnome org
- To: svn-commits-list gnome org
- Subject: damned-lies r1122 - in branches/djamnedlies: . docs stats stats/management/commands
- Date: Sat, 1 Nov 2008 19:38:52 +0000 (UTC)
Author: claudep
Date: Sat Nov 1 19:38:52 2008
New Revision: 1122
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1122&view=rev
Log:
2008-11-01 Claude Paroz <claude 2xlibre net>
* stats/management/commands/migrate.py: Adapted to model change and
reintroduced migrate_stats (conditionally import an old_statistics table
to be able to test with real and massive data).
* stats/models.py: Changed model (category is now the manytomany
intermediate table between branch and release, permitting a branch to be
in multiple releases.
* stats/urls.py: Add the '+' char as a valid char for module name (for
gtk+).
* docs/DataModel.odg: Updated.
Modified:
branches/djamnedlies/ChangeLog
branches/djamnedlies/docs/DataModel.odg
branches/djamnedlies/stats/management/commands/migrate.py
branches/djamnedlies/stats/models.py
branches/djamnedlies/stats/urls.py
Modified: branches/djamnedlies/docs/DataModel.odg
==============================================================================
Binary files. No diff available.
Modified: branches/djamnedlies/stats/management/commands/migrate.py
==============================================================================
--- branches/djamnedlies/stats/management/commands/migrate.py (original)
+++ branches/djamnedlies/stats/management/commands/migrate.py Sat Nov 1 19:38:52 2008
@@ -1,7 +1,7 @@
import os
import sys
from django.core.management.base import BaseCommand
-from stats.models import Person, Team, Language, Module, Branch, Domain, Release, Category
+from stats.models import Person, Team, Language, Module, Branch, Domain, Release, Category, Statistics
from stats.conf import settings
class Command(BaseCommand):
@@ -20,6 +20,7 @@
print self.migrate_teams()
print self.migrate_modules()
print self.migrate_releases()
+ print self.migrate_stats()
# Network_manager domains may need renaming (vpn-daemons/openvpn/po -> po-openvpn, ...)
return "Migration completed."
@@ -150,42 +151,79 @@
new_r.save()
if release.has_key('category'):
for catname, catcontent in release['category'].items():
- relcat = Category(release=new_r, description=catcontent['_description'])
- relcat.save()
for mod, content in catcontent['module'].items():
- # find the right component
- module = Module.objects.get(name=mod)
+ # find the right branch
if content.has_key('branch'):
branch_name = content['branch']
else:
+ module = Module.objects.get(name=mod)
if module.vcs_type == 'git':
branch_name = u'master'
else:
branch_name = u'HEAD'
- # set the release field of the branch (with relcat)
- for br in module.branch_set.all():
- if br.name == branch_name:
- br.category = relcat
- br.save()
+ try:
+ branch = Branch.objects.get(module__name=mod, name=branch_name)
+ cat = Category(release=new_r, branch=branch, category=catcontent['_description'])
+ cat.save()
+ except:
+ print "Unable to find branch '%s' of module '%s' for release '%s'" % (branch_name, mod, release['_description'])
else:
- relcat = Category(release=new_r, description='default')
- relcat.save()
for mod, content in release['module'].items():
- try:
- module = Module.objects.get(name=mod)
- except:
- print "Unable to find module '%s'" % mod
- continue
if content.has_key('branch'):
branch_name = content['branch']
else:
+ module = Module.objects.get(name=mod)
if module.vcs_type == 'git':
branch_name = u'master'
else:
branch_name = u'HEAD'
- # set the release field of the branch (with relcat)
- for br in module.branch_set.all():
- if br.name == branch_name:
- br.category = relcat
- br.save()
+ try:
+ branch = Branch.objects.get(module__name=mod, name=branch_name)
+ cat = Category(release=new_r, branch=branch, category='default')
+ cat.save()
+ except:
+ print "Unable to find branch '%s' of module '%s' for release '%s'" % (branch_name, mod, release['_description'])
return "Releases migrated successfully"
+
+
+ def migrate_stats(self):
+ """ This method migrate statistics if there is an old_statistics table (from previous DL)"""
+ from django.db import connection
+ cursor = connection.cursor()
+ try:
+ cursor.execute("SELECT module, branch, language, type, domain, date, translated, fuzzy, untranslated FROM old_statistics")
+ except:
+ print "No statistics to migrate"
+ MODULE, BRANCH, LANGUAGE, TYPE, DOMAIN, DATE, TRANSLATED, FUZZY, UNTRANSLATED = 0, 1, 2, 3, 4, 5, 6, 7, 8
+ for stat in cursor.fetchall():
+ # link to Branch, Domain and Language
+ try:
+ mod = Module.objects.get(name=stat[MODULE])
+ except:
+ print "Unable to find module corresponding to '%s'." % stat[MODULE]
+ continue
+ try:
+ br = Branch.objects.get(name=stat[BRANCH], module=mod.id)
+ except:
+ print "Unable to find branch corresponding to '%s.%s'." % (stat[MODULE], stat[BRANCH])
+ continue
+ if stat[LANGUAGE] is not None:
+ try:
+ lang = Language.objects.get(locale=stat[LANGUAGE])
+ except:
+ lang = Language(name=stat[LANGUAGE],
+ locale=stat[LANGUAGE])
+ lang.save()
+ print "Unable to find language corresponding to '%s'. Language created." % (stat[LANGUAGE])
+ else:
+ # The POT file
+ lang = None
+ for p in mod.domain_set.all():
+ if p.dtype == stat[TYPE] and p.name == stat[DOMAIN]:
+ dom = p
+ break
+ new_stat = Statistics(branch=br, language=lang, domain=dom, date=stat[DATE],
+ translated=stat[TRANSLATED], fuzzy=stat[FUZZY], untranslated=stat[UNTRANSLATED])
+ new_stat.save()
+ return "Statistics migrated successfully"
+
Modified: branches/djamnedlies/stats/models.py
==============================================================================
--- branches/djamnedlies/stats/models.py (original)
+++ branches/djamnedlies/stats/models.py Sat Nov 1 19:38:52 2008
@@ -190,7 +190,7 @@
#description = models.TextField(null=True)
vcs_subpath = models.CharField(max_length=50, null=True)
module = models.ForeignKey(Module)
- category = models.ForeignKey('Category', null=True)
+ # 'releases' is the backward relation name from Release model
class Meta:
db_table = 'branch'
@@ -205,7 +205,14 @@
elif self.module.vcs_type == 'git' and self.name == "master":
return True
return False
-
+
+ def has_string_freezed(self):
+ """ Returns true if the branch is contained in at least one stringfreezed release """
+ for rel in self.releases:
+ if rel.stringfrozen:
+ return True
+ return False
+
def get_vcs_url(self):
if self.module.vcs_type in ('hg', 'git'):
return "%s/%s" % (self.module.vcs_root, self.module_name)
@@ -273,7 +280,7 @@
""" Update statistics for all po files from the branch """
self.checkout()
domains = Domain.objects.filter(module=self.module)
- string_freezed = self.category.release.stringfrozen
+ string_freezed = self.has_string_freezed()
for dom in domains.all():
domain_path = os.path.join(self.co_path(), dom.directory)
if not os.access(domain_path, os.X_OK):
@@ -531,6 +538,7 @@
name = models.CharField(max_length=50)
stringfrozen = models.BooleanField()
status = models.CharField(max_length=12, choices=RELEASE_STATUS_CHOICES)
+ branches = models.ManyToManyField(Branch, through='Category', related_name='releases')
class Meta:
db_table = 'release'
@@ -551,7 +559,7 @@
LEFT JOIN branch AS br
ON br.id = stat.branch_id
LEFT JOIN category AS cat
- ON br.category_id = cat.id
+ ON cat.branch_id = br.id
LEFT JOIN "release" AS rel
ON rel.id = cat.release_id
WHERE rel.id = %s
@@ -585,7 +593,7 @@
LEFT JOIN branch
ON stat.branch_id = branch.id
LEFT JOIN category
- ON branch.category_id = category.id
+ ON category.branch_id = branch.id
WHERE language_id = %s
AND category.release_id = %s
GROUP BY domain.dtype"""
@@ -634,7 +642,7 @@
LEFT JOIN branch AS br
ON br.id = stat.branch_id
LEFT JOIN category
- ON br.category_id = category.id
+ ON category.branch_id = br.id
WHERE category.release_id = %s
GROUP BY domain.dtype, stat.language_id
ORDER BY domain.dtype, trans DESC"""
@@ -684,13 +692,14 @@
Used for displaying the language-release template """
# Sorted by module to allow grouping ('fake' stats)
- pot_stats = Statistics.objects.filter(language=None, branch__category__release=self).order_by('domain__module__id', 'domain__dtype')
+ pot_stats = Statistics.objects.filter(language=None, branch__releases=self).order_by('domain__module__id', 'domain__dtype')
stats = {'doc':{'totaltrans':0, 'totalfuzzy':0, 'totaluntrans':0, 'categs':{}},
'ui':{'totaltrans':0, 'totalfuzzy':0, 'totaluntrans':0, 'categs':{}}
}
for stat in pot_stats:
dtype = stat.domain.dtype
- categdescr = stat.branch.category.description
+ #import pdb; pdb.set_trace()
+ categdescr = stat.branch.category_set.get(release=self).category
domname = _(stat.domain.description)
modname = stat.domain.module.name
if not stats[dtype]['categs'].has_key(categdescr):
@@ -712,10 +721,10 @@
#stats[dtype]['categs'][categdescr]['modules']["%s-%s" % (stat.branch.id, stat.domain.id)] = stat
# Second pass for translated stats
- tr_stats = Statistics.objects.filter(language=lang, branch__category__release=self).order_by('domain__module__id')
+ tr_stats = Statistics.objects.filter(language=lang, branch__releases=self).order_by('domain__module__id')
for stat in tr_stats:
dtype = stat.domain.dtype
- categdescr = stat.branch.category.description
+ categdescr = stat.branch.category_set.get(release=self).category
domname = _(stat.domain.description)
modname = stat.domain.module.name
stats[dtype]['totaltrans'] += stat.translated
@@ -754,18 +763,21 @@
mod[1] = doms
return stats
-
+
+CATEGORY_CHOICES = (
+ ('default', 'Default'),
+ ('admin-tools', 'Administration Tools'),
+ ('dev-tools', 'Development Tools'),
+ ('desktop', 'GNOME Desktop'),
+ ('dev-platform', 'GNOME developer platform'),
+)
class Category(models.Model):
release = models.ForeignKey(Release)
- description = models.TextField()
+ branch = models.ForeignKey(Branch)
+ category = models.CharField(max_length=30, choices=CATEGORY_CHOICES, default='default')
class Meta:
db_table = 'category'
- ordering = ('release',)
- verbose_name_plural = "categories"
-
- def __unicode__(self):
- return "%s (%s)" % (self.description, self.release)
class Statistics(models.Model):
Modified: branches/djamnedlies/stats/urls.py
==============================================================================
--- branches/djamnedlies/stats/urls.py (original)
+++ branches/djamnedlies/stats/urls.py Sat Nov 1 19:38:52 2008
@@ -15,8 +15,8 @@
url(r'^languages/(?P<langcode>\w+)/(?P<release_id>\d+)/$', 'languagerelease', name='languagerelease'),
(r'^people/$', 'people'),
url(r'^module/$', 'modules', name='modules'),
- (r'^module/(?P<module_name>[\w-]+)$', 'module'),
- (r'^module/(?P<module_name>[\w-]+)/(?P<potbase>\w+)/(?P<branch_name>[\w-]+)/(?P<langcode>\w+)/images/$', 'docimages'),
+ (r'^module/(?P<module_name>[\w\-\+]+)$', 'module'),
+ (r'^module/(?P<module_name>[\w\-\+]+)/(?P<potbase>\w+)/(?P<branch_name>[\w-]+)/(?P<langcode>\w+)/images/$', 'docimages'),
url(r'^releases/$', 'releases', name='releases'),
(r'^releases/(?P<release_id>\d+)$', 'release'),
)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]