forked from repology/repology-updater
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repology-app.py
executable file
·1226 lines (971 loc) · 38.2 KB
/
repology-app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
#
# Copyright (C) 2016-2017 Dmitry Marakasov <[email protected]>
#
# This file is part of repology
#
# repology is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# repology is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with repology. If not, see <http://www.gnu.org/licenses/>.
import json
import math
from operator import itemgetter
import flask
from werkzeug.contrib.profiler import ProfilerMiddleware
from repology.database import Database
from repology.graphprocessor import GraphProcessor
from repology.metapackageproc import *
from repology.package import *
from repology.packageproc import *
from repology.queryfilters import *
from repology.repoman import RepositoryManager
from repology.template_helpers import *
from repology.version import VersionCompare
# create application and handle configuration
app = flask.Flask(__name__)
app.config.from_pyfile('repology.conf.default')
app.config.from_pyfile('repology.conf', silent=True)
app.config.from_envvar('REPOLOGY_CONFIG', silent=True)
# global repology objects
repoman = RepositoryManager(app.config['REPOS_DIR'], 'dummy') # XXX: should not construct fetchers and parsers here
repometadata = repoman.GetMetadata(app.config['REPOSITORIES'])
reponames = repoman.GetNames(app.config['REPOSITORIES'])
# templates: tuning
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True
# templates: custom filters
app.jinja_env.filters['pkg_format'] = pkg_format
app.jinja_env.filters['css_for_package_versionclass'] = css_for_package_versionclass
app.jinja_env.filters['css_for_summary_versionclass'] = css_for_summary_versionclass
app.jinja_env.filters['maintainer_to_links'] = maintainer_to_links
app.jinja_env.filters['maintainers_to_group_mailto'] = maintainers_to_group_mailto
# templates: custom tests
app.jinja_env.tests['for_page'] = for_page
app.jinja_env.tests['fallback_maintainer'] = is_fallback_maintainer
# templates: custom global functions
app.jinja_env.globals['url_for_self'] = url_for_self
# templates: custom global data
app.jinja_env.globals['REPOLOGY_HOME'] = app.config['REPOLOGY_HOME']
app.jinja_env.globals['repometadata'] = repometadata
app.jinja_env.globals['reponames'] = reponames
def get_db():
if not hasattr(flask.g, 'database'):
flask.g.database = Database(app.config['DSN'], readonly=False, autocommit=True)
return flask.g.database
# helpers
def api_v1_package_to_json(package):
output = {
field: getattr(package, field) for field in (
'repo',
'subrepo',
'name',
'version',
'origversion',
'maintainers',
#'category',
#'comment',
#'homepage',
'licenses',
'downloads'
) if getattr(package, field)
}
# XXX: these tweaks should be implemented in core
if package.homepage:
output['www'] = [package.homepage]
if package.comment:
output['summary'] = package.comment
if package.category:
output['categories'] = [package.category]
return output
def api_v1_metapackages_generic(bound, *filters):
metapackages = PackagesToMetapackages(
get_db().GetMetapackages(
bound_to_filter(bound),
*filters,
limit=app.config['METAPACKAGES_PER_PAGE']
)
)
metapackages = {metapackage_name: list(map(api_v1_package_to_json, packageset)) for metapackage_name, packageset in metapackages.items()}
return (
json.dumps(metapackages),
{'Content-type': 'application/json'}
)
def bound_to_filter(bound):
if bound and bound.startswith('<'):
return NameBeforeQueryFilter(bound[1:])
elif bound and bound.startswith('>'):
return NameAfterQueryFilter(bound[1:])
else:
return NameStartingQueryFilter(bound)
def get_packages_name_range(packages):
firstname, lastname = None, None
if packages:
firstname = lastname = packages[0].effname
for package in packages[1:]:
lastname = max(lastname, package.effname)
firstname = min(firstname, package.effname)
return firstname, lastname
def metapackages_to_data(metapackages, repo=None, maintainer=None):
metapackagedata = {}
for metapackagename, packages in sorted(metapackages.items()):
packages = PackagesetSortByVersions(packages)
# 1. Aggregate by repository
packages_by_repo = {}
for package in packages:
if package.repo not in packages_by_repo:
packages_by_repo[package.repo] = []
packages_by_repo[package.repo].append(package)
# 2.1. Extract explicit packages
# 2.2. Discover repos worth showing
# Repo not worth showin is the repo from which all newest (in this repo) packages
# were extracted as explicit
explicit_packages = []
ignored_packages = []
repos_worth_showing = set()
for reponame, repopackages in packages_by_repo.items():
bestversion = None
for package in repopackages:
# discover best version
if bestversion is None and package.versionclass != PackageVersionClass.ignored:
bestversion = package.version
if (repo is not None and repo == package.repo) or (maintainer is not None and maintainer in package.maintainers):
explicit_packages.append(package)
elif package.versionclass == PackageVersionClass.ignored:
ignored_packages.append(package)
elif VersionCompare(package.version, bestversion) == 0:
repos_worth_showing.add(reponame)
# 3. Extract newest package from each repo
newest_packages = []
for reponame in repos_worth_showing:
for package in packages_by_repo[reponame]:
if package.versionclass != PackageVersionClass.ignored:
newest_packages.append(package)
break
# 4. Aggregate by versions
def VersionsDigest(version):
return {
'version': version['version'],
'families': set(map(lambda p: p.family, version['packages'])),
'class': version['packages'][0].versionclass,
}
versions = PackagesetAggregateByVersions(newest_packages)
metapackagedata[metapackagename] = {
'families': PackagesetToFamilies(packages),
'explicit': map(VersionsDigest, PackagesetAggregateByVersions(explicit_packages)),
'newest': map(VersionsDigest, filter(lambda v: v['packages'][0].versionclass == PackageVersionClass.newest, versions)),
'outdated': map(VersionsDigest, filter(lambda v: v['packages'][0].versionclass == PackageVersionClass.outdated, versions)),
'ignored': map(VersionsDigest, PackagesetAggregateByVersions(ignored_packages))
}
return metapackagedata
def metapackages_generic(bound, *filters, template='metapackages.html', repo=None, maintainer=None):
namefilter = bound_to_filter(bound)
# process search
search = flask.request.args.to_dict().get('search')
searchfilter = NameSubstringQueryFilter(search) if search else None
# get packages
packages = get_db().GetMetapackages(namefilter, InAnyRepoQueryFilter(reponames), searchfilter, *filters, limit=app.config['METAPACKAGES_PER_PAGE'])
# on empty result, fallback to show first, last set of results
if not packages:
if bound and bound.startswith('<'):
namefilter = NameStartingQueryFilter()
else:
namefilter = NameBeforeQueryFilter()
packages = get_db().GetMetapackages(namefilter, InAnyRepoQueryFilter(reponames), searchfilter, *filters, limit=app.config['METAPACKAGES_PER_PAGE'])
firstname, lastname = get_packages_name_range(packages)
metapackagedata = metapackages_to_data(PackagesToMetapackages(packages), repo, maintainer)
return flask.render_template(
template,
firstname=firstname,
lastname=lastname,
search=search,
metapackagedata=metapackagedata,
repo=repo,
maintainer=maintainer
)
@app.route('/')
def index():
repostats = [
repo for repo in get_db().GetRepositories()
if repo['name'] in reponames and repometadata[repo['name']]['type'] == 'repository'
]
top_repos = {
'by_total': [
{
'name': repo['name'],
'value': repo['num_metapackages'],
}
for repo in sorted(repostats, key=lambda repo: repo['num_metapackages'], reverse=True)
][:10],
'by_nonunique': [
{
'name': repo['name'],
'value': repo['num_metapackages_newest'] + repo['num_metapackages_outdated'],
}
for repo in sorted(repostats, key=lambda repo: repo['num_metapackages_newest'] + repo['num_metapackages_outdated'], reverse=True)
][:10],
'by_newest': [
{
'name': repo['name'],
'value': repo['num_metapackages_newest'],
}
for repo in sorted(repostats, key=lambda repo: repo['num_metapackages_newest'], reverse=True)
][:10],
'by_pnewest': [
{
'name': repo['name'],
'value': '{:.2f}%'.format(100.0 * repo['num_metapackages_newest'] / repo['num_metapackages'] if repo['num_metapackages'] else 0),
}
for repo in sorted(repostats, key=lambda repo: repo['num_metapackages_newest'] / (repo['num_metapackages'] or 1), reverse=True)
if repo['num_metapackages'] > 1000
][:8]
}
important_packages = [
'apache24',
'awesome',
'bash',
'binutils',
'bison',
'blender',
'boost',
'bzip2',
'chromium',
'claws-mail',
'cmake',
'cppcheck',
'cups',
'curl',
'darktable',
'dia',
'djvulibre',
'dosbox',
'dovecot',
'doxygen',
'dvd+rw-tools',
'emacs',
'exim',
'ffmpeg',
'firefox',
'flex',
'fluxbox',
'freecad',
'freetype',
'gcc',
'gdb',
'geeqie',
'gimp',
'git',
'gnupg',
'go',
'graphviz',
'grub',
'icewm',
'imagemagick',
'inkscape',
'irssi',
'kodi',
'lame',
'lftp',
'libreoffice',
'libressl',
'lighttpd',
'links',
'llvm',
'mariadb',
'maxima',
'mc',
'memcached',
'mercurial',
'mesa',
'mplayer',
'mutt',
'mysql',
'nginx',
'nmap',
'octave',
'openbox',
'openssh',
'openssl',
'openttf',
'openvpn',
'p7zip',
'perl',
'pidgin',
'postfix',
'postgresql',
'privoxy',
'procmail',
'python3',
'qemu',
'rdesktop',
'redis',
'rrdtool',
'rsync',
'rtorrent',
'rxvt-unicode',
'samba',
'sane-backends',
'scons',
'screen',
'scribus',
'scummvm',
'sdl2',
'smartmontools',
'sqlite3',
'squid',
'subversion',
'sudo',
'sumversion',
'thunderbird',
'tigervnc',
'tmux',
'tor',
'valgrind',
'vim',
'virtualbox',
'vlc',
'vsftpd',
'wayland',
'wesnoth',
'wget',
'wine',
'wireshark',
'xorg-server',
'youtube-dl',
'zsh',
]
packages = get_db().GetMetapackage(important_packages)
metapackagedata = metapackages_to_data(PackagesToMetapackages(packages))
return flask.render_template(
'index.html',
top_repos=top_repos,
metapackagedata=metapackagedata
)
@app.route('/metapackages/') # XXX: redirect to metapackages/all?
@app.route('/metapackages/all/')
@app.route('/metapackages/all/<bound>/')
def metapackages_all(bound=None):
return metapackages_generic(
bound,
template='metapackages-all.html'
)
@app.route('/metapackages/unique/')
@app.route('/metapackages/unique/<bound>/')
def metapackages_unique(bound=None):
return metapackages_generic(
bound,
InNumFamiliesQueryFilter(less=1),
template='metapackages-unique.html'
)
@app.route('/metapackages/widespread/')
@app.route('/metapackages/widespread/<bound>/')
def metapackages_widespread(bound=None):
return metapackages_generic(
bound,
InNumFamiliesQueryFilter(more=10),
template='metapackages-widespread.html'
)
@app.route('/metapackages/in-repo/<repo>/')
@app.route('/metapackages/in-repo/<repo>/<bound>/')
def metapackages_in_repo(repo, bound=None):
if not repo or repo not in repometadata:
flask.abort(404)
return metapackages_generic(
bound,
InRepoQueryFilter(repo),
template='metapackages-in-repo.html',
repo=repo,
)
@app.route('/metapackages/outdated-in-repo/<repo>/')
@app.route('/metapackages/outdated-in-repo/<repo>/<bound>/')
def metapackages_outdated_in_repo(repo, bound=None):
if not repo or repo not in repometadata:
flask.abort(404)
return metapackages_generic(
bound,
OutdatedInRepoQueryFilter(repo),
template='metapackages-outdated-in-repo.html',
repo=repo,
)
@app.route('/metapackages/not-in-repo/<repo>/')
@app.route('/metapackages/not-in-repo/<repo>/<bound>/')
def metapackages_not_in_repo(repo, bound=None):
if not repo or repo not in repometadata:
flask.abort(404)
return metapackages_generic(
bound,
NotInRepoQueryFilter(repo),
template='metapackages-not-in-repo.html',
repo=repo,
)
@app.route('/metapackages/candidates-for-repo/<repo>/')
@app.route('/metapackages/candidates-for-repo/<repo>/<bound>/')
def metapackages_candidates_for_repo(repo, bound=None):
if not repo or repo not in repometadata:
flask.abort(404)
return metapackages_generic(
bound,
NotInRepoQueryFilter(repo),
InNumFamiliesQueryFilter(more=5),
template='metapackages-candidates-for-repo.html',
repo=repo,
)
@app.route('/metapackages/unique-in-repo/<repo>/')
@app.route('/metapackages/unique-in-repo/<repo>/<bound>/')
def metapackages_unique_in_repo(repo, bound=None):
if not repo or repo not in repometadata:
flask.abort(404)
return metapackages_generic(
bound,
InRepoQueryFilter(repo),
InNumFamiliesQueryFilter(less=1),
template='metapackages-unique-in-repo.html',
repo=repo,
)
@app.route('/metapackages/by-maintainer/<maintainer>/')
@app.route('/metapackages/by-maintainer/<maintainer>/<bound>/')
def metapackages_by_maintainer(maintainer, bound=None):
return metapackages_generic(
bound,
MaintainerQueryFilter(maintainer),
template='metapackages-by-maintainer.html',
maintainer=maintainer,
)
@app.route('/metapackages/outdated-by-maintainer/<maintainer>/')
@app.route('/metapackages/outdated-by-maintainer/<maintainer>/<bound>/')
def metapackages_outdated_by_maintainer(maintainer, bound=None):
return metapackages_generic(
bound,
MaintainerOutdatedQueryFilter(maintainer),
template='metapackages-outdated-by-maintainer.html',
maintainer=maintainer,
)
@app.route('/maintainers/')
@app.route('/maintainers/<bound>/')
def maintainers(bound=None):
reverse = False
if bound and bound.startswith('..'):
bound = bound[2:]
reverse = True
elif bound and bound.endswith('..'):
bound = bound[:-2]
search = flask.request.args.to_dict().get('search')
minmaintainer, maxmaintainer = get_db().GetMaintainersRange()
maintainers = get_db().GetMaintainers(bound, reverse, search, app.config['MAINTAINERS_PER_PAGE'])
firstpage, lastpage = False, False
for maintainer in maintainers:
if maintainer['maintainer'] == minmaintainer:
firstpage = True
if maintainer['maintainer'] == maxmaintainer:
lastpage = True
return flask.render_template(
'maintainers.html',
search=search,
minmaintainer=minmaintainer,
maxmaintainer=maxmaintainer,
firstpage=firstpage,
lastpage=lastpage,
maintainers=maintainers
)
@app.route('/maintainer/<maintainer>')
def maintainer(maintainer):
maintainer_info = get_db().GetMaintainerInformation(maintainer)
metapackages = get_db().GetMaintainerMetapackages(maintainer, 500)
similar_maintainers = get_db().GetMaintainerSimilarMaintainers(maintainer, 50)
numproblems = get_db().GetProblemsCount(maintainer=maintainer)
if not maintainer_info:
flask.abort(404)
return flask.render_template(
'maintainer.html',
numproblems=numproblems,
maintainer=maintainer,
maintainer_info=maintainer_info,
metapackages=metapackages,
similar_maintainers=similar_maintainers
)
@app.route('/maintainer/<maintainer>/problems')
def maintainer_problems(maintainer):
return flask.render_template(
'maintainer-problems.html',
maintainer=maintainer,
problems=get_db().GetProblems(
maintainer=maintainer,
limit=app.config['PROBLEMS_PER_PAGE']
)
)
@app.route('/repositories/')
def repositories():
return flask.render_template('repositories.html')
@app.route('/repository/<repo>')
def repository(repo):
if not repo or repo not in repometadata:
flask.abort(404)
return flask.render_template(
'repository.html',
repo=repo,
repo_info=get_db().GetRepository(repo)
)
@app.route('/repository/<repo>/problems')
def repository_problems(repo):
if not repo or repo not in repometadata:
flask.abort(404)
return flask.render_template('repository-problems.html', repo=repo, problems=get_db().GetProblems(repo=repo, limit=app.config['PROBLEMS_PER_PAGE']))
@app.route('/metapackage/<name>')
def metapackage(name):
# metapackage landing page; just redirect to packages, may change in future
return flask.redirect(flask.url_for('metapackage_versions', name=name), 303)
@app.route('/metapackage/<name>/versions')
def metapackage_versions(name):
packages_by_repo = {}
for package in get_db().GetMetapackage(name):
if package.repo not in packages_by_repo:
packages_by_repo[package.repo] = []
packages_by_repo[package.repo].append(package)
for repo, packages in packages_by_repo.items():
packages_by_repo[repo] = PackagesetSortByVersions(packages)
return flask.render_template(
'metapackage-versions.html',
reponames_absent=[reponame for reponame in reponames if reponame not in packages_by_repo],
packages_by_repo=packages_by_repo,
name=name
)
@app.route('/metapackage/<name>/packages')
def metapackage_packages(name):
packages = get_db().GetMetapackage(name)
packages = sorted(packages, key=lambda package: package.repo + package.name + package.version)
return flask.render_template(
'metapackage-packages.html',
packages=packages,
name=name,
link_statuses=get_db().GetMetapackageLinkStatuses(name)
)
@app.route('/metapackage/<name>/information')
def metapackage_information(name):
packages = get_db().GetMetapackage(name)
packages = sorted(packages, key=lambda package: package.repo + package.name + package.version)
information = {}
def append_info(infokey, infoval, package):
if infokey not in information:
information[infokey] = {}
if infoval not in information[infokey]:
information[infokey][infoval] = set()
information[infokey][infoval].add(package.family)
for package in packages:
append_info('names', package.name, package)
append_info('versions', package.version, package)
append_info('repos', package.repo, package)
if package.comment:
append_info('summaries', package.comment, package)
for maintainer in package.maintainers:
append_info('maintainers', maintainer, package)
if package.category:
append_info('categories', package.category, package)
if package.homepage:
append_info('homepages', package.homepage, package)
for download in package.downloads:
append_info('downloads', download, package)
versions = PackagesetAggregateByVersions(packages)
for version in versions:
version['families'] = list(sorted(PackagesetToFamilies(version['packages'])))
return flask.render_template(
'metapackage-information.html',
information=information,
versions=versions,
name=name,
link_statuses=get_db().GetMetapackageLinkStatuses(name)
)
@app.route('/metapackage/<name>/related')
def metapackage_related(name):
names = get_db().GetRelatedMetapackages(name, limit=app.config['METAPACKAGES_PER_PAGE'])
too_many_warning = None
if len(names) == app.config['METAPACKAGES_PER_PAGE']:
too_many_warning = app.config['METAPACKAGES_PER_PAGE']
packages = get_db().GetMetapackage(names)
metapackagedata = metapackages_to_data(PackagesToMetapackages(packages))
return flask.render_template(
'metapackage-related.html',
name=name,
metapackagedata=metapackagedata,
too_many_warning=too_many_warning
)
@app.route('/metapackage/<name>/badges')
def metapackage_badges(name):
packages = get_db().GetMetapackage(name)
repos = sorted(list(set([package.repo for package in packages])))
return flask.render_template('metapackage-badges.html', name=name, repos=repos)
@app.route('/metapackage/<name>/report', methods=['GET', 'POST'])
def metapackage_report(name):
if flask.request.method == 'POST':
if get_db().GetReportsCount(name) >= app.config['MAX_REPORTS']:
flask.flash('Could not add report: too many reports for this metapackage', 'danger')
return flask.redirect(flask.url_for('metapackage_report', name=name))
need_verignore = 'need_verignore' in flask.request.form
need_split = 'need_split' in flask.request.form
need_merge = 'need_merge' in flask.request.form
comment = flask.request.form.get('comment', '').strip().replace('\r', '') or None
if comment and len(comment) > 1024:
flask.flash('Could not add report: comment os too long', 'danger')
return flask.redirect(flask.url_for('metapackage_report', name=name))
if not need_verignore and not need_split and not need_merge and not comment:
flask.flash('Could not add report: please fill out the form', 'danger')
return flask.redirect(flask.url_for('metapackage_report', name=name))
if '<a href' in comment:
flask.flash('Spammers not welcome, HTML not allowed', 'danger')
return flask.redirect(flask.url_for('metapackage_report', name=name))
get_db().AddReport(
name,
need_verignore,
need_split,
need_merge,
comment
)
flask.flash('Report for {} added succesfully and will be processed in a few days, thank you!'.format(name), 'success')
return flask.redirect(flask.url_for('metapackage_report', name=name))
return flask.render_template(
'metapackage-report.html',
reports=get_db().GetReports(name),
name=name,
afk_till=AFKChecker(app.config['STAFF_AFK']).GetAFKEnd()
)
@app.route('/badge/vertical-allrepos/<name>.svg')
def badge_vertical_allrepos(name):
summaries = PackagesetToSummaries(get_db().GetMetapackage(name))
repostates = []
for reponame, summary in summaries.items():
repostates.append({
'name': repometadata[reponame]['desc'],
'version': summary['version'],
'versionclass': summary['versionclass']
})
return (
flask.render_template(
'badge-vertical.svg',
repositories=sorted(repostates, key=lambda repo: repo['name']),
name=name
),
{'Content-type': 'image/svg+xml'}
)
@app.route('/badge/tiny-repos/<name>.svg')
def badge_tiny_repos(name):
num_families = len(set([package.family for package in get_db().GetMetapackage(name)]))
return (
flask.render_template(
'badge-tiny.svg',
name=name,
num_families=num_families
),
{'Content-type': 'image/svg+xml'}
)
@app.route('/badge/version-for-repo/<repo>/<name>.svg')
def badge_version_for_repo(repo, name):
summaries = PackagesetToSummaries(get_db().GetMetapackage(name))
if repo not in summaries:
flask.abort(404)
return (
flask.render_template(
'badge-tiny-version.svg',
repo=repo,
version=summaries[repo]['version'],
versionclass=summaries[repo]['versionclass'],
),
{'Content-type': 'image/svg+xml'}
)
@app.route('/news')
def news():
return flask.render_template('news.html')
@app.route('/links')
def links():
return flask.render_template('links.html')
@app.route('/about')
def about():
return flask.render_template('about.html')
@app.route('/opensearch/metapackage.xml')
def opensearch_metapackage():
return flask.render_template('opensearch-metapackage.xml'), {'Content-type': 'application/xml'}
@app.route('/opensearch/maintainer.xml')
def opensearch_maintainer():
return flask.render_template('opensearch-maintainer.xml'), {'Content-type': 'application/xml'}
@app.route('/statistics')
@app.route('/statistics/<sorting>')
def statistics(sorting=None):
repostats = filter(lambda r: r['name'] in reponames, get_db().GetRepositories())
showmedals = True
if sorting == 'newest':
repostats = sorted(repostats, key=lambda s: s['num_metapackages_newest'], reverse=True)
elif sorting == 'pnewest':
repostats = sorted(repostats, key=lambda s: s['num_metapackages_newest'] / (s['num_metapackages'] or 1), reverse=True)
elif sorting == 'outdated':
repostats = sorted(repostats, key=lambda s: s['num_metapackages_outdated'], reverse=True)
elif sorting == 'poutdated':
repostats = sorted(repostats, key=lambda s: s['num_metapackages_outdated'] / (s['num_metapackages'] or 1), reverse=True)
elif sorting == 'total':
repostats = sorted(repostats, key=lambda s: s['num_metapackages'], reverse=True)
else:
sorting = 'name'
repostats = sorted(repostats, key=lambda s: s['name'])
showmedals = False
return flask.render_template(
'statistics.html',
sorting=sorting,
repostats=repostats,
showmedals=showmedals,
repostats_old={}, # {repo['name']: repo for repo in get_db().GetRepositoriesHistoryAgo(60 * 60 * 24 * 7)},
num_metapackages=get_db().GetMetapackagesCount()
)
def graph_generic(getgraph, color, suffix=''):
# use autoscaling until history is filled
numdays = 21
width = 1140
height = 400
gwidth = width - 50
gheight = height - 20
period = 60 * 60 * 24 * numdays
graph = getgraph(period)
return (
flask.render_template(
'graph.svg',
width=width,
height=height,
gwidth=gwidth,
gheight=gheight,
points=graph.GetPoints(period),
yticks=graph.GetYTicks(suffix),
color=color,
numdays=numdays,
x=lambda x: int((1.0 - x) * gwidth) + 0.5,
y=lambda y: int(10.0 + (1.0 - y) * (gheight - 20.0)) + 0.5,
),
{'Content-type': 'image/svg+xml'}
)
def graph_repo_generic(repo, getvalue, color, suffix=''):
if repo not in reponames:
flask.abort(404)
def GetGraph(period):
graph = GraphProcessor()
for histentry in get_db().GetRepositoriesHistoryPeriod(period, repo):
try:
graph.AddPoint(histentry['timedelta'], getvalue(histentry['snapshot']))
except:
pass # ignore missing keys, division errors etc.
return graph
return graph_generic(GetGraph, color, suffix)
def graph_total_generic(getvalue, color, suffix=''):
def GetGraph(period):
graph = GraphProcessor()
for histentry in get_db().GetStatisticsHistoryPeriod(period):
try:
graph.AddPoint(histentry['timedelta'], getvalue(histentry['snapshot']))
except:
pass # ignore missing keys, division errors etc.
return graph
return graph_generic(GetGraph, color, suffix)
@app.route('/graph/repo/<repo>/metapackages_total.svg')
def graph_repo_metapackages_total(repo):
return graph_repo_generic(repo, lambda s: s['num_metapackages'], '#000000')
@app.route('/graph/repo/<repo>/metapackages_newest.svg')
def graph_repo_metapackages_newest(repo):
return graph_repo_generic(repo, lambda s: s['num_metapackages_newest'], '#5cb85c')
@app.route('/graph/repo/<repo>/metapackages_newest_percent.svg')
def graph_repo_metapackages_newest_percent(repo):
return graph_repo_generic(repo, lambda s: s['num_metapackages_newest'] / s['num_metapackages'] * 100.0, '#5cb85c', '%')
@app.route('/graph/repo/<repo>/metapackages_outdated.svg')
def graph_repo_metapackages_outdated(repo):
return graph_repo_generic(repo, lambda s: s['num_metapackages_outdated'], '#d9534f')
@app.route('/graph/repo/<repo>/metapackages_outdated_percent.svg')
def graph_repo_metapackages_outdated_percent(repo):
return graph_repo_generic(repo, lambda s: s['num_metapackages_outdated'] / s['num_metapackages'] * 100.0, '#d9534f', '%')
@app.route('/graph/repo/<repo>/metapackages_unique.svg')
def graph_repo_metapackages_unique(repo):
return graph_repo_generic(repo, lambda s: s['num_metapackages_unique'], '#5bc0de')
@app.route('/graph/repo/<repo>/metapackages_unique_percent.svg')
def graph_repo_metapackages_unique_percent(repo):
return graph_repo_generic(repo, lambda s: s['num_metapackages_unique'] / s['num_metapackages'] * 100.0, '#5bc0de', '%')
@app.route('/graph/repo/<repo>/problems.svg')
def graph_repo_problems(repo):
return graph_repo_generic(repo, lambda s: s['num_problems'], '#c00000')
@app.route('/graph/repo/<repo>/problems_per_metapackage.svg')
def graph_repo_problems_per_metapackage(repo):
return graph_repo_generic(repo, lambda s: s['num_problems'] / s['num_metapackages'], '#c00000')
@app.route('/graph/repo/<repo>/maintainers.svg')
def graph_repo_maintainers(repo):
return graph_repo_generic(repo, lambda s: s['num_maintainers'], '#c000c0')
@app.route('/graph/repo/<repo>/packages_per_maintainer.svg')
def graph_repo_packages_per_maintainer(repo):
return graph_repo_generic(repo, lambda s: s['num_packages'] / s['num_maintainers'], '#c000c0')
@app.route('/graph/total/packages.svg')