Created
September 10, 2017 16:53
-
-
Save Demon000/a803c922bd112171d4e1dbaa49294728 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from urllib.parse import urlparse, urlunparse, parse_qs | |
def parse_url_git_kernel_org(parseResult): | |
parameters = parse_qs(parseResult.query) | |
return 'https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/patch/?id=' + parameters['id'][0] | |
def parse_url_github_com(parseResult): | |
return urlunparse(parseResult) + '.patch' | |
def parse_url_source_codeaurora_org(parseResult): | |
parameters = parse_qs(parseResult.query) | |
return 'https://source.codeaurora.org/quic/la/kernel/msm-3.10/patch/?id=' + parameters['id'][0] | |
domainToParser = { | |
'git.kernel.org': parse_url_git_kernel_org, | |
'github.com': parse_url_github_com, | |
'source.codeaurora.org': parse_url_source_codeaurora_org | |
} | |
def link_to_patch(url): | |
parseResult = urlparse(url) | |
domain = parseResult.netloc | |
try: | |
patchUrl = domainToParser[domain](parseResult) | |
print(patchUrl) | |
except: | |
pass | |
link_to_patch('...') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment