Skip to content

pylint fix for readthedocs.core #5650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 29 additions & 16 deletions readthedocs/core/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

log = logging.getLogger(__name__)

LOG_TEMPLATE = '(Middleware) {msg} [{host}{path}]'
LOG_TEMPLATE = '(Middleware) %(msg)s [%(host)s%(path)s]'
SUBDOMAIN_URLCONF = settings.SUBDOMAIN_URLCONF
SINGLE_VERSION_URLCONF = settings.SINGLE_VERSION_URLCONF

Expand Down Expand Up @@ -74,10 +74,11 @@ def process_request(self, request):
request.urlconf = SUBDOMAIN_URLCONF
request.domain_object = True
log.debug(
LOG_TEMPLATE.format(
msg='Domain Object Detected: %s' % domain.domain,
LOG_TEMPLATE,
dict(
{'msg': 'Domain Object Detected: %s' % 'domain'},
**log_kwargs
),
)
)
break
if (
Expand All @@ -88,28 +89,37 @@ def process_request(self, request):
request.urlconf = SUBDOMAIN_URLCONF
request.rtdheader = True
log.debug(
LOG_TEMPLATE.format(
msg='X-RTD-Slug header detected: %s' % request.slug,
LOG_TEMPLATE,
dict(
{'msg': 'X-RTD-Slug header detected: %s' % request.slug},
**log_kwargs
),
)
)
# Try header first, then DNS
elif not hasattr(request, 'domain_object'):
# Some person is CNAMEing to us without configuring a domain - 404.
log.warning(LOG_TEMPLATE.format(msg='CNAME 404', **log_kwargs))
log.warning(
LOG_TEMPLATE,
dict({'msg': 'CNAME 404'}, **log_kwargs)
)
return render(request, 'core/dns-404.html', context={'host': host}, status=404)
# Google was finding crazy www.blah.readthedocs.org domains.
# Block these explicitly after trying CNAME logic.
if len(domain_parts) > 3 and not settings.DEBUG:
# Stop www.fooo.readthedocs.org
if domain_parts[0] == 'www':
log.debug(LOG_TEMPLATE.format(
msg='404ing long domain', **log_kwargs
))
log.debug(
LOG_TEMPLATE,
dict({'msg': '404ing long domain'}, **log_kwargs)
)
return HttpResponseBadRequest(_('Invalid hostname'))
log.debug(LOG_TEMPLATE.format(
msg='Allowing long domain name', **log_kwargs
))
log.debug(
LOG_TEMPLATE,
dict(
{'msg': 'Allowing long domain name'},
**log_kwargs
)
)
# Normal request.
return None

Expand Down Expand Up @@ -167,8 +177,11 @@ def process_request(self, request):
path = request.get_full_path()
log_kwargs = dict(host=host, path=path)
log.debug(
LOG_TEMPLATE.
format(msg='Handling single_version request', **log_kwargs),
LOG_TEMPLATE,
dict(
{'msg': 'Handling single_version request'},
**log_kwargs
)
)

return None
Expand Down
67 changes: 36 additions & 31 deletions readthedocs/core/symlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,12 @@ def sanity_check(self):
"""
if os.path.islink(self.project_root) and not self.project.single_version:
log.info(
constants.LOG_TEMPLATE.format(
project=self.project.slug,
version='',
msg='Removing single version symlink',
),
constants.LOG_TEMPLATE,
{
'project': self.project.slug,
'version': '',
'msg': 'Removing single version symlink',
}
)
safe_unlink(self.project_root)
safe_makedirs(self.project_root)
Expand Down Expand Up @@ -159,13 +160,13 @@ def symlink_cnames(self, domain=None):
self.project.slug,
)
log.debug(
constants.LOG_TEMPLATE.format(
project=self.project.slug,
version='',
msg=log_msg,
),
constants.LOG_TEMPLATE,
{
'project': self.project.slug,
'version': '',
'msg': log_msg,
}
)

# CNAME to doc root
symlink = os.path.join(self.CNAME_ROOT, dom)
self.environment.run('ln', '-nsf', self.project_root, symlink)
Expand All @@ -191,11 +192,12 @@ def remove_symlink_cname(self, domain):
"""
log_msg = 'Removing symlink for CNAME {}'.format(domain)
log.debug(
constants.LOG_TEMPLATE.format(
project=self.project.slug,
version='',
msg=log_msg
),
constants.LOG_TEMPLATE,
{
'project': self.project.slug,
'version': '',
'msg': log_msg,
}
)
symlink = os.path.join(self.CNAME_ROOT, domain)
safe_unlink(symlink)
Expand Down Expand Up @@ -226,11 +228,12 @@ def symlink_subprojects(self):
to_slug,
)
log.debug(
constants.LOG_TEMPLATE.format(
project=self.project.slug,
version='',
msg=log_msg,
),
constants.LOG_TEMPLATE,
{
'project': self.project.slug,
'version': '',
'msg': log_msg,
}
)
symlink = os.path.join(self.subproject_root, from_slug)
docs_dir = os.path.join(
Expand Down Expand Up @@ -280,11 +283,12 @@ def symlink_translations(self):

log_msg = 'Symlinking translation: {}->{}'.format(language, slug)
log.debug(
constants.LOG_TEMPLATE.format(
project=self.project.slug,
version='',
msg=log_msg,
),
constants.LOG_TEMPLATE,
{
'project': self.project.slug,
'version': '',
'msg': log_msg,
}
)
symlink = os.path.join(self.project_root, language)
docs_dir = os.path.join(self.WEB_ROOT, slug, language)
Expand Down Expand Up @@ -349,11 +353,12 @@ def symlink_versions(self):
for version in version_queryset:
log_msg = 'Symlinking Version: {}'.format(version)
log.debug(
constants.LOG_TEMPLATE.format(
project=self.project.slug,
version='',
msg=log_msg,
),
constants.LOG_TEMPLATE,
{
'project': self.project.slug,
'version': '',
'msg': log_msg,
}
)
symlink = os.path.join(version_dir, version.slug)
docs_dir = os.path.join(
Expand Down
11 changes: 6 additions & 5 deletions readthedocs/core/views/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,12 @@ def get_project_from_url(url):

def log_info(project, msg):
log.info(
constants.LOG_TEMPLATE.format(
project=project,
version='',
msg=msg,
),
constants.LOG_TEMPLATE,
{
'project': project,
'version': '',
'msg': msg,
}
)


Expand Down
2 changes: 1 addition & 1 deletion readthedocs/core/views/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def redirect_page_with_filename(request, project, subproject, filename): # pyli
def _serve_401(request, project):
res = render(request, '401.html')
res.status_code = 401
log.debug('Unauthorized access to {} documentation'.format(project.slug))
log.debug('Unauthorized access to %s documentation', project.slug)
return res


Expand Down
2 changes: 1 addition & 1 deletion readthedocs/projects/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
('other', 'Other'),
)

LOG_TEMPLATE = '(Build) [{project}:{version}] {msg}'
LOG_TEMPLATE = '(Build) [%(project)s:%(version)s] %(msg)s'

PROJECT_PK_REGEX = r'(?:[-\w]+)'
PROJECT_SLUG_REGEX = r'(?:[-\w]+)'
Expand Down