You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2019/10/14 21:00:10 UTC

[allura] 05/09: [#8336] Remove more old unused code

This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch db/8336
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 5e6ee32ee2016bc656fd9192ceca2dbae5a23479
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Fri Oct 11 17:23:53 2019 -0400

    [#8336] Remove more old unused code
---
 Allura/allura/model/stats.py                     |  88 ---------------
 Allura/allura/scripts/remove_duplicate_troves.py | 130 -----------------------
 2 files changed, 218 deletions(-)

diff --git a/Allura/allura/model/stats.py b/Allura/allura/model/stats.py
index cbb71dd..0928f51 100644
--- a/Allura/allura/model/stats.py
+++ b/Allura/allura/model/stats.py
@@ -87,44 +87,6 @@ class Stats(MappedClass):
         min_date = config.get('userstats.start_date', '0001-1-1')
         return max(datetime.strptime(min_date, '%Y-%m-%d'), self.registration_date)
 
-    def getCodeContribution(self):
-        days = (datetime.today() - self.start_date).days
-        if not days:
-            days = 1
-        for val in self['general']:
-            if val['category'] is None:
-                for commits in val['commits']:
-                    if commits['language'] is None:
-                        if days > 30:
-                            return round(float(commits.lines) / days * 30, 2)
-                        else:
-                            return float(commits.lines)
-        return 0
-
-    def getDiscussionContribution(self):
-        days = (datetime.today() - self.start_date).days
-        if not days:
-            days = 1
-        for val in self['general']:
-            if val['category'] is None:
-                for artifact in val['messages']:
-                    if artifact['messagetype'] is None:
-                        tot = artifact.created + artifact.modified
-                        if days > 30:
-                            return round(float(tot) / days * 30, 2)
-                        else:
-                            return float(tot)
-        return 0
-
-    def getTicketsContribution(self):
-        for val in self['general']:
-            if val['category'] is None:
-                tickets = val['tickets']
-                if tickets.assigned == 0:
-                    return 0
-                return round(float(tickets.solved) / tickets.assigned, 2)
-        return 0
-
     def getCommits(self, category=None):
         i = getElementIndex(self.general, category=category)
         if i is None:
@@ -183,17 +145,6 @@ class Stats(MappedClass):
             by_cat[cat] = dict(number=n, lines=lines)
         return by_cat
 
-    # For the moment, commit stats by language are not used, since each project
-    # can be linked to more than one programming language and we don't know how
-    # to which programming language should be credited a line of code modified
-    # within a project including two or more languages.
-    def getCommitsByLanguage(self):
-        i = getElementIndex(self.general, category=None)
-        if i is None:
-            return dict(number=0, lines=0)
-        return dict([(el.language, dict(lines=el.lines, number=el.number))
-                     for el in self.general[i].commits])
-
     def getArtifactsByCategory(self, detailed=False):
         from allura.model.project import TroveCategory
 
@@ -268,25 +219,6 @@ class Stats(MappedClass):
             by_cat[cat] = dict(number=n, lines=lines)
         return by_cat
 
-    def getLastMonthCommitsByLanguage(self):
-        from allura.model.project import TroveCategory
-
-        self.checkOldArtifacts()
-        seen = set()
-        langlist = [el.language for el in self.general
-                    if el.language not in seen and not seen.add(el.language)]
-
-        by_lang = {}
-        for lang in langlist:
-            lineslist = [el.lines for el in self.lastmonth.commits
-                         if lang in el.programming_languages + [None]]
-            n = len(lineslist)
-            lines = sum(lineslist)
-            if lang != None:
-                lang = TroveCategory.query.get(_id=lang)
-            by_lang[lang] = dict(number=n, lines=lines)
-        return by_lang
-
     def getLastMonthArtifacts(self, category=None, art_type=None):
         self.checkOldArtifacts()
         cre, mod = reduce(
@@ -316,26 +248,6 @@ class Stats(MappedClass):
             by_type[t] = dict(created=cre, modified=mod)
         return by_type
 
-    def getLastMonthArtifactsByCategory(self):
-        from allura.model.project import TroveCategory
-
-        self.checkOldArtifacts()
-        seen = set()
-        catlist = [el.category for el in self.general
-                   if el.category not in seen and not seen.add(el.category)]
-
-        by_cat = {}
-        for cat in catlist:
-            cre, mod = reduce(
-                addtuple,
-                [(int(el.created), 1 - int(el.created))
-                 for el in self.lastmonth.messages
-                 if cat in el.categories + [None]], (0, 0))
-            if cat != None:
-                cat = TroveCategory.query.get(_id=cat)
-            by_cat[cat] = dict(created=cre, modified=mod)
-        return by_cat
-
     def getLastMonthTickets(self, category=None):
         from allura.model.project import TroveCategory
 
diff --git a/Allura/allura/scripts/remove_duplicate_troves.py b/Allura/allura/scripts/remove_duplicate_troves.py
deleted file mode 100644
index 7866b2e..0000000
--- a/Allura/allura/scripts/remove_duplicate_troves.py
+++ /dev/null
@@ -1,130 +0,0 @@
-#       Licensed to the Apache Software Foundation (ASF) under one
-#       or more contributor license agreements.  See the NOTICE file
-#       distributed with this work for additional information
-#       regarding copyright ownership.  The ASF licenses this file
-#       to you under the Apache License, Version 2.0 (the
-#       "License"); you may not use this file except in compliance
-#       with the License.  You may obtain a copy of the License at
-#
-#         http://www.apache.org/licenses/LICENSE-2.0
-#
-#       Unless required by applicable law or agreed to in writing,
-#       software distributed under the License is distributed on an
-#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-#       KIND, either express or implied.  See the License for the
-#       specific language governing permissions and limitations
-#       under the License.
-
-import argparse
-import logging
-from itertools import groupby
-from collections import defaultdict
-from operator import itemgetter
-
-from ming.odm import ThreadLocalORMSession
-
-from allura.scripts import ScriptTask
-from allura import model as M
-
-
-log = logging.getLogger(__name__)
-
-
-class RemoveDuplicateTroves(ScriptTask):
-    
-    trove_types = [
-        'trove_root_database',
-        'trove_developmentstatus',
-        'trove_audience',
-        'trove_license',
-        'trove_os',
-        'trove_language',
-        'trove_topic',
-        'trove_natlanguage',
-        'trove_environment',
-    ]
-
-    @classmethod
-    def execute(cls, options):
-        duplicates = cls._find_duplicates()
-        log.info('Found %s duplicate categories: %s', len(duplicates), duplicates.keys())
-        for name, dups in duplicates.iteritems():
-            projects_with_category = {}
-            for dup in dups:
-                projects = cls._projects_with_category(dup._id)
-                projects_with_category[dup._id] = projects
-            log.info('Following projects are using category %s:', name)
-            for _id, ps in projects_with_category.iteritems():
-                log.info('  with id %s: %s', _id, [p.shortname for p in ps])
-            priority = [(i, len(ps)) for i, ps in projects_with_category.items()]
-            priority = sorted(priority, key=itemgetter(1), reverse=True)
-            priority = [p[0] for p in priority]
-            live, kill = priority[0], priority[1:]
-            log.info('%s will live %s will die', live, kill)
-            if sum([len(projects_with_category[_id]) for _id in kill]) > 0:
-                # Duplicates are used somewhere, need to reasign for all projects that use them
-                projects = []
-                ids_to_kill = set(kill)
-                for p in [projects_with_category[_id] for _id in kill]:
-                    projects.extend(p)
-                for p in projects:
-                    for tt in cls.trove_types:
-                        _ids = ids_to_kill.intersection(getattr(p, tt))
-                        for _id in _ids:
-                            log.info('Removing %s from %s.%s and adding %s instead', _id, p.shortname, tt, live)
-                            if not options.dry_run:
-                                getattr(p, tt).remove(_id)
-                                getattr(p, tt).append(live)
-            log.info('Removing categories %s', kill)
-            if not options.dry_run:
-                M.TroveCategory.query.remove({'_id': {'$in': kill}})
-            ThreadLocalORMSession.flush_all()
-
-    @classmethod
-    def _find_duplicates(cls):
-        dups = []
-        agpl = M.TroveCategory.query.find({'shortname': 'agpl'}).all()
-        if len(agpl) > 1:
-            # agpl is present twice with different cat_id
-            # (update in creation command updated only one of duplicates),
-            # so code below will not catch it
-            dups.extend(agpl)
-        for cat in M.TroveCategory.query.find():
-            if M.TroveCategory.query.find({
-                'shortname': cat.shortname,
-                'trove_cat_id': cat.trove_cat_id,
-                'trove_parent_id': cat.trove_parent_id,
-                'fullname': cat.fullname,
-                'fullpath': cat.fullpath,
-            }).count() > 1:
-                dups.append(cat)
-        result = defaultdict(list)
-        for k, v in groupby(dups, lambda x: x.shortname):
-            result[k].extend(list(v))
-        return result
-
-    @classmethod
-    def _projects_with_category(cls, _id):
-        p = M.Project.query.find({'$or': [
-            {'trove_root_database': _id},
-            {'trove_developmentstatus': _id},
-            {'trove_audience': _id},
-            {'trove_license': _id},
-            {'trove_os': _id},
-            {'trove_language': _id},
-            {'trove_topic': _id},
-            {'trove_natlanguage': _id},
-            {'trove_environment':_id},
-        ]})
-        return p.all()
-
-    @classmethod
-    def parser(cls):
-        parser = argparse.ArgumentParser(description='Remove duplicate troves')
-        parser.add_argument('--dry-run', action='store_true', dest='dry_run',
-                            default=False, help='Print what will be changed but do not change anything')
-        return parser
-
-
-if __name__ == '__main__':
-    RemoveDuplicateTroves.main()