- 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:
parent
1881492546
commit
e6857efe04
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
*.swp
|
||||
Session.vim
|
||||
__pycache__
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
|
Binary file not shown.
11
pyf.py
11
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:
|
||||
|
33
quickos.py
33
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
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user