Created
July 16, 2019 09:36
-
-
Save pyohei/a7126d593c05377ba4fb305590c2197d to your computer and use it in GitHub Desktop.
djangoのURLの一覧を取得して、別のURLと比較するスクリプト。
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
"""URLの一覧を抽出するスクリプト | |
簡易的に作成したものなので、コンテナの中に入って直接実行する必要がある。 | |
PYTHONPATHなどを事前に通しておけば、コンテナ外からも動作する可能性はある。 | |
""" | |
from collections import OrderedDict | |
import django; django.setup() | |
from backoffice.coke import urls | |
# スプレッドシートに記載しているURLの一覧 | |
SPREADSHEET_URLS = [ | |
] | |
PARSED_URLS = [] | |
def show_urls(url_list, depth=0): | |
for u in url_list: | |
r_url = u.regex.pattern.replace('^', '/').replace('$','') | |
PARSED_URLS.append(r_url) | |
if hasattr(u, 'url_patterns'): | |
show_urls(u.url_patterns, depth+1) | |
show_urls(urls.urlpatterns) | |
print('== 共通部分 ==') | |
for l in sorted(set(SPREADSHEET_URLS).intersection(set(PARSED_URLS))): | |
print(l) | |
print('== スプレッドシートのみ ==') | |
for l in sorted(list(set(SPREADSHEET_URLS).difference(set(PARSED_URLS)))): | |
print(l) | |
print('== urls.pyのみ ==') | |
for l in sorted(list(set(PARSED_URLS).difference(set(SPREADSHEET_URLS)))): | |
print(l) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment