Skip to content

Commit

Permalink
fix(python3 migration bugs)
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad-pbr committed Nov 20, 2020
1 parent 3de4c04 commit c3ea7e9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
24 changes: 16 additions & 8 deletions modules/journal/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(\
Expand All @@ -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'
Expand Down Expand Up @@ -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)
8 changes: 4 additions & 4 deletions modules/storage/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': {}
}

Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit c3ea7e9

Please sign in to comment.