|
1 | | -import ConfigParser |
| 1 | +try: |
| 2 | + import configparser as ConfigParser |
| 3 | +except: |
| 4 | + import ConfigParser |
2 | 5 | config = ConfigParser.ConfigParser() |
3 | | -import StringIO |
| 6 | +from io import StringIO |
4 | 7 | from itertools import chain |
5 | 8 | import re |
6 | 9 | import sys |
|
30 | 33 |
|
31 | 34 | def read_config(): |
32 | 35 | tmp_config = ConfigParser.ConfigParser() |
33 | | - ini = '[dummysection]\n' + open(os.path.join(os.environ['NETKIT_HOME'], '..', 'config'), 'r').read() |
34 | | - ini_string = StringIO.StringIO(ini) |
| 36 | + ini = u'[dummysection]\n' + open(os.path.join(os.environ['NETKIT_HOME'], '..', 'config'), 'r').read() |
| 37 | + ini_string = StringIO(ini) |
35 | 38 | tmp_config.readfp(ini_string) |
36 | 39 | conf = {} |
37 | 40 | for key, value in tmp_config.items('dummysection'): |
@@ -95,8 +98,8 @@ def lab_parse(path, force=False): |
95 | 98 | return ({}, [], {}, {}) # has to get names from last positional args |
96 | 99 |
|
97 | 100 | # reads lab.conf |
98 | | - ini_str = '[dummysection]\n' + open(os.path.join(path, 'lab.conf'), 'r').read() |
99 | | - ini_fp = StringIO.StringIO(ini_str) |
| 101 | + ini_str = u'[dummysection]\n' + open(os.path.join(path, 'lab.conf'), 'r').read() |
| 102 | + ini_fp = StringIO(ini_str) |
100 | 103 | config.readfp(ini_fp) |
101 | 104 |
|
102 | 105 | # gets 2 list of keys, one for machines and the other for the metadata |
@@ -193,7 +196,7 @@ def create_commands(machines, links, options, metadata, path, execbash=False, no |
193 | 196 |
|
194 | 197 | # writing the network list in the temp file |
195 | 198 | if not execbash: |
196 | | - if not PRINT: u.write_temp(lab_links_text, u.generate_urlsafe_hash(path) + '_links', PLATFORM, file_mode="w+") |
| 199 | + if not PRINT: u.write_temp(lab_links_text, str(u.generate_urlsafe_hash(path)) + '_links', PLATFORM, file_mode="w+") |
197 | 200 |
|
198 | 201 | # generating commands for running the containers, copying the config folder and executing the terminals connected to the containers |
199 | 202 | if PLATFORM != WINDOWS: |
@@ -296,7 +299,7 @@ def create_commands(machines, links, options, metadata, path, execbash=False, no |
296 | 299 | # writing the container list in the temp file |
297 | 300 | if not no_machines_tmp: |
298 | 301 | if not execbash: |
299 | | - if not PRINT: u.write_temp(lab_machines_text, u.generate_urlsafe_hash(path) + '_machines', PLATFORM) |
| 302 | + if not PRINT: u.write_temp(lab_machines_text, str(u.generate_urlsafe_hash(path)) + '_machines', PLATFORM) |
300 | 303 |
|
301 | 304 |
|
302 | 305 | # for each machine we have to get the machine.startup file and insert every non empty line as a string inside an array of exec commands. We also replace escapes and quotes |
|
0 commit comments