Skip to content

Commit 2b5b875

Browse files
committed
Remove repeated/dead code
1 parent c37b009 commit 2b5b875

File tree

2 files changed

+21
-98
lines changed

2 files changed

+21
-98
lines changed

readthedocs/core/symlink.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
from readthedocs.builds.models import Version
6565
from readthedocs.core.utils.extend import SettingsOverrideObject
6666
from readthedocs.core.utils import safe_makedirs, safe_unlink
67+
from readthedocs.doc_builder.environments import LocalEnvironment
6768
from readthedocs.projects import constants
6869
from readthedocs.projects.models import Domain
69-
from readthedocs.projects.utils import run
7070

7171
log = logging.getLogger(__name__)
7272

@@ -83,6 +83,7 @@ def __init__(self, project):
8383
self.subproject_root = os.path.join(
8484
self.project_root, 'projects'
8585
)
86+
self.environment = LocalEnvironment(project)
8687
self.sanity_check()
8788

8889
def sanity_check(self):
@@ -152,11 +153,13 @@ def symlink_cnames(self, domain=None):
152153

153154
# CNAME to doc root
154155
symlink = os.path.join(self.CNAME_ROOT, dom.domain)
155-
run(['ln', '-nsf', self.project_root, symlink])
156+
self.environment.run('ln', '-nsf', self.project_root, symlink)
156157

157158
# Project symlink
158159
project_cname_symlink = os.path.join(self.PROJECT_CNAME_ROOT, dom.domain)
159-
run(['ln', '-nsf', self.project.doc_path, project_cname_symlink])
160+
self.environment.run(
161+
'ln', '-nsf', self.project.doc_path, project_cname_symlink
162+
)
160163

161164
def remove_symlink_cname(self, domain):
162165
"""Remove CNAME symlink."""
@@ -201,10 +204,12 @@ def symlink_subprojects(self):
201204
# TODO this should use os.symlink, not a call to shell. For now,
202205
# this passes command as a list to be explicit about escaping
203206
# characters like spaces.
204-
status, _, stderr = run(['ln', '-nsf', docs_dir, symlink])
205-
if status > 0:
206-
log.error('Could not symlink path: status=%d error=%s',
207-
status, stderr)
207+
result = self.environment.run('ln', '-nsf', docs_dir, symlink)
208+
if result.exit_code > 0:
209+
log.error(
210+
'Could not symlink path: status=%d error=%s',
211+
result.exit_code, result.error
212+
)
208213

209214
# Remove old symlinks
210215
if os.path.exists(self.subproject_root):
@@ -238,7 +243,7 @@ def symlink_translations(self):
238243
version='', msg=log_msg))
239244
symlink = os.path.join(self.project_root, language)
240245
docs_dir = os.path.join(self.WEB_ROOT, slug, language)
241-
run(['ln', '-nsf', docs_dir, symlink])
246+
self.environment.run('ln', '-nsf', docs_dir, symlink)
242247

243248
# Remove old symlinks
244249
for lang in os.listdir(self.project_root):
@@ -270,7 +275,7 @@ def symlink_single_version(self):
270275
if version is not None:
271276
docs_dir = os.path.join(settings.DOCROOT, self.project.slug,
272277
'rtd-builds', version.slug)
273-
run(['ln', '-nsf', docs_dir, symlink])
278+
self.environment.run('ln', '-nsf', docs_dir, symlink)
274279

275280
def symlink_versions(self):
276281
"""
@@ -293,7 +298,7 @@ def symlink_versions(self):
293298
version='', msg=log_msg))
294299
symlink = os.path.join(version_dir, version.slug)
295300
docs_dir = os.path.join(settings.DOCROOT, self.project.slug, 'rtd-builds', version.slug)
296-
run(['ln', '-nsf', docs_dir, symlink])
301+
self.environment.run('ln', '-nsf', docs_dir, symlink)
297302
versions.add(version.slug)
298303

299304
# Remove old symlinks

readthedocs/projects/utils.py

Lines changed: 6 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
"""Utility functions used by projects."""
33

44
from __future__ import (
5-
absolute_import, division, print_function, unicode_literals)
5+
absolute_import,
6+
division,
7+
print_function,
8+
unicode_literals,
9+
)
610

7-
import fnmatch
811
import logging
912
import os
10-
import subprocess
11-
import traceback
1213

13-
import six
14-
from builtins import object, open
14+
from builtins import open
1515
from django.conf import settings
1616

1717
log = logging.getLogger(__name__)
@@ -32,82 +32,6 @@ def version_from_slug(slug, version):
3232
return v
3333

3434

35-
def find_file(filename):
36-
"""
37-
Recursively find matching file from the current working path.
38-
39-
:param file: Filename to match
40-
:returns: A list of matching filenames.
41-
"""
42-
matches = []
43-
for root, __, filenames in os.walk('.'):
44-
for match in fnmatch.filter(filenames, filename):
45-
matches.append(os.path.join(root, match))
46-
return matches
47-
48-
49-
def run(*commands):
50-
"""
51-
Run one or more commands.
52-
53-
Each argument in `commands` can be passed as a string or as a list. Passing
54-
as a list is the preferred method, as space escaping is more explicit and it
55-
avoids the need for executing anything in a shell.
56-
57-
If more than one command is given, then this is equivalent to
58-
chaining them together with ``&&``; if all commands succeed, then
59-
``(status, out, err)`` will represent the last successful command.
60-
If one command failed, then ``(status, out, err)`` will represent
61-
the failed command.
62-
63-
:returns: ``(status, out, err)``
64-
"""
65-
environment = os.environ.copy()
66-
environment['READTHEDOCS'] = 'True'
67-
if 'DJANGO_SETTINGS_MODULE' in environment:
68-
del environment['DJANGO_SETTINGS_MODULE']
69-
if 'PYTHONPATH' in environment:
70-
del environment['PYTHONPATH']
71-
# Remove PYTHONHOME env variable if set, otherwise pip install of requirements
72-
# into virtualenv will install incorrectly
73-
if 'PYTHONHOME' in environment:
74-
del environment['PYTHONHOME']
75-
cwd = os.getcwd()
76-
if not commands:
77-
raise ValueError('run() requires one or more command-line strings')
78-
79-
for command in commands:
80-
# If command is a string, split it up by spaces to pass into Popen.
81-
# Otherwise treat the command as an iterable.
82-
if isinstance(command, six.string_types):
83-
run_command = command.split()
84-
else:
85-
try:
86-
run_command = list(command)
87-
command = ' '.join(command)
88-
except TypeError:
89-
run_command = command
90-
log.debug('Running command: cwd=%s command=%s', cwd, command)
91-
try:
92-
p = subprocess.Popen(
93-
run_command,
94-
cwd=cwd,
95-
stdout=subprocess.PIPE,
96-
stderr=subprocess.PIPE,
97-
env=environment,
98-
)
99-
100-
out, err = p.communicate()
101-
ret = p.returncode
102-
except OSError:
103-
out = ''
104-
err = traceback.format_exc()
105-
ret = -1
106-
log.exception('Command failed')
107-
108-
return (ret, out, err)
109-
110-
11135
def safe_write(filename, contents):
11236
"""
11337
Normalize and write to filename.
@@ -126,9 +50,3 @@ def safe_write(filename, contents):
12650
with open(filename, 'w', encoding='utf-8', errors='ignore') as fh:
12751
fh.write(contents)
12852
fh.close()
129-
130-
131-
class DictObj(object):
132-
133-
def __getattr__(self, attr):
134-
return self.__dict__.get(attr)

0 commit comments

Comments
 (0)