From 227ec54ab23f1e82fe29dbc379a071dd2e44b0cc Mon Sep 17 00:00:00 2001 From: Dan Howe Date: Mon, 18 Mar 2019 21:50:51 +1100 Subject: [PATCH] Fix filepath problem for non-Windows platforms --- major_projects_grabber/major_projects_grabber.py | 9 ++++++--- setup.py | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/major_projects_grabber/major_projects_grabber.py b/major_projects_grabber/major_projects_grabber.py index ee88659..5d657ce 100644 --- a/major_projects_grabber/major_projects_grabber.py +++ b/major_projects_grabber/major_projects_grabber.py @@ -121,12 +121,15 @@ def download_document(url, document_path): # Check if destination path is too long (Windows filename limitation) try: + # Create output directories as required + os.makedirs(os.path.dirname(document_path), exist_ok=True) + + # Check if empty file can be created in this location open(document_path, 'a').close() except FileNotFoundError: + # Tweak long path for Windows document_path = '\\\\?\\' + os.path.abspath(document_path) - - # Create output directories as required - os.makedirs(os.path.dirname(document_path), exist_ok=True) + os.makedirs(os.path.dirname(document_path), exist_ok=True) # Check if a non-empty file exists if os.path.isfile(document_path) and os.path.getsize(document_path) > 0: diff --git a/setup.py b/setup.py index 83a069e..b4c23d4 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup setup( name='major_projects_grabber', - version='0.2.0', + version='0.2.1', packages=['major_projects_grabber'], install_requires=['requests', 'lxml', 'tqdm'], entry_points={