Skip to content

Commit 60b48aa

Browse files
committed
Add force_unzip, progress bar during unzip, unzip_path. Updated README.
1 parent 5ca551a commit 60b48aa

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ __pycache__
33
*.pyc
44
.pypirc
55
.vscode
6-
dist
6+
dist
7+
build
8+
onedrivedownloader.egg-info

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
First stable release: `1.0.0`
88

9+
Current: `1.0.2`
10+
11+
*Do not require authentication.*
12+
913
### Requires
1014
- `tqdm`: for nice progress bar
1115
- `requests`: fetch data from OneDrive

onedrivedownloader/main.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def _create_if_not_exists(path: str, remove=True) -> None:
2626

2727
os.makedirs(path, exist_ok=True)
2828

29-
def download(url: str, filename: str, unzip=False, unzip_path: str = None, force_download=False, clean=False) -> None:
29+
def download(url: str, filename: str, unzip=False, unzip_path: str = None, force_download=False, force_unzip=False, clean=False) -> None:
3030
"""
3131
Download a file from a OneDrive url.
3232
@@ -36,6 +36,7 @@ def download(url: str, filename: str, unzip=False, unzip_path: str = None, force
3636
:param unzip: Whether to unzip the file.
3737
:param unzip_path: The path to unzip the file to. Default is current path.
3838
:param force_download: Whether to force download the file even if it already exists.
39+
:param force_unzip: Whether to force unzip and overwrite the file even if it already exists.
3940
:param clean: Whether to clean the unzipped files after unzipping.
4041
"""
4142

@@ -49,9 +50,6 @@ def download(url: str, filename: str, unzip=False, unzip_path: str = None, force
4950
progress_bar = tqdm(total=total_size_in_bytes, unit='iB', unit_scale=True) if total_size_in_bytes > 1024 else None
5051
block_size = 1024
5152

52-
# parent if filename has a path else current path
53-
parent_path = os.path.split(filename)[0] if os.path.split(filename)[0] != '' else os.getcwd()
54-
5553
if not os.path.exists(filename) or force_download:
5654
_create_if_not_exists(filename)
5755

@@ -72,13 +70,18 @@ def download(url: str, filename: str, unzip=False, unzip_path: str = None, force
7270
if unzip:
7371
assert filename.endswith(".zip"), "ERROR: file is not a zip file!"
7472

75-
clean_unzip_path = unzip_path is not None and os.path.realpath(unzip_path) not in os.path.realpath(filename)
73+
unzip_path = unzip_path if unzip_path is not None else os.path.split(filename)[0]
74+
clean_unzip_path = force_unzip and os.path.realpath(unzip_path) not in os.path.realpath(filename)
7675

77-
print("Extracting files...")
78-
7976
_create_if_not_exists(unzip_path, remove=clean_unzip_path)
77+
78+
if force_unzip:
79+
print("Warning: overwriting existing files!")
80+
8081
with zipfile.ZipFile(filename, 'r') as zip_ref:
81-
zip_ref.extractall(unzip_path)
82+
for file in tqdm(iterable=zip_ref.namelist(), total=len(zip_ref.namelist()), desc="Extracting files"):
83+
if not os.path.exists(os.path.join(unzip_path, file)) or force_unzip:
84+
zip_ref.extract(member=file, path=unzip_path)
8285

8386
if clean:
8487
os.remove(filename)

setup.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
from distutils.core import setup
1+
from setuptools import setup, find_packages
2+
3+
with open("README.md", "r", encoding="utf-8") as fh:
4+
long_description = fh.read()
5+
with open("requirements.txt", "r", encoding="utf-8") as fh:
6+
requirements = fh.read()
7+
28
setup(
39
name='onedrivedownloader',
4-
packages=['onedrivedownloader'],
5-
version='1.0.1',
10+
packages=find_packages(),
11+
version='1.0.2',
612
license='MIT',
713
description='Python utility to download files through OneDrive',
14+
long_description=long_description,
15+
long_description_content_type="text/markdown",
816
author='Lorenzo Bonicelli',
917
author_email='[email protected]',
1018
url='https://github.com/loribonna/onedrivedownloader',
11-
download_url='https://github.com/loribonna/onedrivedownloader/archive/refs/tags/v1.0.1.zip',
12-
keywords=['onedrive', 'downloader', 'python', 'utility'],
13-
install_requires=[
14-
'requests',
15-
'tqdm'
16-
],
19+
download_url='https://github.com/loribonna/onedrivedownloader/archive/refs/tags/v1.0.2.zip',
20+
keywords=['onedrive', 'downloader', 'download', 'python', 'utility'],
21+
install_requires=[requirements],
1722
classifiers=[
1823
'Development Status :: 3 - Alpha',
1924
'Intended Audience :: Developers',

0 commit comments

Comments
 (0)