From c3ea7e904eed32d7e7dec33a9d30b8d6c3037946 Mon Sep 17 00:00:00 2001 From: Vlad Poberezhny Date: Fri, 20 Nov 2020 16:44:17 +0200 Subject: [PATCH] fix(python3 migration bugs) --- modules/journal/client.py | 24 ++++++++++++++++-------- modules/storage/client.py | 8 ++++---- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/modules/journal/client.py b/modules/journal/client.py index 1653a3c..d93ea24 100644 --- a/modules/journal/client.py +++ b/modules/journal/client.py @@ -23,11 +23,15 @@ def get_timestamp(): return datetime.now().strftime("%B %d, %Y at %H:%M") def command(cmd): - return Popen(shlex.split(cmd), stdout=PIPE).communicate()[0] + return Popen(shlex.split(cmd), stdout=PIPE).communicate()[0].decode() -def read(kiwi, topic): - return command('kiwi storage source -r -S {} -n {}'.format(\ - join(kiwi.module_home, 'sources'), topic)) +def read(kiwi, topic, from_file=None): + if not from_file: + return command('kiwi storage source -r -S {} -n {}'.format(\ + join(kiwi.module_home, 'sources'), topic)) + + return command('kiwi storage retrieve -s file -d {}'.format(\ + from_file)) def get_topics(kiwi): return command('kiwi storage source -l -S {}'.format(\ @@ -50,7 +54,7 @@ def write(kiwi, log, topic): # use storage module to store the journal stdout = command('kiwi storage source -S {} -m "{}" -n {} -c "{}"'.format(\ join(kiwi.module_home, 'sources'), get_timestamp(), topic, log)) - print(stdout.rstrip(), end=' ') + print(stdout.rstrip()) def format_log(log): out = '-'*50 + '\n' @@ -83,17 +87,21 @@ def kiwi_main(kiwi): # list journals elif args.list_topics: - print(get_topics(kiwi), end=' ') + print(get_topics(kiwi)) # print journal elif not args.log and not args.file: - print(read(kiwi, args.topic), end=' ') + print(read(kiwi, args.topic)), # write to journal else: log = args.log if args.file: - log = read(kiwi, args.file) + if isfile(args.file): + log = read(kiwi, args.topic, args.file) + else: + print('Given file does not exist. Make sure the path to file is absolute.') + return write(kiwi, log, args.topic) diff --git a/modules/storage/client.py b/modules/storage/client.py index de3114a..c1195a1 100644 --- a/modules/storage/client.py +++ b/modules/storage/client.py @@ -35,7 +35,7 @@ def github_store(args): headers = {'Content-type': 'application/json'} commit_json = { 'message': args.message if args.message else 'No message', - 'content': base64.b64encode(bytes(args.content), 'utf-8'), + 'content': base64.b64encode(bytes(args.content, "utf-8")).decode(), 'committer': {} } @@ -201,10 +201,10 @@ def kiwi_main(kiwi): arg.destination = os.path.join(arg.destination, args.filename) if args.retrieve: - print(retrieve(arg), end=' ') + print(retrieve(arg)) return elif args.list: - print(list_items(arg), end=' ') + print(list_items(arg)) return else: @@ -242,7 +242,7 @@ def kiwi_main(kiwi): data = retrieve(args) if not args.hide: - print(data, end=' ') + print(data, end='') # store data in a file if args.file: