This repository has been archived by the owner on Jun 12, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
449 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import json | ||
from urllib2 import urlopen | ||
from urlparse import urljoin | ||
from ConfigParser import ConfigParser | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from l10nstats.models import Active | ||
|
||
|
||
class Command(BaseCommand): | ||
option_list = BaseCommand.option_list | ||
|
||
def handle(self, *args, **kwargs): | ||
self.handleApps(*args, **kwargs) | ||
self.handleDirs(*args, **kwargs) | ||
|
||
def handleApps(self, *args, **kwargs): | ||
l10nbuilds = urlopen( | ||
'https://raw.githubusercontent.com/Pike/master-ball/' | ||
'master/l10n-master/l10nbuilds.ini') | ||
cp = ConfigParser() | ||
cp.readfp(l10nbuilds) | ||
for section in cp.sections(): | ||
self.stdout.write(section + '\n') | ||
self.handleSection(section, dict(cp.items(section))) | ||
|
||
def handleSection(self, section, items): | ||
locales = items['locales'] | ||
if locales == 'all': | ||
inipath = '/'.join(( | ||
items['repo'], items['mozilla'], | ||
'raw-file', 'default', | ||
items['l10n.ini'] | ||
)) | ||
ini = ConfigParser() | ||
ini.readfp(urlopen(inipath)) | ||
allpath = urljoin( | ||
urljoin(inipath, ini.get('general', 'depth')), | ||
ini.get('general', 'all')) | ||
locales = urlopen(allpath).read() | ||
locales = locales.split() | ||
obs = (Active.objects | ||
.filter(run__tree__code=section) | ||
.exclude(run__locale__code__in=locales) | ||
.order_by('run__locale__code')) | ||
obslocs = ' '.join(obs.values_list('run__locale__code', flat=True)) | ||
if not obslocs: | ||
self.stdout.write(' OK\n') | ||
return | ||
s = raw_input('Remove %s? [Y/n] ' % obslocs) | ||
if s.lower() == 'y' or s == '': | ||
obs.delete() | ||
|
||
def handleDirs(self, *args, **kwargs): | ||
dirbuilds = json.load(urlopen( | ||
'https://raw.githubusercontent.com/Pike/master-ball/' | ||
'master/l10n-master/dir-builds.json')) | ||
for treedata in dirbuilds: | ||
obs = (Active.objects | ||
.filter(run__tree__code=treedata['name']) | ||
.exclude(run__locale__code__in=treedata['locales']) | ||
.order_by('run__locale__code')) | ||
obslocs = ' '.join(obs.values_list('run__locale__code', flat=True)) | ||
if not obslocs: | ||
self.stdout.write(' OK\n') | ||
continue | ||
s = raw_input('Remove %s? [Y/n] ' % obslocs) | ||
if s.lower() == 'y' or s == '': | ||
obs.delete() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.