1
0
mirror of https://github.com/HorlogeSkynet/CDNUpdates synced 2025-02-25 04:00:46 +01:00

Let's use a real constants module to facilitate external contributions

This commit is contained in:
Samuel FORESTIER 2019-05-11 14:40:40 +02:00
parent e98b1a0c17
commit 2ef2278647
5 changed files with 191 additions and 133 deletions

@ -2,7 +2,8 @@
from urllib.parse import urlparse
from .CDNContent import CDNContent, CDNPROVIDERS
from .CDNConstants import CDN_PROVIDERS
from .CDNContent import CDNContent
from .CDNUtils import log_message
@ -22,7 +23,7 @@ class CheckForCDNProviders: # pylint: disable=too-few-public-methods
parsed_result = urlparse(self.view.substr(region))
# ... to check if it's a known CDN provider.
if parsed_result.netloc in CDNPROVIDERS:
if parsed_result.netloc in CDN_PROVIDERS:
# If this matches, we store it and move on to the next element.
self.cdn_content_list.append(CDNContent(region, parsed_result))

@ -2,7 +2,7 @@
from sublime import IGNORECASE
from .CDNUtils import LINK_REGEX
from .CDNConstants import LINK_REGEX
class CheckForLinks: # pylint: disable=too-few-public-methods

173
CDNConstants.py Normal file

@ -0,0 +1,173 @@
"""CDNUpdates' constants module"""
# pylint: disable=line-too-long
# This regex has been written by @sindresorhus for Semver.
# <https://github.com/sindresorhus/semver-regex>
SEMVER_REGEX = r"v?(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\da-z-]+(?:\.[\da-z-]+)*)?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?"
# This is a regex written by @diegoperini, Python ported by @adamrofer.
# <https://gist.github.com/dperini/729294>
# It has been tweaked to work with network path references and HTML tags.
LINK_REGEX = r"(?:(https?:)?//)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S[^\"\s]*)?"
# pylint: enable=line-too-long
# This list stores the API links of handled CDN providers.
CDN_PROVIDERS = [
'cdnjs.cloudflare.com',
'maxcdn.bootstrapcdn.com',
'code.jquery.com',
'ajax.googleapis.com',
'cdn.jsdelivr.net',
'rawgit.com',
'cdn.rawgit.com',
'code.ionicframework.com',
'use.fontawesome.com',
'opensource.keycdn.com',
'cdn.staticfile.org',
'ajax.microsoft.com',
'ajax.aspnetcdn.com',
'cdn.ckeditor.com'
]
# The CDNs provided by Google are well "formatted".
# This dictionary will only store the "correspondences" with GitHub repositories.
AJAX_GOOGLE_APIS_CORRESPONDENCES = {
'dojo': {
'owner': 'dojo',
'name': 'dojo'
},
'ext-core': {
'owner': 'ExtCore',
'name': 'ExtCore'
},
'hammerjs': {
'owner': 'hammerjs',
'name': 'hammer.js'
},
'indefinite-observable': {
'owner': 'material-motion',
'name': 'indefinite-observable-js'
},
'jquery': {
'owner': 'jquery',
'name': 'jquery'
},
'jquerymobile': {
'owner': 'jquery',
'name': 'jquery-mobile'
},
'jqueryui': {
'owner': 'jquery',
'name': 'jquery-ui'
},
'mootools': {
'owner': 'mootools',
'name': 'mootools-core'
},
'myanmar-tools': {
'owner': 'googlei18n',
'name': 'myanmar-tools'
},
'prototype': {
'owner': 'sstephenson',
'name': 'prototype'
},
'scriptaculous': {
'owner': 'madrobby',
'name': 'scriptaculous'
},
'shaka-player': {
'owner': 'google',
'name': 'shaka-player'
},
'spf': {
'owner': 'youtube',
'name': 'spfjs'
},
'swfobject': {
'owner': 'swfobject',
'name': 'swfobject'
},
'threejs': {
'owner': 'mrdoob',
'name': 'three.js'
},
'webfont': {
'owner': 'typekit',
'name': 'webfontloader'
}
}
# This one will store the "correspondences" with GitHub repositories for Microsoft's CDNs.
# Sources : <https://docs.microsoft.com/en-us/aspnet/ajax/cdn/>
AJAX_MICROSOFT_CORRESPONDENCES = {
'jquery': {
'owner': 'jquery',
'name': 'jquery'
},
'jquery.migrate': {
'owner': 'jquery',
'name': 'jquery-migrate'
},
'jquery.ui': {
'owner': 'jquery',
'name': 'jquery-ui'
},
'jquery.mobile': {
'owner': 'jquery',
'name': 'jquery-mobile'
},
'jquery.validate': {
'owner': 'jquery-validation',
'name': 'jquery-validation'
},
'jquery.templates': {
'owner': 'BorisMoore',
'name': 'jquery-tmpl',
'fuzzy_check': True
},
'jquery.cycle': {
'owner': 'malsup',
'name': 'cycle2'
},
'jquery.dataTables': {
'owner': 'dataTables',
'name': 'dataTables'
},
'jshint': {
'owner': 'jshint',
'name': 'jshint'
},
'modernizr': {
'owner': 'Modernizr',
'name': 'Modernizr'
},
'respond': {
'owner': 'scottjehl',
'name': 'Respond'
},
'globalize': {
'owner': 'globalizejs',
'name': 'globalize'
},
'knockout': {
'owner': 'knockout',
'name': 'knockout'
},
'bootstrap': {
'owner': 'twbs',
'name': 'bootstrap'
},
'bootstrap-touch-carousel': {
'owner': 'ixisio',
'name': 'bootstrap-touch-carousel'
},
'hammer.js': {
'owner': 'hammerjs',
'name': 'hammer.js'
},
'signalr': {
'owner': 'SignalR',
'name': 'SignalR'
}
}

@ -7,26 +7,12 @@ from urllib.request import Request, urlopen
from sublime import load_settings
from .CDNUtils import SEMVER_REGEX, log_message
# This list stores the API links of handled CDN providers.
CDNPROVIDERS = [
'cdnjs.cloudflare.com',
'maxcdn.bootstrapcdn.com',
'code.jquery.com',
'ajax.googleapis.com',
'cdn.jsdelivr.net',
'rawgit.com',
'cdn.rawgit.com',
'code.ionicframework.com',
'use.fontawesome.com',
'opensource.keycdn.com',
'cdn.staticfile.org',
'ajax.microsoft.com',
'ajax.aspnetcdn.com',
'cdn.ckeditor.com'
]
from .CDNConstants import (
AJAX_GOOGLE_APIS_CORRESPONDENCES,
AJAX_MICROSOFT_CORRESPONDENCES,
SEMVER_REGEX
)
from .CDNUtils import log_message
class CDNContent:
@ -124,46 +110,14 @@ class CDNContent:
# CDN from AJAX.GOOGLEAPIS.COM will be handled here.
elif self.parsed_result.netloc == 'ajax.googleapis.com':
tmp = self.parsed_result.path.split('/')
# The CDNs provided by Google are well "formatted".
# This dictionary will only store the "correspondences" with...
# ... GitHub repositories.
correspondences = {
'dojo': {'owner': 'dojo', 'name': 'dojo'},
'ext-core': {'owner': 'ExtCore', 'name': 'ExtCore'},
'hammerjs': {'owner': 'hammerjs', 'name': 'hammer.js'},
'indefinite-observable': {
'owner': 'material-motion',
'name': 'indefinite-observable-js'
},
'jquery': {'owner': 'jquery', 'name': 'jquery'},
'jquerymobile': {'owner': 'jquery', 'name': 'jquery-mobile'},
'jqueryui': {'owner': 'jquery', 'name': 'jquery-ui'},
'mootools': {'owner': 'mootools', 'name': 'mootools-core'},
'myanmar-tools': {
'owner': 'googlei18n',
'name': 'myanmar-tools'
},
'prototype': {'owner': 'sstephenson', 'name': 'prototype'},
'scriptaculous': {
'owner': 'madrobby',
'name': 'scriptaculous'
},
'shaka-player': {'owner': 'google', 'name': 'shaka-player'},
'spf': {'owner': 'youtube', 'name': 'spfjs'},
'swfobject': {'owner': 'swfobject', 'name': 'swfobject'},
'threejs': {'owner': 'mrdoob', 'name': 'three.js'},
'webfont': {'owner': 'typekit', 'name': 'webfontloader'}
}
self.name = tmp[3]
if self.name not in correspondences.keys():
if self.name not in AJAX_GOOGLE_APIS_CORRESPONDENCES.keys():
self.status = 'not_found'
return
self.compare_with_latest_github_tag(
correspondences.get(self.name)['owner'],
correspondences.get(self.name)['name'],
AJAX_GOOGLE_APIS_CORRESPONDENCES.get(self.name)['owner'],
AJAX_GOOGLE_APIS_CORRESPONDENCES.get(self.name)['name'],
tmp[4]
)
@ -277,80 +231,22 @@ class CDNContent:
elif self.parsed_result.netloc in [
'ajax.microsoft.com', 'ajax.aspnetcdn.com'
]:
tmp = self.parsed_result.path.split('/')
# Sources : https://docs.microsoft.com/en-us/aspnet/ajax/cdn/
correspondences = {
'jquery': {
'owner': 'jquery', 'name': 'jquery'
},
'jquery.migrate': {
'owner': 'jquery', 'name': 'jquery-migrate'
},
'jquery.ui': {
'owner': 'jquery', 'name': 'jquery-ui'
},
'jquery.mobile': {
'owner': 'jquery', 'name': 'jquery-mobile'
},
'jquery.validate': {
'owner': 'jquery-validation', 'name': 'jquery-validation'
},
'jquery.templates': {
'owner': 'BorisMoore', 'name': 'jquery-tmpl',
'fuzzy_check': True
},
'jquery.cycle': {
'owner': 'malsup', 'name': 'cycle2'
},
'jquery.dataTables': {
'owner': 'dataTables', 'name': 'dataTables'
},
'jshint': {
'owner': 'jshint', 'name': 'jshint'
},
'modernizr': {
'owner': 'Modernizr', 'name': 'Modernizr'
},
'respond': {
'owner': 'scottjehl', 'name': 'Respond'
},
'globalize': {
'owner': 'globalizejs', 'name': 'globalize'
},
'knockout': {
'owner': 'knockout', 'name': 'knockout'
},
'bootstrap': {
'owner': 'twbs', 'name': 'bootstrap'
},
'bootstrap-touch-carousel': {
'owner': 'ixisio', 'name': 'bootstrap-touch-carousel'
},
'hammer.js': {
'owner': 'hammerjs', 'name': 'hammer.js'
},
'signalr': {
'owner': 'SignalR', 'name': 'SignalR'
}
}
if tmp[2] not in correspondences.keys():
if tmp[2] not in AJAX_MICROSOFT_CORRESPONDENCES.keys():
self.status = 'not_found'
return
self.name = tmp[2]
self.compare_with_latest_github_tag(
correspondences.get(tmp[2])['owner'],
correspondences.get(tmp[2])['name'],
AJAX_MICROSOFT_CORRESPONDENCES.get(tmp[2])['owner'],
AJAX_MICROSOFT_CORRESPONDENCES.get(tmp[2])['name'],
# Sometimes the version is in the path...
tmp[3] if len(tmp) == 5
# ... and some other times contained within the name.
else re.search(SEMVER_REGEX, tmp[3]).group(0),
# Microsoft has tagged some libraries very badly...
# Check `correspondences` above for this entry.
correspondences.get(tmp[2]).get('fuzzy_check', False)
# Check `CDNConstants.AJAX_MICROSOFT_CORRESPONDENCES` for this entry.
AJAX_MICROSOFT_CORRESPONDENCES.get(tmp[2]).get('fuzzy_check', False)
)
elif self.parsed_result.netloc == 'cdn.ckeditor.com':

@ -3,18 +3,6 @@
from sublime import active_window, load_settings
# pylint: disable=line-too-long
# This regex has been written by @sindresorhus for Semver.
# <https://github.com/sindresorhus/semver-regex>
SEMVER_REGEX = r"v?(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\da-z-]+(?:\.[\da-z-]+)*)?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?"
# This is a regex written by @diegoperini, Python ported by @adamrofer.
# <https://gist.github.com/dperini/729294>
# It has been tweaked to work with network path references and HTML tags.
LINK_REGEX = r"(?:(https?:)?//)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S[^\"\s]*)?"
# pylint: enable=line-too-long
def clear_view(view):
"""Removes the passed `view` object all traces of our elements (known identifiers)"""
if view: