diff --git a/.gitignore b/.gitignore index 223f15a..6fc6cad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.swp Session.vim -__pycache__ +__pycache__/ +*.py[cod] diff --git a/__pycache__/pyf.cpython-35.pyc b/__pycache__/pyf.cpython-35.pyc index e8039a8..3e79dd9 100644 Binary files a/__pycache__/pyf.cpython-35.pyc and b/__pycache__/pyf.cpython-35.pyc differ diff --git a/pyf.py b/pyf.py index 3159066..98ac5c3 100644 --- a/pyf.py +++ b/pyf.py @@ -4,6 +4,16 @@ import os WORKDIR = os.getcwd() + +TMP = '/tmp/quickos.log' +def log(message): + ''' write to logfile TMP + @param message: the message which shall be written to the log file + ''' + with open(TMP, 'a') as f: + f.write('{} {}\n'.format(time.ctime(), message)) + + def prt(message): ''' print a message with style ''' print('::: {}'.format(message)) @@ -18,7 +28,6 @@ def download(url, file_name, progress=True): if progress: from tqdm import tqdm prt('downloading {}'.format(url)) - file_name = '{}/{}'.format(WORKDIR, url.split('/')[-1]) class TqdmUpTo(tqdm): def update_to(self, b=1, bsize=1, tsize=None): if tsize is not None: diff --git a/quickos.py b/quickos.py index dfa7997..0a264e4 100755 --- a/quickos.py +++ b/quickos.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 - from pprint import pprint import daemon import time @@ -10,14 +9,10 @@ import os import json from pyf import download, prt + WORKDIR = os.getcwd() - -TMP = '/tmp/quickos.log' - - - def init_parser(): ''' initialize the argument parser @return agrs: the parsed arguments @@ -33,16 +28,6 @@ def init_parser(): return parser.parse_args() - -def log(message): - ''' write to logfile TMP - @param message: the message which shall be written to the log file - ''' - with open(TMP, 'a') as f: - f.write('{} {}\n'.format(time.ctime(), message)) - - - # algo check if new version should be downloaded # a: is image file there? # -> no: download image file @@ -64,15 +49,19 @@ def check_update(database): ''' check if update is necessary ''' from urllib.parse import urlparse from os import path - for name, ops in database.items(): + for name, dist in database.items(): prt('checking operating system {} ...'.format(name)) - if ops['file_name'] == '': - file_name = urlparse(ops['file_url']) + if dist['file_name'] == '': + file_name = urlparse(dist['file_url']) file_name = file_name.path - file_name = path.basename(file_name) - print(file_name) - download(ops['file_url'], file_name) + file_name = '{}/dist/{}'.format(WORKDIR, path.basename(file_name)) + download(dist['file_url'], file_name) + continue + + file_name = '{}/dist/{}'.format(WORKDIR, dist['file_name']) + if not path.isfile(file_name): + download(dist['file_url'], file_name) continue