コード例 #1
0
ファイル: bugs.py プロジェクト: KenjiTakahashi/intranet
    def get_project(self, project, resolved=False, credentials=None):
        """
        Get bugs for given project
        """
        start = time()
        bugs = []
        tracker = project.tracker
        credentials = credentials or self._get_credentials(tracker.id)

        if not credentials:
            return []

        login_mapping = TrackerCredentials.get_logins_mapping(tracker)
        fetcher = get_fetcher(tracker, credentials, login_mapping)
        (fetcher.fetch_resolved_bugs_for_query if resolved else fetcher.fetch_bugs_for_query)(*project.get_selector_tuple())

        while True:
            if fetcher.isReady():
                if fetcher.error:
                    WARN(u"Could not fetch bugs from tracker %s: %s" % (tracker.name, fetcher.error))
                    flash(u"Could not fetch bugs from tracker %s" % (tracker.name, ))
                else:
                    for bug in fetcher:
                        bug.project = project
                        bugs.append(bug)
                break
            elif time() - start > MAX_TIMEOUT:
                WARN(u"Fetchers for tracker %s timed-out" % (tracker.name, ))
                flash(u"Getting bugs from tracker %s timed out" % (tracker.name, ))
            else:
                sleep(0.1)

        bugs = self.add_time(bugs)
        return bugs
コード例 #2
0
ファイル: bugs.py プロジェクト: rutral/intranet
    def get_project(self, project, resolved=False, credentials=None):
        """
        Get bugs for given project
        """
        start = time()
        bugs = []
        tracker = project.tracker
        credentials = credentials or self._get_credentials(tracker.id)

        if not credentials:
            return []

        login_mapping = TrackerCredentials.get_logins_mapping(tracker)
        fetcher = get_fetcher(tracker, credentials, login_mapping)
        (fetcher.fetch_resolved_bugs_for_query if resolved else fetcher.fetch_bugs_for_query)(*project.get_selector_tuple())

        while True:
            if fetcher.isReady():
                if fetcher.error:
                    WARN(u"Could not fetch bugs from tracker %s: %s" % (tracker.name, fetcher.error))
                    flash(u"Could not fetch bugs from tracker %s" % (tracker.name, ))
                else:
                    for bug in fetcher:
                        bug.project = project
                        bugs.append(bug)
                break
            elif time() - start > MAX_TIMEOUT:
                WARN(u"Fetchers for tracker %s timed-out" % (tracker.name, ))
                flash(u"Getting bugs from tracker %s timed out" % (tracker.name, ))
            else:
                sleep(0.1)

        bugs = self.add_time(bugs)
        return bugs
コード例 #3
0
ファイル: bugs.py プロジェクト: pytlakp/intranet-1
 def _get_bugs(self, fetcher_callback, full_mapping=True):
     start = time()
     fetchers = []
     creds_q = DBSession.query(Tracker, TrackerCredentials)\
                        .filter(Tracker.id==TrackerCredentials.tracker_id)\
                        .filter(TrackerCredentials.user_id==self.user.id)
     for tracker, credentials in creds_q:
         if full_mapping:
             mapping = TrackerCredentials.get_logins_mapping(tracker)
         else:
             mapping = {credentials.login.lower(): self.user}
         fetcher = get_fetcher(tracker, credentials, mapping)
         fetchers.append(fetcher)
         fetcher_callback(fetcher)  # initialize query
     bugs = []
     while fetchers:
         for i, fetcher in enumerate(fetchers):
             if fetcher.isReady():
                 fetchers.pop(i)
                 if fetcher.error:
                     WARN(u"Could not fetch bugs from tracker %s: %s" %
                          (fetcher.tracker.name, fetcher.error))
                     flash(u"Could not fetch bugs from tracker %s" %
                           (fetcher.tracker.name, ))
                 else:
                     for bug in fetcher:
                         bugs.append(bug)
                 break
         else:
             # no fetcher is yet ready, give them time
             if time() - start > MAX_TIMEOUT:
                 WARN(u"Fetchers for trackers %s timed-out" %
                      (u', '.join(fetcher.tracker.name
                                  for fetcher in fetchers)))
                 for fetcher in fetchers:
                     pass
                     flash(u"Getting bugs from tracker %s timed out" %
                           (fetcher.tracker.name, ))
                 fetchers = []
             else:
                 sleep(0.1)
                 # all bugs were fetched, time to resolve their projects
     projects = {}
     for bug in bugs:
         projects[bug.project_id] = None
         # query for all project id's
     projects = dict((project.id, project)
                     for project in Project.query.filter(
                         Project.id.in_(projects.keys())))
     # now assign projects to bugs
     for bug in bugs:
         bug.project = projects.get(bug.project_id)
     return bugs
コード例 #4
0
ファイル: mail_fetcher.py プロジェクト: Rhenan/intranet-open
    def __call__(self, *args, **kwargs):
        config = ApplicationConfig.get_current_config(allow_empty=True)
        if config is None:
            WARN(u'Application config not found, emails cannot be checked')
            return
        trackers = dict(
            (tracker.mailer, tracker)
                for tracker in Tracker.query.filter(Tracker.mailer != None).filter(Tracker.mailer != '')
        )
        if not len(trackers):
            WARN(u'No trackers have mailers configured, email will not be checked')
            return

        username = config.google_user_email.encode('utf-8')
        password = config.google_user_password.encode('utf-8')

        # TODO
        logins_mappings = dict(
            (tracker.id, TrackerCredentials.get_logins_mapping(tracker))
                for tracker in trackers.itervalues()
        )
        selector_mappings = dict(
            (tracker.id, SelectorMapping(tracker))
                for tracker in trackers.itervalues()
        )

        # find all projects connected to the tracker
        projects = dict(
            (project.id, project)
                for project in Project.query.all()
        )

        # all pre-conditions should be checked by now

        # start fetching
        fetcher = MailFetcher(
            username,
            password,
        )

        # ok, we have all mails, lets create timeentries from them
        extractor = TimeEntryMailExtractor(
            trackers,
            logins_mappings,
            projects,
            selector_mappings,
        )

        for msg in fetcher:
            timeentry = extractor.get(msg)
            if timeentry:
                DBSession.add(timeentry)
        transaction.commit()
コード例 #5
0
    def __call__(self, *args, **kwargs):
        config = ApplicationConfig.get_current_config(allow_empty=True)
        if config is None:
            WARN(u'Application config not found, emails cannot be checked')
            return
        trackers = dict(
            (tracker.mailer, tracker) for tracker in Tracker.query.filter(
                Tracker.mailer != None).filter(Tracker.mailer != ''))
        if not len(trackers):
            WARN(
                u'No trackers have mailers configured, email will not be checked'
            )
            return

        username = config.google_user_email.encode('utf-8')
        password = config.google_user_password.encode('utf-8')

        # TODO
        logins_mappings = dict(
            (tracker.id, TrackerCredentials.get_logins_mapping(tracker))
            for tracker in trackers.itervalues())
        selector_mappings = dict((tracker.id, SelectorMapping(tracker))
                                 for tracker in trackers.itervalues())

        # find all projects connected to the tracker
        projects = dict(
            (project.id, project) for project in Project.query.all())

        # all pre-conditions should be checked by now

        # start fetching
        fetcher = MailFetcher(
            username,
            password,
        )

        # ok, we have all mails, lets create timeentries from them
        extractor = TimeEntryMailExtractor(
            trackers,
            logins_mappings,
            projects,
            selector_mappings,
        )

        for msg in fetcher:
            timeentry = extractor.get(msg)
            if timeentry:
                DBSession.add(timeentry)
        transaction.commit()
コード例 #6
0
ファイル: bugs.py プロジェクト: woliveira0101/intranet-open
    def _get_bugs(self, fetcher_callback, full_mapping=True):
        fetchers = []
        creds_q = DBSession.query(Tracker, TrackerCredentials, User)\
                           .filter(Tracker.id==TrackerCredentials.tracker_id) \
                           .filter(User.id==TrackerCredentials.user_id)\
                           .filter(TrackerCredentials.user_id==self.user.id).all()

        for tracker, credentials, user in creds_q:
            if full_mapping:
                mapping = TrackerCredentials.get_logins_mapping(tracker)
            else:
                mapping = {credentials.login.lower(): self.user}
            fetcher = get_fetcher(tracker, credentials, user, mapping)
            fetchers.append(fetcher)
            fetcher_callback(fetcher)  # initialize query
        bugs = []

        for fetcher in fetchers:
            try:
                fbugs = fetcher.get_result()
                bugs.extend(fbugs)
            except FetcherTimeout as e:
                flash(
                    'Fetchers for trackers %s timed-out' %
                    fetcher.tracker.name,
                    klass='error',
                )
            except FetcherBadDataError as e:
                flash(e, klass='error')
            except FetcherBaseException as e:
                flash(
                    'Could not fetch bugs from tracker %s' %
                    fetcher.tracker.name,
                    klass='error',
                )

        projects = {}
        for bug in bugs:
            projects[bug.project_id] = None
            # query for all project id's
        projects = dict((project.id, project)
                        for project in Project.query.filter(
                            Project.id.in_(projects.keys())))
        # now assign projects to bugs
        for bug in bugs:
            bug.project = projects.get(bug.project_id)
        return bugs
コード例 #7
0
ファイル: bugs.py プロジェクト: rutral/intranet
 def _get_bugs(self, fetcher_callback, full_mapping=True):
     start = time()
     fetchers = []
     creds_q = DBSession.query(Tracker, TrackerCredentials)\
                        .filter(Tracker.id==TrackerCredentials.tracker_id)\
                        .filter(TrackerCredentials.user_id==self.user.id)
     for tracker, credentials in creds_q:
         if full_mapping:
             mapping = TrackerCredentials.get_logins_mapping(tracker)
         else:
             mapping = {credentials.login.lower(): self.user}
         fetcher = get_fetcher(tracker, credentials, mapping)
         fetchers.append(fetcher)
         fetcher_callback(fetcher) # initialize query
     bugs = []
     while fetchers:
         for i, fetcher in enumerate(fetchers):
             if fetcher.isReady():
                 fetchers.pop(i)
                 if fetcher.error:
                     WARN(u"Could not fetch bugs from tracker %s: %s" % (fetcher.tracker.name, fetcher.error))
                     flash(u"Could not fetch bugs from tracker %s" % (fetcher.tracker.name, ))
                 else:
                     for bug in fetcher:
                         bugs.append(bug)
                 break
         else:
             # no fetcher is yet ready, give them time
             if time() - start > MAX_TIMEOUT:
                 WARN(u"Fetchers for trackers %s timed-out" % (u', '.join(fetcher.tracker.name for fetcher in fetchers)))
                 for fetcher in fetchers:
                     pass
                     flash(u"Getting bugs from tracker %s timed out" % (fetcher.tracker.name, ))
                 fetchers = []
             else:
                 sleep(0.1)
                 # all bugs were fetched, time to resolve their projects
     projects = {}
     for bug in bugs:
         projects[bug.project_id] = None
         # query for all project id's
     projects = dict((project.id, project) for project in Project.query.filter(Project.id.in_(projects.keys())))
     # now assign projects to bugs
     for bug in bugs:
         bug.project = projects.get(bug.project_id)
     return bugs
コード例 #8
0
ファイル: bugs.py プロジェクト: adamgr/intranet
    def get_sprint(self, sprint):
        bugs = memcache.get(SCRUM_BUG_CACHE_KEY % sprint.id)
        if bugs:
            return bugs
        query = self.request.db_session.query
        tracker, creds = query(Tracker, TrackerCredentials)\
                            .filter(TrackerCredentials.tracker_id==sprint.project.tracker_id)\
                            .filter(TrackerCredentials.tracker_id==Tracker.id)\
                            .filter(TrackerCredentials.user_id==self.user.id).one()
        mapping = TrackerCredentials.get_logins_mapping(tracker)
        fetcher = get_fetcher(tracker, creds, mapping)
        fetcher.fetch_scrum(sprint.name, sprint.project.project_selector)
        start = time()
        bugs = []
        while True:
            if fetcher.isReady():
                if fetcher.error:
                    ERROR(u"Fetcher for tracker %s failed with %r" % (tracker.name, fetcher.error))
                    break
                bugs = [ bug for bug in fetcher ]
                break
            else: # fetcher is not ready yet
                if time() - start > MAX_TIMEOUT:
                    ERROR(u'Request timed-out')
                    break
                else:
                    sleep(0.1)

        projects = {}
        for bug in bugs:
            projects[bug.project_id] = None
            # query for all project id's
        projects = dict((project.id, project) for project in Project.query.filter(Project.id.in_(projects.keys())))

        # now assign projects to bugs
        for bug in bugs:
            if bug.project_id:
                bug.project = projects.get(bug.project_id)
            else:
                bug.project_id = sprint.project_id
                bug.project = sprint.project

        bugs = self.add_time(bugs, sprint=sprint)
        memcache.set(SCRUM_BUG_CACHE_KEY % sprint.id, bugs, SCRUM_BUG_CACHE_TIMEOUT)
        return bugs
コード例 #9
0
ファイル: bugs.py プロジェクト: pytlakp/intranet-1
    def get_sprint(self, sprint):
        bugs = memcache.get(SCRUM_BUG_CACHE_KEY % sprint.id)
        if bugs:
            return bugs
        query = self.request.db_session.query
        tracker, creds = query(Tracker, TrackerCredentials)\
                            .filter(TrackerCredentials.tracker_id==sprint.project.tracker_id)\
                            .filter(TrackerCredentials.tracker_id==Tracker.id)\
                            .filter(TrackerCredentials.user_id==self.user.id).one()
        mapping = TrackerCredentials.get_logins_mapping(tracker)
        fetcher = get_fetcher(tracker, creds, mapping)
        fetcher.fetch_scrum(sprint.name, sprint.project.project_selector)
        start = time()
        bugs = []
        while True:
            if fetcher.isReady():
                if fetcher.error:
                    ERROR(u"Fetcher for tracker %s failed with %r" %
                          (tracker.name, fetcher.error))
                    break
                bugs = [bug for bug in fetcher]
                break
            else:  # fetcher is not ready yet
                if time() - start > MAX_TIMEOUT:
                    ERROR(u'Request timed-out')
                    break
                else:
                    sleep(0.1)

        projects = {}
        for bug in bugs:
            projects[bug.project_id] = None
            # query for all project id's
        projects = dict((project.id, project)
                        for project in Project.query.filter(
                            Project.id.in_(projects.keys())))

        # now assign projects to bugs
        for bug in bugs:
            bug.project = projects.get(bug.project_id)

        bugs = self.add_time(bugs, sprint=sprint)
        memcache.set(SCRUM_BUG_CACHE_KEY % sprint.id, bugs,
                     SCRUM_BUG_CACHE_TIMEOUT)
        return bugs
コード例 #10
0
ファイル: bugs.py プロジェクト: Rhenan/intranet-open
    def _get_bugs(self, fetcher_callback, full_mapping=True):
        fetchers = []
        creds_q = DBSession.query(Tracker, TrackerCredentials, User)\
                           .filter(Tracker.id==TrackerCredentials.tracker_id) \
                           .filter(User.id==TrackerCredentials.user_id)\
                           .filter(TrackerCredentials.user_id==self.user.id).all()

        for tracker, credentials, user in creds_q:
            if full_mapping:
                mapping = TrackerCredentials.get_logins_mapping(tracker)
            else:
                mapping = {credentials.login.lower(): self.user}
            fetcher = get_fetcher(tracker, credentials, user, mapping)
            fetchers.append(fetcher)
            fetcher_callback(fetcher) # initialize query
        bugs = []

        for fetcher in fetchers:
            try:
                fbugs = fetcher.get_result()
                bugs.extend(fbugs)
            except FetcherTimeout as e:
                flash(
                    'Fetchers for trackers %s timed-out' % fetcher.tracker.name,
                    klass='error',
                )
            except FetcherBadDataError as e:
                flash(e, klass='error')
            except FetcherBaseException as e:
                flash(
                    'Could not fetch bugs from tracker %s' % fetcher.tracker.name,
                    klass='error',
                )


        projects = {}
        for bug in bugs:
            projects[bug.project_id] = None
            # query for all project id's
        projects = dict((project.id, project) for project in Project.query.filter(Project.id.in_(projects.keys())))
        # now assign projects to bugs
        for bug in bugs:
            bug.project = projects.get(bug.project_id)
        return bugs
コード例 #11
0
ファイル: mail.py プロジェクト: KenjiTakahashi/intranet
    def _run(self):
        config = ApplicationConfig.get_current_config(allow_empty=True)
        if config is None:
            WARN(u'Application config not found, emails cannot be checked')
            return self.mark_not_busy()
        trackers = dict(
            (tracker.mailer, tracker)
                for tracker in Tracker.query.filter(Tracker.mailer != None).filter(Tracker.mailer != '')
        )
        if not len(trackers):
            WARN(u'No trackers have mailers configured, email will not be checked')
            return self.mark_not_busy()

        username = config.google_user_email.encode('utf-8')
        password = config.google_user_password.encode('utf-8')

        # TODO
        logins_mappings = dict(
            (tracker.id, TrackerCredentials.get_logins_mapping(tracker))
                for tracker in trackers.itervalues()
        )
        selector_mappings = dict(
            (tracker.id, SelectorMapping(tracker))
                for tracker in trackers.itervalues()
        )

        # find all projects connected to the tracker
        projects = dict(
            (project.id, project)
                for project in Project.query.all()
        )

        # all pre-conditions should be checked by now

        # start fetching
        f = CustomClientFactory(username, password, self.mark_not_busy,
            trackers, logins_mappings, projects, selector_mappings)
        f.protocol = MailerPOP3Client
        reactor.connectSSL(self.POP3_SERVER, self.POP3_PORT, f, self.context_factory)
コード例 #12
0
ファイル: mail.py プロジェクト: pytlakp/intranet-1
    def _run(self):
        config = ApplicationConfig.get_current_config(allow_empty=True)
        if config is None:
            WARN(u'Application config not found, emails cannot be checked')
            return self.mark_not_busy()
        trackers = dict(
            (tracker.mailer, tracker)
                for tracker in Tracker.query.filter(Tracker.mailer != None).filter(Tracker.mailer != '')
        )
        if not len(trackers):
            WARN(u'No trackers have mailers configured, email will not be checked')
            return self.mark_not_busy()

        username = config.google_user_email.encode('utf-8')
        password = config.google_user_password.encode('utf-8')

        # TODO
        logins_mappings = dict(
            (tracker.id, TrackerCredentials.get_logins_mapping(tracker))
                for tracker in trackers.itervalues()
        )
        selector_mappings = dict(
            (tracker.id, SelectorMapping(tracker))
                for tracker in trackers.itervalues()
        )

        # find all projects connected to the tracker
        projects = dict(
            (project.id, project)
                for project in Project.query.all()
        )

        # all pre-conditions should be checked by now

        # start fetching
        f = CustomClientFactory(username, password, self.mark_not_busy,
            trackers, logins_mappings, projects, selector_mappings)
        f.protocol = MailerPOP3Client
        reactor.connectSSL(self.POP3_SERVER, self.POP3_PORT, f, self.context_factory)
コード例 #13
0
ファイル: bugs.py プロジェクト: woliveira0101/intranet-open
    def get_project(self, project, resolved=False, credentials=None):
        """
        Get bugs for given project
        """
        start = time()
        bugs = []
        tracker = project.tracker
        credentials = credentials or self._get_credentials(tracker.id)

        if not credentials:
            return []

        login_mapping = TrackerCredentials.get_logins_mapping(tracker)
        fetcher = get_fetcher(tracker, credentials, self.user, login_mapping)
        fetcher.fetch_bugs_for_query(*project.get_selector_tuple(),
                                     resolved=resolved)

        bugs = []

        try:
            for bug in fetcher.get_result():
                bug.project = project
                bugs.append(bug)
        except FetcherTimeout as e:
            flash(
                'Fetchers for trackers %s timed-out' % fetcher.tracker.name,
                klass='error',
            )
        except FetcherBadDataError as e:
            flash(e, klass='error')
        except FetcherBaseException as e:
            flash(
                'Could not fetch bugs from tracker %s' % fetcher.tracker.name,
                klass='error',
            )

        bugs = self.add_time(bugs)
        return bugs
コード例 #14
0
ファイル: bugs.py プロジェクト: Rhenan/intranet-open
    def get_project(self, project, resolved=False, credentials=None):
        """
        Get bugs for given project
        """
        start = time()
        bugs = []
        tracker = project.tracker
        credentials = credentials or self._get_credentials(tracker.id)

        if not credentials:
            return []

        login_mapping = TrackerCredentials.get_logins_mapping(tracker)
        fetcher = get_fetcher(tracker, credentials, self.user, login_mapping)
        fetcher.fetch_bugs_for_query(*project.get_selector_tuple(), resolved=resolved)

        bugs = []

        try:
            for bug in fetcher.get_result():
                bug.project = project
                bugs.append(bug)
        except FetcherTimeout as e:
            flash(
                'Fetchers for trackers %s timed-out' % fetcher.tracker.name,
                klass='error',
            )
        except FetcherBadDataError as e:
            flash(e, klass='error')
        except FetcherBaseException as e:
            flash(
                'Could not fetch bugs from tracker %s' % fetcher.tracker.name,
                klass='error',
            )

        bugs = self.add_time(bugs)
        return bugs