]> git.ipfire.org Git - ipfire.org.git/commitdiff
Rename fireinfo module
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 30 Oct 2018 09:52:19 +0000 (09:52 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 30 Oct 2018 09:52:19 +0000 (09:52 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/web/__init__.py
src/web/fireinfo.py [moved from src/web/handlers_fireinfo.py with 79% similarity]
src/web/handlers.py
src/web/ui_modules.py

index 20f553a3dba84735289f98d313d4334982daa3b3..a5a73d0b45d3ef44eb289cceb121bdd9cfb0ec84 100644 (file)
@@ -79,8 +79,8 @@ web_PYTHON = \
        src/web/blog.py \
        src/web/boot.py \
        src/web/download.py \
+       src/web/fireinfo.py \
        src/web/handlers.py \
-       src/web/handlers_fireinfo.py \
        src/web/iuse.py \
        src/web/location.py \
        src/web/mirrors.py \
index 971c26541088bbb19d6a056f90fe7483e680f725..6097c470d7a113610b6868c3852a919675d6a4af 100644 (file)
@@ -17,6 +17,7 @@ from . import auth
 from . import blog
 from . import boot
 from . import download
+from . import fireinfo
 from . import iuse
 from . import location
 from . import mirrors
@@ -83,9 +84,9 @@ class Application(tornado.web.Application):
                                "LanguageName"         : ui_modules.LanguageNameModule,
 
                                "ProgressBar"          : ui_modules.ProgressBarModule,
-                               "FireinfoDeviceTable"  : ui_modules.FireinfoDeviceTableModule,
-                               "FireinfoDeviceAndGroupsTable" : ui_modules.FireinfoDeviceAndGroupsTableModule,
-                               "FireinfoGeoTable"        : ui_modules.FireinfoGeoTableModule,
+                               "FireinfoDeviceTable"  : fireinfo.DeviceTableModule,
+                               "FireinfoDeviceAndGroupsTable" : fireinfo.DeviceAndGroupsTableModule,
+                               "FireinfoGeoTable"     : fireinfo.GeoTableModule,
                        },
 
                        # Call this when a page wasn't found
@@ -183,29 +184,29 @@ class Application(tornado.web.Application):
 
                # fireinfo.ipfire.org
                self.add_handlers(r"fireinfo(\.dev)?\.ipfire\.org", [
-                       (r"/", FireinfoIndexHandler),
-                       (r"/device/driver/(.*)", FireinfoDeviceDriverDetail),
-                       (r"/device/vendors", FireinfoDeviceVendorsHandler),
-                       (r"/device/(pci|usb)/([0-9a-f]{4})", FireinfoDeviceVendorHandler),
-                       (r"/device/(pci|usb)/([0-9a-f]{4})/([0-9a-f]{4})", FireinfoDeviceModelHandler),
+                       (r"/", fireinfo.IndexHandler),
+                       (r"/device/driver/(.*)", fireinfo.DeviceDriverDetail),
+                       (r"/device/vendors", fireinfo.DeviceVendorsHandler),
+                       (r"/device/(pci|usb)/([0-9a-f]{4})", fireinfo.DeviceVendorHandler),
+                       (r"/device/(pci|usb)/([0-9a-f]{4})/([0-9a-f]{4})", fireinfo.DeviceModelHandler),
 
                        # Show profiles
-                       (r"/profile/random", FireinfoRandomProfileHandler),
-                       (r"/profile/([a-z0-9]{40})", FireinfoProfileDetailHandler),
+                       (r"/profile/random", fireinfo.RandomProfileHandler),
+                       (r"/profile/([a-z0-9]{40})", fireinfo.ProfileDetailHandler),
 
                        # Send profiles.
-                       (r"/send/([a-z0-9]+)", FireinfoProfileSendHandler),
+                       (r"/send/([a-z0-9]+)", fireinfo.ProfileSendHandler),
 
                        # Stats handlers
-                       (r"/statistics", FireinfoStatsHandler),
-                       (r"/statistics/processors", FireinfoStatsProcessorsHandler),
-                       (r"/statistics/processors/(arm|x86)", FireinfoStatsProcessorDetailHandler),
-                       (r"/statistics/geo-locations", FireinfoStatsGeoHandler),
-                       (r"/statistics/languages", FireinfoStatsLanguagesHandler),
-                       (r"/statistics/memory", FireinfoStatsMemoryHandler),
-                       (r"/statistics/networking", FireinfoStatsNetworkingHandler),
-                       (r"/statistics/releases", FireinfoStatsReleasesHandler),
-                       (r"/statistics/virtualization", FireinfoStatsVirtualHandler),
+                       (r"/statistics", fireinfo.StatsHandler),
+                       (r"/statistics/processors", fireinfo.StatsProcessorsHandler),
+                       (r"/statistics/processors/(arm|x86)", fireinfo.StatsProcessorDetailHandler),
+                       (r"/statistics/geo-locations", fireinfo.StatsGeoHandler),
+                       (r"/statistics/languages", fireinfo.StatsLanguagesHandler),
+                       (r"/statistics/memory", fireinfo.StatsMemoryHandler),
+                       (r"/statistics/networking", fireinfo.StatsNetworkingHandler),
+                       (r"/statistics/releases", fireinfo.StatsReleasesHandler),
+                       (r"/statistics/virtualization", fireinfo.StatsVirtualHandler),
 
                        # Compat handlers
                        (r"/stats", tornado.web.RedirectHandler, { "url" : "/statistics" }),
@@ -214,8 +215,8 @@ class Application(tornado.web.Application):
                        (r"/stats/network", tornado.web.RedirectHandler, { "url" : "/statistics/networking" }),
                        (r"/stats/oses", tornado.web.RedirectHandler, { "url" : "/statistics/releases" }),
                        (r"/stats/virtual", tornado.web.RedirectHandler, { "url" : "/statistics/virtualization" }),
-                       (r"/vendor/(pci|usb)/([0-9a-f]{4})", FireinfoDeviceVendorCompatHandler),
-                       (r"/model/(pci|usb)/([0-9a-f]{4})/([0-9a-f]{4})", FireinfoDeviceModelCompatHandler),
+                       (r"/vendor/(pci|usb)/([0-9a-f]{4})", fireinfo.DeviceVendorCompatHandler),
+                       (r"/model/(pci|usb)/([0-9a-f]{4})/([0-9a-f]{4})", fireinfo.DeviceModelCompatHandler),
                ])
 
                # i-use.ipfire.org
similarity index 79%
rename from src/web/handlers_fireinfo.py
rename to src/web/fireinfo.py
index 12c417ea4d29cbda4cbff791be18a0e6d35cd665..19f001ca630e71a036192a62adc1843899521941 100644 (file)
@@ -1,7 +1,5 @@
 #!/usr/bin/python
 
-
-
 import datetime
 import hwdata
 import logging
@@ -12,21 +10,9 @@ import tornado.web
 from .. import fireinfo
 
 from . import base
+from . import ui_modules
 
-class FireinfoBaseHandler(base.BaseHandler):
-       def cut_string(self, s, limit=15):
-               if len(s) > limit:
-                       s = s[:limit] + "..."
-
-               return s
-
-       def render(self, *args, **kwargs):
-               kwargs.update({
-                       "cut_string" : self.cut_string,
-               })
-
-               return BaseHandler.render(self, *args, **kwargs)
-
+class BaseHandler(base.BaseHandler):
        @property
        def when(self):
                return self.get_argument_date("when", None)
@@ -46,7 +32,7 @@ class Profile(dict):
                self[key] = val
 
 
-class FireinfoProfileSendHandler(FireinfoBaseHandler):
+class ProfileSendHandler(BaseHandler):
        def check_xsrf_cookie(self):
                # This cookie is not required here.
                pass
@@ -166,7 +152,7 @@ class FireinfoProfileSendHandler(FireinfoBaseHandler):
                self.finish("Your profile was successfully saved to the database.")
 
 
-class FireinfoIndexHandler(FireinfoBaseHandler):
+class IndexHandler(BaseHandler):
        def _profile_not_found(self, profile_id):
                self.set_status(404)
                self.render("fireinfo/profile-notfound.html", profile_id=profile_id)
@@ -186,7 +172,7 @@ class FireinfoIndexHandler(FireinfoBaseHandler):
                self.redirect("/profile/%s" % profile_id)
 
 
-class FireinfoProfileDetailHandler(FireinfoIndexHandler):
+class ProfileDetailHandler(BaseHandler):
        def get(self, profile_id):
                profile = self.fireinfo.get_profile(profile_id, when=self.when)
 
@@ -197,7 +183,7 @@ class FireinfoProfileDetailHandler(FireinfoIndexHandler):
                self.render("fireinfo/profile-detail.html", profile=profile)
 
 
-class FireinfoRandomProfileHandler(FireinfoBaseHandler):
+class RandomProfileHandler(BaseHandler):
        def get(self):
                profile_id = self.fireinfo.get_random_profile(when=self.when)
                if profile_id is None:
@@ -206,25 +192,25 @@ class FireinfoRandomProfileHandler(FireinfoBaseHandler):
                self.redirect("/profile/%s" % profile_id)
 
 
-class FireinfoDeviceDriverDetail(FireinfoBaseHandler):
+class DeviceDriverDetail(BaseHandler):
        def get(self, driver):
                self.render("fireinfo/driver.html", driver=driver,
                        driver_map=self.fireinfo.get_driver_map(driver, when=self.when))
 
 
-class FireinfoDeviceVendorsHandler(FireinfoBaseHandler):
+class DeviceVendorsHandler(BaseHandler):
        def get(self):
                vendors = self.fireinfo.get_vendor_list(when=self.when)
 
                self.render("fireinfo/vendors.html", vendors=vendors)
 
 
-class FireinfoStatsHandler(FireinfoBaseHandler):
+class StatsHandler(BaseHandler):
        def get(self):
                self.render("fireinfo/stats.html")
 
 
-class FireinfoStatsProcessorsHandler(FireinfoBaseHandler):
+class StatsProcessorsHandler(BaseHandler):
        def get(self):
                avg, stddev, min, max = self.fireinfo.get_cpu_clock_speeds(when=self.when)
                arch_map = self.fireinfo.get_arch_map(when=self.when)
@@ -241,7 +227,7 @@ class FireinfoStatsProcessorsHandler(FireinfoBaseHandler):
                return self.render("fireinfo/stats-cpus.html", **data)
 
 
-class FireinfoStatsProcessorDetailHandler(FireinfoBaseHandler):
+class StatsProcessorDetailHandler(BaseHandler):
        def get(self, platform):
                assert platform in ("arm", "x86")
 
@@ -251,7 +237,7 @@ class FireinfoStatsProcessorDetailHandler(FireinfoBaseHandler):
                        platform=platform, flags=flags)
 
 
-class FireinfoStatsMemoryHandler(FireinfoBaseHandler):
+class StatsMemoryHandler(BaseHandler):
        def get(self):
                avg, stddev, min, max = self.fireinfo.get_memory_amounts(when=self.when)
                amounts = self.fireinfo.get_common_memory_amounts(when=self.when)
@@ -267,7 +253,7 @@ class FireinfoStatsMemoryHandler(FireinfoBaseHandler):
                return self.render("fireinfo/stats-memory.html", **data)
 
 
-class FireinfoStatsReleasesHandler(FireinfoBaseHandler):
+class StatsReleasesHandler(BaseHandler):
        def get(self):
                data = {
                        "releases" : self.fireinfo.get_releases_map(when=self.when),
@@ -276,7 +262,7 @@ class FireinfoStatsReleasesHandler(FireinfoBaseHandler):
                return self.render("fireinfo/stats-oses.html", **data)
 
 
-class FireinfoStatsVirtualHandler(FireinfoBaseHandler):
+class StatsVirtualHandler(BaseHandler):
        def get(self):
                data = {
                        "hypervisors" : self.fireinfo.get_hypervisor_map(when=self.when),
@@ -286,26 +272,26 @@ class FireinfoStatsVirtualHandler(FireinfoBaseHandler):
                return self.render("fireinfo/stats-virtual.html", **data)
 
 
-class FireinfoStatsGeoHandler(FireinfoBaseHandler):
+class StatsGeoHandler(BaseHandler):
        def get(self):
                return self.render("fireinfo/stats-geo.html",
                        geo_locations = self.fireinfo.get_geo_location_map(when=self.when))
 
 
-class FireinfoStatsLanguagesHandler(FireinfoBaseHandler):
+class StatsLanguagesHandler(BaseHandler):
        def get(self):
                return self.render("fireinfo/stats-languages.html",
                        languages = self.fireinfo.get_language_map(when=self.when))
 
 
-class FireinfoStatsNetworkingHandler(FireinfoBaseHandler):
+class StatsNetworkingHandler(BaseHandler):
        def get(self):
                network=self.fireinfo.get_network_zones_map(when=self.when)
 
                return self.render("fireinfo/stats-network.html", network=network)
 
 
-class FireinfoDeviceVendorHandler(FireinfoBaseHandler):
+class DeviceVendorHandler(BaseHandler):
        def get(self, subsystem, vendor_id):
                devices = self.fireinfo.get_devices_by_vendor(subsystem, vendor_id,
                        when=self.when)
@@ -316,12 +302,12 @@ class FireinfoDeviceVendorHandler(FireinfoBaseHandler):
                        devices=devices)
 
 
-class FireinfoDeviceVendorCompatHandler(FireinfoBaseHandler):
+class DeviceVendorCompatHandler(BaseHandler):
        def get(self, subsystem, vendor_id):
                self.redirect("/device/%s/%s" % (subsystem, vendor_id))
 
 
-class FireinfoDeviceModelHandler(FireinfoBaseHandler):
+class DeviceModelHandler(BaseHandler):
        def get(self, subsystem, vendor, model):
                percentage = self.fireinfo.get_device_percentage(subsystem, vendor,
                                model, when=self.when)
@@ -339,12 +325,12 @@ class FireinfoDeviceModelHandler(FireinfoBaseHandler):
                        percentage=percentage, subsystem=subsystem)
 
 
-class FireinfoDeviceModelCompatHandler(FireinfoBaseHandler):
+class DeviceModelCompatHandler(BaseHandler):
        def get(self, subsystem, vendor_id, model_id):
                self.redirect("/device/%s/%s/%s" % (subsystem, vendor_id, model_id))
 
 
-class AdminFireinfoHandler(FireinfoBaseHandler):
+class AdminFireinfoHandler(BaseHandler):
        def get(self):
                profiles_with_data, profiles_all = self.fireinfo.get_active_profiles(when=self.when)
 
@@ -356,3 +342,60 @@ class AdminFireinfoHandler(FireinfoBaseHandler):
                }
 
                self.render("fireinfo/stats-admin.html", **data)
+
+
+class DeviceTableModule(ui_modules.UIModule):
+       def render(self, devices):
+               return self.render_string("fireinfo/modules/table-devices.html",
+                               devices=devices)
+
+
+class DeviceAndGroupsTableModule(ui_modules.UIModule):
+       def render(self, devices):
+               _ = self.locale.translate
+
+               groups = {}
+
+               for device in devices:
+                       if device.cls not in groups:
+                               groups[device.cls] = []
+
+                       groups[device.cls].append(device)
+
+               # Sort all devices
+               for key in list(groups.keys()):
+                       groups[key].sort()
+
+               # Order the groups by their name
+               groups = list(groups.items())
+               groups.sort()
+
+               return self.render_string("fireinfo/modules/table-devices-and-groups.html",
+                               groups=groups)
+
+
+class GeoTableModule(ui_modules.UIModule):
+       def render(self, items):
+               countries = []
+               other_countries = []
+               for code, value in items:
+                       # Skip the satellite providers in this ranking
+                       if code in (None, "A1", "A2"):
+                               continue
+
+                       name = self.backend.geoip.get_country_name(code)
+
+                       # Don't add countries with a small share on the list
+                       if value < 0.01:
+                               other_countries.append(name)
+                               continue
+
+                       country = database.Row({
+                               "code"  : code,
+                               "name"  : name,
+                               "value" : value,
+                       })
+                       countries.append(country)
+
+               return self.render_string("fireinfo/modules/table-geo.html",
+                       countries=countries, other_countries=other_countries)
index 1d5b22d8e05c2ca3c5a4daae9a2aac3ab852d0ec..ea6718b9d671ef5c9109c4de795106681462772c 100644 (file)
@@ -6,8 +6,6 @@ import tornado.web
 
 from . import base
 
-from .handlers_fireinfo import *
-
 class LangCompatHandler(base.BaseHandler):
        """
                Redirect links in the old format to current site:
index 6175e7327c4b32a56b1680519b57770a1b92977c..07f095895add7eee7585f3960011e143a26583b4 100644 (file)
@@ -10,63 +10,6 @@ class UIModule(tornado.web.UIModule):
                return self.handler.backend
 
 
-class FireinfoDeviceTableModule(UIModule):
-       def render(self, devices):
-               return self.render_string("fireinfo/modules/table-devices.html",
-                               devices=devices)
-
-
-class FireinfoDeviceAndGroupsTableModule(UIModule):
-       def render(self, devices):
-               _ = self.locale.translate
-
-               groups = {}
-
-               for device in devices:
-                       if device.cls not in groups:
-                               groups[device.cls] = []
-
-                       groups[device.cls].append(device)
-
-               # Sort all devices
-               for key in list(groups.keys()):
-                       groups[key].sort()
-
-               # Order the groups by their name
-               groups = list(groups.items())
-               groups.sort()
-
-               return self.render_string("fireinfo/modules/table-devices-and-groups.html",
-                               groups=groups)
-
-
-class FireinfoGeoTableModule(UIModule):
-       def render(self, items):
-               countries = []
-               other_countries = []
-               for code, value in items:
-                       # Skip the satellite providers in this ranking
-                       if code in (None, "A1", "A2"):
-                               continue
-
-                       name = self.backend.geoip.get_country_name(code)
-
-                       # Don't add countries with a small share on the list
-                       if value < 0.01:
-                               other_countries.append(name)
-                               continue
-
-                       country = database.Row({
-                               "code"  : code,
-                               "name"  : name,
-                               "value" : value,
-                       })
-                       countries.append(country)
-
-               return self.render_string("fireinfo/modules/table-geo.html",
-                       countries=countries, other_countries=other_countries)
-
-
 class LanguageNameModule(UIModule):
        def render(self, language):
                _ = self.locale.translate