From 0856ac758fb7bc97ec089ca8bd1395379028fa66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 19 Jan 2020 18:35:48 +0100 Subject: [PATCH] general: paint it black --- debian/debian_config.py | 13 +-- debian/settings.py | 6 +- scrutiny/projects/admin.py | 6 ++ .../management/commands/scrutinise.py | 11 +-- .../management/commands/update-redmine.py | 21 +++-- scrutiny/projects/migrations/0001_initial.py | 59 +++++++----- .../migrations/0002_auto_20150325_0908.py | 5 +- scrutiny/projects/models.py | 39 ++++---- scrutiny/projects/templatetags/tags.py | 2 + scrutiny/projects/urls.py | 35 +++++--- scrutiny/projects/utils.py | 16 ++-- scrutiny/projects/views.py | 90 ++++++++++++------- scrutiny/settings.py | 24 ++--- scrutiny/views.py | 6 +- scrutiny/wsgi.py | 2 + setup.py | 47 +++++----- 16 files changed, 218 insertions(+), 164 deletions(-) diff --git a/debian/debian_config.py b/debian/debian_config.py index c04b78c..19258df 100644 --- a/debian/debian_config.py +++ b/debian/debian_config.py @@ -9,9 +9,7 @@ TEMPLATE_DEBUG = False SECRET_KEY = open('/etc/%s/secret' % PROJECT_NAME).read() -ADMINS = ( - ('Tous', 'root@localhost'), -) +ADMINS = (('Tous', 'root@localhost'),) EMAIL_SUBJECT_PREFIX = '[%s] ' % PROJECT_NAME @@ -27,14 +25,9 @@ MEDIA_ROOT = os.path.join(VAR_DIR, 'media') CSRF_COOKIE_SECURE = True SESSION_COOKIE_SECURE = True SESSION_EXPIRE_AT_BROWSER_CLOSER = True -SESSION_COOKIE_AGE = 36000 # 10h +SESSION_COOKIE_AGE = 36000 # 10h -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': PROJECT_NAME, - } -} +DATABASES = {'default': {'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': PROJECT_NAME,}} # # local settings diff --git a/debian/settings.py b/debian/settings.py index 8eafd3c..062874c 100644 --- a/debian/settings.py +++ b/debian/settings.py @@ -15,15 +15,15 @@ DEBUG = False TEMPLATE_DEBUG = False -#ADMINS = ( +# ADMINS = ( # # ('User 1', 'watchdog@example.net'), # # ('User 2', 'janitor@example.net'), -#) +# ) # ALLOWED_HOSTS must be correct in production! # See https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts ALLOWED_HOSTS = [ - '*', + '*', ] # Databases diff --git a/scrutiny/projects/admin.py b/scrutiny/projects/admin.py index 7f2c2dc..16b406e 100644 --- a/scrutiny/projects/admin.py +++ b/scrutiny/projects/admin.py @@ -2,31 +2,37 @@ from django.contrib import admin from .models import Project, Platform, Service, InstalledService, Module + class ProjectAdmin(admin.ModelAdmin): prepopulated_fields = {'slug': ('title',)} + admin.site.register(Project, ProjectAdmin) class PlatformAdmin(admin.ModelAdmin): prepopulated_fields = {'slug': ('title',)} + admin.site.register(Platform, PlatformAdmin) class ServiceAdmin(admin.ModelAdmin): prepopulated_fields = {'slug': ('title',)} + admin.site.register(Service, ServiceAdmin) class InstalledServiceAdmin(admin.ModelAdmin): pass + admin.site.register(InstalledService, InstalledServiceAdmin) class ModuleAdmin(admin.ModelAdmin): pass + admin.site.register(Module, ModuleAdmin) diff --git a/scrutiny/projects/management/commands/scrutinise.py b/scrutiny/projects/management/commands/scrutinise.py index 0abe014..ba5ed0f 100644 --- a/scrutiny/projects/management/commands/scrutinise.py +++ b/scrutiny/projects/management/commands/scrutinise.py @@ -10,23 +10,21 @@ class Command(BaseCommand): help = 'Scrutiny services for changes' def handle(self, verbosity, *args, **options): - self.verbose = (int(verbosity) > 1) + self.verbose = int(verbosity) > 1 for service in InstalledService.objects.all(): if not service.url.endswith('/'): service.url = '%s/' % service.url if self.verbose: print('Checking %s' % service.url) try: - response = requests.get('%s__version__' % service.url, - timeout=5, verify=True) + response = requests.get('%s__version__' % service.url, timeout=5, verify=True) response.raise_for_status() except requests.RequestException as e: print('Error with %s (%r)' % (service.url, e)) continue versions = response.json() - current_modules = set([x for x in - service.service.get_modules(platforms=[service.platform])]) + current_modules = set([x for x in service.service.get_modules(platforms=[service.platform])]) seen_modules = set() for module_name, version_string in versions.items(): @@ -44,8 +42,7 @@ class Command(BaseCommand): version = module.version_set.create(version=version_string) try: - installed_version = InstalledVersion.objects.get( - service=service, version=version) + installed_version = InstalledVersion.objects.get(service=service, version=version) except InstalledVersion.DoesNotExist: installed_version = InstalledVersion() installed_version.service = service diff --git a/scrutiny/projects/management/commands/update-redmine.py b/scrutiny/projects/management/commands/update-redmine.py index b13ec25..0ef82a2 100644 --- a/scrutiny/projects/management/commands/update-redmine.py +++ b/scrutiny/projects/management/commands/update-redmine.py @@ -27,7 +27,9 @@ class Command(BaseCommand): continue try: - issues = list(redmine_server.issue.filter(project_id=module.redmine_project, status_id=RESOLVED_ID)) + issues = list( + redmine_server.issue.filter(project_id=module.redmine_project, status_id=RESOLVED_ID) + ) except redmine.exceptions.ResourceNotFoundError: if verbosity > 1: print('unknown redmine module:', module.name) @@ -36,13 +38,20 @@ class Command(BaseCommand): deployment_status = get_issue_deployment_status(issue.id) if not deployment_status.get('platforms'): if verbosity > 1: - print(' unknown status for https://dev.entrouvert.org/issues/%s (%s)' % ( - issue.id, module.redmine_project)) + print( + ' unknown status for https://dev.entrouvert.org/issues/%s (%s)' + % (issue.id, module.redmine_project) + ) continue - platforms_ok = [x.rsplit(' / ', 1)[0] for x in deployment_status['platforms'].keys() - if deployment_status['platforms'][x]['status'] == 'ok'] + platforms_ok = [ + x.rsplit(' / ', 1)[0] + for x in deployment_status['platforms'].keys() + if deployment_status['platforms'][x]['status'] == 'ok' + ] if settings.REDMINE_REFERENCE_PLATFORM in platforms_ok: if verbosity > 0: - print('%s - https://dev.entrouvert.org/issues/%s' % (module.redmine_project, issue.id)) + print( + '%s - https://dev.entrouvert.org/issues/%s' % (module.redmine_project, issue.id) + ) issue.status_id = DEPLOYED_ID issue.save() diff --git a/scrutiny/projects/migrations/0001_initial.py b/scrutiny/projects/migrations/0001_initial.py index 0915dba..d98fa3d 100644 --- a/scrutiny/projects/migrations/0001_initial.py +++ b/scrutiny/projects/migrations/0001_initial.py @@ -6,85 +6,98 @@ from django.db import models, migrations class Migration(migrations.Migration): - dependencies = [ - ] + dependencies = [] operations = [ migrations.CreateModel( name='InstalledService', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ( + 'id', + models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True), + ), ('url', models.URLField()), ], - options={ - }, + options={}, bases=(models.Model,), ), migrations.CreateModel( name='InstalledVersion', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ( + 'id', + models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True), + ), ('timestamp', models.DateTimeField()), ('service', models.ForeignKey(to='projects.InstalledService')), ], - options={ - }, + options={}, bases=(models.Model,), ), migrations.CreateModel( name='Module', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ( + 'id', + models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True), + ), ('name', models.CharField(max_length=50)), ('repository_url', models.URLField()), ], - options={ - }, + options={}, bases=(models.Model,), ), migrations.CreateModel( name='Platform', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ( + 'id', + models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True), + ), ('title', models.CharField(max_length=50)), ('slug', models.SlugField()), ], - options={ - }, + options={}, bases=(models.Model,), ), migrations.CreateModel( name='Project', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ( + 'id', + models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True), + ), ('title', models.CharField(max_length=50)), ('slug', models.SlugField()), ], - options={ - }, + options={}, bases=(models.Model,), ), migrations.CreateModel( name='Service', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ( + 'id', + models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True), + ), ('title', models.CharField(max_length=50)), ('slug', models.SlugField()), ('project', models.ForeignKey(to='projects.Project')), ], - options={ - }, + options={}, bases=(models.Model,), ), migrations.CreateModel( name='Version', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ( + 'id', + models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True), + ), ('version', models.CharField(max_length=50)), ('module', models.ForeignKey(to='projects.Module')), ], - options={ - }, + options={}, bases=(models.Model,), ), migrations.AddField( diff --git a/scrutiny/projects/migrations/0002_auto_20150325_0908.py b/scrutiny/projects/migrations/0002_auto_20150325_0908.py index 36e82c5..3d68278 100644 --- a/scrutiny/projects/migrations/0002_auto_20150325_0908.py +++ b/scrutiny/projects/migrations/0002_auto_20150325_0908.py @@ -11,10 +11,7 @@ class Migration(migrations.Migration): ] operations = [ - migrations.AlterModelOptions( - name='platform', - options={'ordering': ['order']}, - ), + migrations.AlterModelOptions(name='platform', options={'ordering': ['order']},), migrations.AddField( model_name='platform', name='order', diff --git a/scrutiny/projects/models.py b/scrutiny/projects/models.py index 4950727..e3dcc36 100644 --- a/scrutiny/projects/models.py +++ b/scrutiny/projects/models.py @@ -5,6 +5,7 @@ import subprocess from django.conf import settings from django.db import models + class Project(models.Model): title = models.CharField(max_length=50) slug = models.SlugField() @@ -40,14 +41,14 @@ class Service(models.Model): platforms = self.project.platform_set.all() for platform in platforms: try: - installed_service = InstalledService.objects.get(service=self, - platform=platform) + installed_service = InstalledService.objects.get(service=self, platform=platform) except InstalledService.DoesNotExist: continue seen_modules = [] uninstalled_modules = [] - for installed_version in InstalledVersion.objects.filter( - service=installed_service).order_by('-timestamp'): + for installed_version in InstalledVersion.objects.filter(service=installed_service).order_by( + '-timestamp' + ): if installed_version.version.module in seen_modules: continue seen_modules.append(installed_version.version.module) @@ -59,8 +60,7 @@ class Service(models.Model): def get_installed_service(self, platform): try: - installed_service = InstalledService.objects.get(service=self, - platform=platform) + installed_service = InstalledService.objects.get(service=self, platform=platform) except InstalledService.DoesNotExist: return None return installed_service @@ -72,9 +72,12 @@ class InstalledService(models.Model): url = models.URLField() def __unicode__(self): - return '%s / %s / %s (@ %s)' % (self.platform.project.title, - self.platform.title, self.service.title, - self.url) + return '%s / %s / %s (@ %s)' % ( + self.platform.project.title, + self.platform.title, + self.service.title, + self.url, + ) class Module(models.Model): @@ -94,13 +97,13 @@ class Module(models.Model): def get_installed_version(self, platform, service): try: - installed_service = InstalledService.objects.get( - platform=platform, service=service) + installed_service = InstalledService.objects.get(platform=platform, service=service) except InstalledService.DoesNotExist: return None try: - v = InstalledVersion.objects.filter( - service=installed_service, version__module=self).order_by('-timestamp')[0] + v = InstalledVersion.objects.filter(service=installed_service, version__module=self).order_by( + '-timestamp' + )[0] except IndexError: return None return v @@ -141,12 +144,14 @@ class Module(models.Model): if grep: cmd.append('--grep') cmd.append(grep) + def get_ref(v): if re.findall(r'\.g([0-9a-f]{7})', v): return re.findall(r'\.g([0-9a-f]{7})', v)[0] if re.findall(r'\+g([0-9a-f]{7})', v): return re.findall(r'\+g([0-9a-f]{7})', v)[0] return 'v' + v + cmd.append('%s...%s' % (get_ref(v1), get_ref(v2))) p = subprocess.Popen(cmd, **kws) @@ -162,6 +167,7 @@ class Module(models.Model): versions.add(version.version.version) return versions + class Version(models.Model): module = models.ForeignKey('Module') version = models.CharField(max_length=100, blank=True) @@ -177,9 +183,8 @@ class InstalledVersion(models.Model): def get_previous_version(self): try: - return InstalledVersion.objects.filter(service=self.service, - version__module=self.version.module, - timestamp__lt=self.timestamp - ).order_by('-timestamp')[0] + return InstalledVersion.objects.filter( + service=self.service, version__module=self.version.module, timestamp__lt=self.timestamp + ).order_by('-timestamp')[0] except IndexError: return None diff --git a/scrutiny/projects/templatetags/tags.py b/scrutiny/projects/templatetags/tags.py index a966c7d..93d9dd7 100644 --- a/scrutiny/projects/templatetags/tags.py +++ b/scrutiny/projects/templatetags/tags.py @@ -2,6 +2,7 @@ from django import template register = template.Library() + @register.simple_tag def installed_version(module, platform, service): v = module.get_installed_version(platform, service) @@ -9,6 +10,7 @@ def installed_version(module, platform, service): return '' return v.version.version + @register.simple_tag def service_url(platform, service): installed_service = service.get_installed_service(platform=platform) diff --git a/scrutiny/projects/urls.py b/scrutiny/projects/urls.py index b9a5a13..7da3950 100644 --- a/scrutiny/projects/urls.py +++ b/scrutiny/projects/urls.py @@ -1,8 +1,17 @@ from django.conf.urls import url -from .views import (ModulesView, ProjectDetailView, ProjectSummaryHistoryView, - ProjectHistoryView, ModuleDiffView, IssuesSnippet, ModuleIssuesView, - ModuleDeploymentsView, module_deployments_json, api_issues_json) +from .views import ( + ModulesView, + ProjectDetailView, + ProjectSummaryHistoryView, + ProjectHistoryView, + ModuleDiffView, + IssuesSnippet, + ModuleIssuesView, + ModuleDeploymentsView, + module_deployments_json, + api_issues_json, +) urlpatterns = [ @@ -10,14 +19,18 @@ urlpatterns = [ url(r'^(?P[\w,-]+)/$', ProjectDetailView.as_view(), name='project-view'), url(r'^(?P[\w,-]+)/history$', ProjectSummaryHistoryView.as_view(), name='project-summary-history'), url(r'^(?P[\w,-]+)/detailed-history$', ProjectHistoryView.as_view(), name='project-history'), - url(r'^modules/(?P[\w,-]+)/diff/(?P[\w,\.-]+)/(?P[\w,\.-]+)$', - ModuleDiffView.as_view(), name='module-diff'), + url( + r'^modules/(?P[\w,-]+)/diff/(?P[\w,\.-]+)/(?P[\w,\.-]+)$', + ModuleDiffView.as_view(), + name='module-diff', + ), url(r'^issues/snippet/$', IssuesSnippet.as_view(), name='issues-snippet'), - url(r'^modules/(?P[\w,-]+)/issues/(?P[\w,\.-]+)/(?P[\w,\.-]+)$', - ModuleIssuesView.as_view(), name='module-issues'), - url(r'^modules/(?P[\w,-]+)/$', - ModuleDeploymentsView.as_view(), name='module-deployments'), - url(r'^modules/(?P[\w,-]+)/json$', - module_deployments_json, name='module-deployments-json'), + url( + r'^modules/(?P[\w,-]+)/issues/(?P[\w,\.-]+)/(?P[\w,\.-]+)$', + ModuleIssuesView.as_view(), + name='module-issues', + ), + url(r'^modules/(?P[\w,-]+)/$', ModuleDeploymentsView.as_view(), name='module-deployments'), + url(r'^modules/(?P[\w,-]+)/json$', module_deployments_json, name='module-deployments-json'), url(r'^api/issues/(?P\d+)/$', api_issues_json), ] diff --git a/scrutiny/projects/utils.py b/scrutiny/projects/utils.py index 989127f..621695f 100644 --- a/scrutiny/projects/utils.py +++ b/scrutiny/projects/utils.py @@ -23,8 +23,9 @@ class Issue(object): def update_content(self): response = requests.get( - '%s/issues/%s.json' % (settings.REDMINE_URL, self.id), - headers={'X-Redmine-API-Key': settings.REDMINE_API_KEY}) + '%s/issues/%s.json' % (settings.REDMINE_URL, self.id), + headers={'X-Redmine-API-Key': settings.REDMINE_API_KEY}, + ) response.raise_for_status() content = response.json() cache.set('issue-%s' % self.id, content, CACHE_DURATION) @@ -64,7 +65,6 @@ class Issue(object): class CommitAndIssues(object): - def __init__(self, oneline): self.issues = [] self.commit = oneline.strip() @@ -91,6 +91,7 @@ class CommitAndIssues(object): def get_issue_deployment_status(issue_id): from .models import Module, InstalledService + data = {} for module in Module.objects.all(): try: @@ -112,16 +113,17 @@ def get_issue_deployment_status(issue_id): if not version_number: continue service_name = '%s / %s / %s' % ( - installed_version.service.platform.project.title, - installed_version.service.platform.title, - installed_version.service.service.title) + installed_version.service.platform.project.title, + installed_version.service.platform.title, + installed_version.service.service.title, + ) version_hash = module.get_version_hash(version_number) if not version_hash in git_log_hashes: continue version_index = git_log_hashes.index(version_hash) data['platforms'][service_name] = { 'version': version_number, - 'status': 'ok' if version_index <= fix_index else 'nok' + 'status': 'ok' if version_index <= fix_index else 'nok', } if data: break diff --git a/scrutiny/projects/views.py b/scrutiny/projects/views.py index 8e5d3c3..ac090dc 100644 --- a/scrutiny/projects/views.py +++ b/scrutiny/projects/views.py @@ -11,6 +11,7 @@ from django.views.generic.detail import DetailView from .models import Project, InstalledService, Module, InstalledVersion from .utils import CommitAndIssues, decorate_commit_line, get_issue_deployment_status + class ProjectDetailView(DetailView): model = Project @@ -36,8 +37,11 @@ class ModuleDiffView(TemplateView): context['commit2'] = commit2 context['difflog'] = '\n'.join( - [decorate_commit_line(line) for line in \ - context['module'].get_diff_log(commit1, commit2).splitlines()]) + [ + decorate_commit_line(line) + for line in context['module'].get_diff_log(commit1, commit2).splitlines() + ] + ) return context @@ -50,8 +54,7 @@ class ModuleIssuesView(TemplateView): context['module'] = Module.objects.get(name=name) context['commit1'] = commit1 context['commit2'] = commit2 - commits = CommitAndIssues.get_for_commits( - context['module'], commit1, commit2) + commits = CommitAndIssues.get_for_commits(context['module'], commit1, commit2) issues = {} for commit in commits: for issue in commit.issues: @@ -75,8 +78,9 @@ class ProjectHistoryView(DetailView): def get_context_data(self, **kwargs): context = super(ProjectHistoryView, self).get_context_data(**kwargs) - installed_versions = InstalledVersion.objects.filter( - service__platform__project=self.object).order_by('-timestamp')[:1000] + installed_versions = InstalledVersion.objects.filter(service__platform__project=self.object).order_by( + '-timestamp' + )[:1000] context['installed_versions'] = installed_versions @@ -89,30 +93,42 @@ class ProjectSummaryHistoryView(DetailView): # XXX: add an 'interesting' attribute to module model? interesting_modules = [ - 'publik-base-theme', 'combo', 'wcs', 'hobo', 'authentic2', - 'welco', 'chrono', 'corbo', 'passerelle', 'fargo', 'mandayejs', - 'bijoe', 'wcs-olap', 'gadjo', - ] + 'publik-base-theme', + 'combo', + 'wcs', + 'hobo', + 'authentic2', + 'welco', + 'chrono', + 'corbo', + 'passerelle', + 'fargo', + 'mandayejs', + 'bijoe', + 'wcs-olap', + 'gadjo', + ] def get_context_data(self, **kwargs): context = super(ProjectSummaryHistoryView, self).get_context_data(**kwargs) platforms = list(self.get_object().platform_set.all()) platform = platforms[-1] - installed_versions = list(InstalledVersion.objects.filter( + installed_versions = list( + InstalledVersion.objects.filter( timestamp__gt=timezone.now() - datetime.timedelta(days=120), version__module__name__in=self.interesting_modules, - service__platform=platform).exclude( - version__version='').order_by('-timestamp')[:1000]) + service__platform=platform, + ) + .exclude(version__version='') + .order_by('-timestamp')[:1000] + ) installed_versions.reverse() versions_and_day = {} for installed in installed_versions: installed_day = installed.timestamp.strftime('%Y-%m-%d') if not installed_day in versions_and_day: - versions_and_day[installed_day] = { - 'modules': {}, - 'day': installed.timestamp.date() - } + versions_and_day[installed_day] = {'modules': {}, 'day': installed.timestamp.date()} if installed.version.module.name in versions_and_day[installed_day]['modules']: continue versions_and_day[installed_day]['modules'][installed.version.module.name] = { @@ -135,17 +151,17 @@ class ProjectSummaryHistoryView(DetailView): if len(platforms) > 1: validation_platform = platforms[-2] - future_versions = { - 'modules': {}, - 'day': 'future' - } + future_versions = {'modules': {}, 'day': 'future'} module_names = previous_versions.keys() for module_name in module_names: try: - installed_version = InstalledVersion.objects.filter( - version__module__name=module_name, - service__platform=validation_platform).exclude( - version__version='').order_by('-timestamp')[0] + installed_version = ( + InstalledVersion.objects.filter( + version__module__name=module_name, service__platform=validation_platform + ) + .exclude(version__version='') + .order_by('-timestamp')[0] + ) except IndexError: continue if not installed_version.version.version: @@ -175,12 +191,14 @@ class ModulesView(TemplateView): context['modules'] = Module.objects.all().order_by('name') return context + def try_int(x): try: return int(x) except ValueError: return 0 + version_re = re.compile(r'[\.\+-]d?e?v?') @@ -215,11 +233,18 @@ def module_deployments_json(request, name, **kwargs): if version and not version in installed_versions: installed_versions.append(version) - json.dump([{'version': x.version.version, + json.dump( + [ + { + 'version': x.version.version, 'project': x.service.platform.project.slug, 'service': x.service.service.slug, - 'platform': x.service.platform.slug} for x in installed_versions], - response) + 'platform': x.service.platform.slug, + } + for x in installed_versions + ], + response, + ) return response @@ -244,12 +269,11 @@ class IssuesSnippet(TemplateView): if not module.repository_url: continue commits = CommitAndIssues.get_for_commits( - module, - str(module_info.get('previous_version')), - str(module_info.get('current_version'))) + module, str(module_info.get('previous_version')), str(module_info.get('current_version')) + ) for commit in commits: for issue in commit.issues: - if issue.subject == '---': # private issue + if issue.subject == '---': # private issue continue if not int(issue.id) in issues: issues[int(issue.id)] = issue @@ -261,7 +285,7 @@ class IssuesSnippet(TemplateView): context['issues'] = list(issues.values()) context['issues'].sort(key=lambda x: x.closed_on) - context['issues'].reverse() # most recent on top + context['issues'].reverse() # most recent on top return context diff --git a/scrutiny/settings.py b/scrutiny/settings.py index 7b0bd17..4ab7bbc 100644 --- a/scrutiny/settings.py +++ b/scrutiny/settings.py @@ -40,8 +40,7 @@ MIDDLEWARE_CLASSES = ( ) # Serve xstatic files, required for gadjo -STATICFILES_FINDERS = list(global_settings.STATICFILES_FINDERS) + \ - ['gadjo.finders.XStaticFinder'] +STATICFILES_FINDERS = list(global_settings.STATICFILES_FINDERS) + ['gadjo.finders.XStaticFinder'] ROOT_URLCONF = 'scrutiny.urls' @@ -51,10 +50,7 @@ WSGI_APPLICATION = 'scrutiny.wsgi.application' # https://docs.djangoproject.com/en/1.7/ref/settings/#databases DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'scrutiny.sqlite3'), - } + 'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'scrutiny.sqlite3'),} } # Internationalization @@ -70,7 +66,7 @@ USE_L10N = True USE_TZ = True -LOCALE_PATHS = (os.path.join(BASE_DIR, 'scrutiny', 'locale'), ) +LOCALE_PATHS = (os.path.join(BASE_DIR, 'scrutiny', 'locale'),) # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.7/howto/static-files/ @@ -78,9 +74,7 @@ LOCALE_PATHS = (os.path.join(BASE_DIR, 'scrutiny', 'locale'), ) STATIC_URL = '/static/' # Additional locations of static files -STATICFILES_DIRS = ( - os.path.join(BASE_DIR, 'scrutiny', 'static'), -) +STATICFILES_DIRS = (os.path.join(BASE_DIR, 'scrutiny', 'static'),) MEDIA_ROOT = os.path.join(BASE_DIR, 'media') @@ -89,9 +83,7 @@ MEDIA_URL = '/media/' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [ - os.path.join(BASE_DIR, 'scrutiny', 'templates'), - ], + 'DIRS': [os.path.join(BASE_DIR, 'scrutiny', 'templates'),], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -139,13 +131,13 @@ MELLON_USERNAME_TEMPLATE = '{attributes[name_id_content]}' MELLON_IDENTITY_PROVIDERS = [] - REDMINE_REFERENCE_PLATFORM = 'SaaS2 / Test' REDMINE_URL = 'https://dev.entrouvert.org' REDMINE_API_KEY = None -local_settings_file = os.environ.get('SCRUTINY_SETTINGS_FILE', - os.path.join(os.path.dirname(__file__), 'local_settings.py')) +local_settings_file = os.environ.get( + 'SCRUTINY_SETTINGS_FILE', os.path.join(os.path.dirname(__file__), 'local_settings.py') +) if os.path.exists(local_settings_file): exec(open(local_settings_file).read()) diff --git a/scrutiny/views.py b/scrutiny/views.py index d901c9a..311f1c6 100644 --- a/scrutiny/views.py +++ b/scrutiny/views.py @@ -19,10 +19,10 @@ def login(request, *args, **kwargs): if any(get_idps()): if not 'next' in request.GET: return HttpResponseRedirect(resolve_url('mellon_login')) - return HttpResponseRedirect(resolve_url('mellon_login') + '?next=' - + quote(request.GET.get('next'))) + return HttpResponseRedirect(resolve_url('mellon_login') + '?next=' + quote(request.GET.get('next'))) return auth_views.login(request, *args, **kwargs) + def logout(request, next_page=None): if any(get_idps()): return HttpResponseRedirect(resolve_url('mellon_logout')) @@ -34,7 +34,6 @@ def logout(request, next_page=None): return HttpResponseRedirect(next_page) - class Home(TemplateView): template_name = 'scrutiny/home.html' @@ -43,4 +42,5 @@ class Home(TemplateView): context['projects'] = Project.objects.all() return context + home = Home.as_view() diff --git a/scrutiny/wsgi.py b/scrutiny/wsgi.py index 0317c0b..6a46f3b 100644 --- a/scrutiny/wsgi.py +++ b/scrutiny/wsgi.py @@ -7,7 +7,9 @@ For more information on this file, see https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/ """ import os + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "scrutiny.settings") from django.core.wsgi import get_wsgi_application + application = get_wsgi_application() diff --git a/setup.py b/setup.py index 22a44f6..5f5b7de 100755 --- a/setup.py +++ b/setup.py @@ -5,6 +5,7 @@ from distutils.command.sdist import sdist import os import subprocess + class eo_sdist(sdist): def run(self): if os.path.exists('VERSION'): @@ -17,6 +18,7 @@ class eo_sdist(sdist): if os.path.exists('VERSION'): os.remove('VERSION') + def get_version(): '''Use the VERSION, if absent generates a version with git describe, if not tag exists, take 0.0- and add the length of the commit log. @@ -25,38 +27,35 @@ def get_version(): with open('VERSION', 'r') as v: return v.read() if os.path.exists('.git'): - p = subprocess.Popen(['git','describe','--dirty=.dirty','--match=v*'], - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p = subprocess.Popen( + ['git', 'describe', '--dirty=.dirty', '--match=v*'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) result = p.communicate()[0] if p.returncode == 0: - result = result.decode('ascii').strip()[1:] # strip spaces/newlines and initial v - if '-' in result: # not a tagged version + result = result.decode('ascii').strip()[1:] # strip spaces/newlines and initial v + if '-' in result: # not a tagged version real_number, commit_count, commit_hash = result.split('-', 2) version = '%s.post%s+%s' % (real_number, commit_count, commit_hash) else: version = result return version else: - return '0.0.post%s' % len( - subprocess.check_output( - ['git', 'rev-list', 'HEAD']).splitlines()) + return '0.0.post%s' % len(subprocess.check_output(['git', 'rev-list', 'HEAD']).splitlines()) return '0.0' -setup(name='scrutiny', - version=get_version(), - license='AGPLv3', - description='', - author="Entr'ouvert", - author_email="info@entrouvert.com", - packages=find_packages(os.path.dirname(__file__) or '.'), - scripts=['manage.py'], - include_package_data = True, - install_requires=[ - 'django >= 1.8, < 1.12', - 'requests', - 'gadjo', - ], - cmdclass={ - 'sdist': eo_sdist, - }, + +setup( + name='scrutiny', + version=get_version(), + license='AGPLv3', + description='', + author="Entr'ouvert", + author_email="info@entrouvert.com", + packages=find_packages(os.path.dirname(__file__) or '.'), + scripts=['manage.py'], + include_package_data=True, + install_requires=['django >= 1.8, < 1.12', 'requests', 'gadjo',], + cmdclass={'sdist': eo_sdist,}, )