Browse code

Switch to Python 3.

Xavier G authored on18/11/2019 07:53:46
Showing4 changed files

... ...
@@ -1,4 +1,4 @@
1
-#!/usr/bin/env python
1
+#!/usr/bin/env python3
2 2
 # -*- coding: utf-8 -*-
3 3
 # Copyright © 2017-2019 Xavier G. <xavier.boobank@kindwolf.org>
4 4
 # This work is free. You can redistribute it and/or modify it under the
... ...
@@ -1,4 +1,4 @@
1
-#!/usr/bin/env python
1
+#!/usr/bin/env python3
2 2
 # -*- coding: utf-8 -*-
3 3
 # Copyright © 2017-2019 Xavier G. <xavier.boobank@kindwolf.org>
4 4
 # This work is free. You can redistribute it and/or modify it under the
... ...
@@ -45,21 +45,22 @@ def run_boobank(conf):
45 45
                                        stdout=subprocess.PIPE, close_fds=True, bufsize=-1)
46 46
     # Send all commands at once:
47 47
     for command in commands:
48
-        boobank_process.stdin.write(command['command'] + "\n")
49
-    boobank_process.stdin.write("quit\n")
48
+        command_line = command['command'] + "\n"
49
+        boobank_process.stdin.write(command_line.encode('utf-8'))
50
+    boobank_process.stdin.write("quit\n".encode('utf-8'))
50 51
     boobank_process.stdin.flush()
51 52
     boobank_process.stdin.close()
52 53
     # Parse output to extract relevant lines only:
53 54
     out_time = time.time()
54 55
     out_lines = []
55 56
     while True:
56
-        out_line = boobank_process.stdout.readline()
57
+        out_line = boobank_process.stdout.readline().decode('utf-8')
57 58
         if not out_line:
58 59
             break
59 60
         rem = re.search(r'^boobank>\s*(.+)$', out_line)
60 61
         if rem:
61 62
             out_lines.append(rem.group(1))
62
-    for i in xrange(len(commands)):
63
+    for i in range(len(commands)):
63 64
         out_data = json.loads(out_lines[i])
64 65
         commands[i]['result'] = {'timestamp': out_time, 'data': out_data}
65 66
     return results
... ...
@@ -96,7 +97,7 @@ def write_cache(results):
96 97
         if 'data' not in command['result'] or not command['result']['data']:
97 98
             continue
98 99
         cache_path = os.path.expanduser(command['cache_path'])
99
-        mkdir(os.path.dirname(cache_path), 0700)
100
+        mkdir(os.path.dirname(cache_path), 0o700)
100 101
         with open(cache_path, 'w') as filedesc:
101 102
             json.dump(command['result'], filedesc, indent=4)
102 103
 
... ...
@@ -1,4 +1,4 @@
1
-#!/usr/bin/env python
1
+#!/usr/bin/env python3
2 2
 # -*- coding: utf-8 -*-
3 3
 # Copyright © 2017-2019 Xavier G. <xavier.boobank@kindwolf.org>
4 4
 # This work is free. You can redistribute it and/or modify it under the
... ...
@@ -71,7 +71,7 @@ def send_account(graphite_socket, account, timestamp):
71 71
     pattern = '%s %.2f %d\n'
72 72
     values = (get_path(account), float(account['balance']), int(timestamp))
73 73
     line = pattern % values
74
-    graphite_socket.send(line)
74
+    graphite_socket.send(line.encode('utf-8'))
75 75
 
76 76
 if __name__ == '__main__':
77 77
     main()
... ...
@@ -1,4 +1,4 @@
1
-#!/usr/bin/env python
1
+#!/usr/bin/env python3
2 2
 # -*- coding: utf-8 -*-
3 3
 # Copyright © 2017-2019 Xavier G. <xavier.boobank@kindwolf.org>
4 4
 # This work is free. You can redistribute it and/or modify it under the