- update .gitignore to ignore python bytecode

- move log-routine to pyf
- add feature to check_update to properly check if the file exists
This commit is contained in:
willip 2019-03-08 11:53:21 +00:00
parent 1881492546
commit e6857efe04
4 changed files with 23 additions and 24 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
*.swp *.swp
Session.vim Session.vim
__pycache__ __pycache__/
*.py[cod]

Binary file not shown.

11
pyf.py
View File

@ -4,6 +4,16 @@ import os
WORKDIR = os.getcwd() 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): def prt(message):
''' print a message with style ''' ''' print a message with style '''
print('::: {}'.format(message)) print('::: {}'.format(message))
@ -18,7 +28,6 @@ def download(url, file_name, progress=True):
if progress: if progress:
from tqdm import tqdm from tqdm import tqdm
prt('downloading {}'.format(url)) prt('downloading {}'.format(url))
file_name = '{}/{}'.format(WORKDIR, url.split('/')[-1])
class TqdmUpTo(tqdm): class TqdmUpTo(tqdm):
def update_to(self, b=1, bsize=1, tsize=None): def update_to(self, b=1, bsize=1, tsize=None):
if tsize is not None: if tsize is not None:

View File

@ -1,7 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from pprint import pprint from pprint import pprint
import daemon import daemon
import time import time
@ -10,14 +9,10 @@ import os
import json import json
from pyf import download, prt from pyf import download, prt
WORKDIR = os.getcwd() WORKDIR = os.getcwd()
TMP = '/tmp/quickos.log'
def init_parser(): def init_parser():
''' initialize the argument parser ''' initialize the argument parser
@return agrs: the parsed arguments @return agrs: the parsed arguments
@ -33,16 +28,6 @@ def init_parser():
return parser.parse_args() 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 # algo check if new version should be downloaded
# a: is image file there? # a: is image file there?
# -> no: download image file # -> no: download image file
@ -64,15 +49,19 @@ def check_update(database):
''' check if update is necessary ''' ''' check if update is necessary '''
from urllib.parse import urlparse from urllib.parse import urlparse
from os import path from os import path
for name, ops in database.items(): for name, dist in database.items():
prt('checking operating system {} ...'.format(name)) prt('checking operating system {} ...'.format(name))
if ops['file_name'] == '': if dist['file_name'] == '':
file_name = urlparse(ops['file_url']) file_name = urlparse(dist['file_url'])
file_name = file_name.path file_name = file_name.path
file_name = path.basename(file_name) file_name = '{}/dist/{}'.format(WORKDIR, path.basename(file_name))
print(file_name) download(dist['file_url'], file_name)
download(ops['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 continue