Skip to content

Commit

Permalink
Merge pull request #2281 from getnikola/dont-create-folders-when-down…
Browse files Browse the repository at this point in the history
…load-disabled

Don't create download directories when not downloading uploads.
  • Loading branch information
Kwpolska committed Mar 6, 2016
2 parents d5015e9 + 87286f1 commit 1ed3e80
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions nikola/plugins/command/import_wordpress.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,6 @@ def populate_context(self, channel):

def download_url_content_to_file(self, url, dst_path):
"""Download some content (attachments) to a file."""
if self.no_downloads:
return

try:
request = requests.get(url, auth=self.auth)
if request.status_code >= 400:
Expand All @@ -468,10 +465,13 @@ def import_attachment(self, item, wordpress_namespace):
'foo')
path = urlparse(url).path
dst_path = os.path.join(*([self.output_folder, 'files'] + list(path.split('/'))))
dst_dir = os.path.dirname(dst_path)
utils.makedirs(dst_dir)
LOGGER.info("Downloading {0} => {1}".format(url, dst_path))
self.download_url_content_to_file(url, dst_path)
if self.no_downloads:
LOGGER.info("Skipping downloading {0} => {1}".format(url, dst_path))
else:
dst_dir = os.path.dirname(dst_path)
utils.makedirs(dst_dir)
LOGGER.info("Downloading {0} => {1}".format(url, dst_path))
self.download_url_content_to_file(url, dst_path)
dst_url = '/'.join(dst_path.split(os.sep)[2:])
links[link] = '/' + dst_url
links[url] = '/' + dst_url
Expand Down Expand Up @@ -567,10 +567,13 @@ def add(our_key, wp_key, is_int=False, ignore_zero=False, is_float=False):

path = urlparse(url).path
dst_path = os.path.join(*([self.output_folder, 'files'] + list(path.split('/'))))
dst_dir = os.path.dirname(dst_path)
utils.makedirs(dst_dir)
LOGGER.info("Downloading {0} => {1}".format(url, dst_path))
self.download_url_content_to_file(url, dst_path)
if self.no_downloads:
LOGGER.info("Skipping downloading {0} => {1}".format(url, dst_path))
else:
dst_dir = os.path.dirname(dst_path)
utils.makedirs(dst_dir)
LOGGER.info("Downloading {0} => {1}".format(url, dst_path))
self.download_url_content_to_file(url, dst_path)
dst_url = '/'.join(dst_path.split(os.sep)[2:])
links[url] = '/' + dst_url

Expand Down

0 comments on commit 1ed3e80

Please sign in to comment.