mirror of
https://github.com/danieldemus/deconz_fw_downloader.git
synced 2025-01-10 15:12:00 +01:00
Allow suppressing repetitive output
This commit is contained in:
parent
8a3abc319b
commit
e9da0d16b5
2
.gitignore
vendored
2
.gitignore
vendored
@ -159,3 +159,5 @@ cython_debug/
|
|||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
|
||||||
|
.fleet/
|
||||||
|
@ -13,6 +13,9 @@ class Downloader(ABC):
|
|||||||
otau_path = os.path.join(os.path.expanduser('~/otau/'))
|
otau_path = os.path.join(os.path.expanduser('~/otau/'))
|
||||||
log_path = os.path.join(otau_path, 'log.log')
|
log_path = os.path.join(otau_path, 'log.log')
|
||||||
|
|
||||||
|
def __init__(self, verbose):
|
||||||
|
self.verbose = verbose
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_url_list(self):
|
def get_url_list(self):
|
||||||
pass
|
pass
|
||||||
@ -37,6 +40,7 @@ class Downloader(ABC):
|
|||||||
nowish = datetime.now(timezone.utc) + timedelta(seconds=-2)
|
nowish = datetime.now(timezone.utc) + timedelta(seconds=-2)
|
||||||
if delay > nowish:
|
if delay > nowish:
|
||||||
wait = (delay - nowish).seconds + 1
|
wait = (delay - nowish).seconds + 1
|
||||||
|
if self.verbose:
|
||||||
print(f"Some downloads were deferred by the server. Waiting {wait} seconds until retry", end='', flush=True)
|
print(f"Some downloads were deferred by the server. Waiting {wait} seconds until retry", end='', flush=True)
|
||||||
ix = 0
|
ix = 0
|
||||||
while ix < wait:
|
while ix < wait:
|
||||||
@ -60,6 +64,7 @@ class Downloader(ABC):
|
|||||||
|
|
||||||
def download_file(self, url, filename, retries):
|
def download_file(self, url, filename, retries):
|
||||||
if filename and os.path.isfile(os.path.join(self.otau_path, filename)):
|
if filename and os.path.isfile(os.path.join(self.otau_path, filename)):
|
||||||
|
if self.verbose:
|
||||||
print(f"{filename} skipped. A file with that name already exists")
|
print(f"{filename} skipped. A file with that name already exists")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -92,6 +97,7 @@ class Downloader(ABC):
|
|||||||
print(f"{fname} downloaded")
|
print(f"{fname} downloaded")
|
||||||
self.write_log(src, fname, len(firmwarecontent))
|
self.write_log(src, fname, len(firmwarecontent))
|
||||||
else:
|
else:
|
||||||
|
if self.verbose:
|
||||||
print(f"{fname} skipped. A file with that name already exists")
|
print(f"{fname} skipped. A file with that name already exists")
|
||||||
else:
|
else:
|
||||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||||
@ -103,14 +109,17 @@ class Downloader(ABC):
|
|||||||
file.close()
|
file.close()
|
||||||
if list(filter(lambda ext: fname.endswith(ext), self.archive_extensions)):
|
if list(filter(lambda ext: fname.endswith(ext), self.archive_extensions)):
|
||||||
shutil.unpack_archive(fullname, tmpdirname)
|
shutil.unpack_archive(fullname, tmpdirname)
|
||||||
|
if self.verbose:
|
||||||
print(f"Downloaded and unpacked {fname}")
|
print(f"Downloaded and unpacked {fname}")
|
||||||
for f in self.filtered_filelist(tmpdirname):
|
for f in self.filtered_filelist(tmpdirname):
|
||||||
target = os.path.join(self.otau_path, os.path.basename(f))
|
target = os.path.join(self.otau_path, os.path.basename(f))
|
||||||
if not os.path.isfile(target):
|
if not os.path.isfile(target):
|
||||||
shutil.copyfile(f, target)
|
shutil.copyfile(f, target)
|
||||||
|
if self.verbose:
|
||||||
print(f"Extracted {os.path.basename(f)}")
|
print(f"Extracted {os.path.basename(f)}")
|
||||||
self.write_log(fname, os.path.basename(f), os.path.getsize(f))
|
self.write_log(fname, os.path.basename(f), os.path.getsize(f))
|
||||||
else:
|
else:
|
||||||
|
if self.verbose:
|
||||||
print('%s skipped. A file with that name already exists' % os.path.basename(f))
|
print('%s skipped. A file with that name already exists' % os.path.basename(f))
|
||||||
else:
|
else:
|
||||||
print(f"{fname} is not a supported file type")
|
print(f"{fname} is not a supported file type")
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
Snipped to download current IKEA ZLL OTA files into ~/otau
|
Snipped to download current IKEA ZLL OTA files into ~/otau
|
||||||
compatible with python 3.
|
compatible with python 3.
|
||||||
"""
|
"""
|
||||||
|
import argparse
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from danfoss import Danfoss
|
from danfoss import Danfoss
|
||||||
@ -11,11 +11,17 @@ from ikea import Ikea
|
|||||||
from github_koenkk import GithubKoenkk
|
from github_koenkk import GithubKoenkk
|
||||||
from ligthify import Lightify
|
from ligthify import Lightify
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
prog = 'fw_downloads.py',
|
||||||
|
description = 'Downloads zigbee firmware update files from various sources for the Deconz OTA plugin')
|
||||||
|
parser.add_argument('-v', '--verbose', action='store_true', help='write each file operation to the console')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
print ('%s - Downloadscript started' % f"{datetime.datetime.now():%Y-%m-%d %H:%M:%S}")
|
print ('%s - Downloadscript started' % f"{datetime.datetime.now():%Y-%m-%d %H:%M:%S}")
|
||||||
|
|
||||||
Danfoss().perform_downloads()
|
Danfoss(args.verbose).perform_downloads()
|
||||||
Ikea().perform_downloads()
|
Ikea(args.verbose).perform_downloads()
|
||||||
GithubKoenkk().perform_downloads()
|
GithubKoenkk(args.verbose).perform_downloads()
|
||||||
Lightify().perform_downloads()
|
Lightify(args.verbose).perform_downloads()
|
||||||
|
|
||||||
print ('%s - Downloadscript finished' % f"{datetime.datetime.now():%Y-%m-%d %H:%M:%S}")
|
print ('%s - Downloadscript finished' % f"{datetime.datetime.now():%Y-%m-%d %H:%M:%S}")
|
||||||
|
Loading…
Reference in New Issue
Block a user