equal
deleted
inserted
replaced
11 # |
11 # |
12 # Contributors: |
12 # Contributors: |
13 # |
13 # |
14 # Description: |
14 # Description: |
15 # |
15 # |
|
16 import os |
|
17 import shutil |
16 |
18 |
17 def hex_to_bindata(hexdata): |
19 def hex_to_bindata(hexdata): |
18 hexdata = hexdata.replace(' ', '').replace('\r', '').replace('\n', '').replace('\t', '') |
20 hexdata = hexdata.replace(' ', '').replace('\r', '').replace('\n', '').replace('\t', '') |
19 if len(hexdata) % 2 != 0: |
21 if len(hexdata) % 2 != 0: |
20 raise ValueError("'%s' is not divisible by 2", hexdata) |
22 raise ValueError("'%s' is not divisible by 2", hexdata) |
26 for i in xrange(len(hexdata) / 2): |
28 for i in xrange(len(hexdata) / 2): |
27 start = i * 2 |
29 start = i * 2 |
28 end = start + 2 |
30 end = start + 2 |
29 temp.append(chr(int(hexdata[start:end], 16))) |
31 temp.append(chr(int(hexdata[start:end], 16))) |
30 return ''.join(temp) |
32 return ''.join(temp) |
|
33 |
|
34 def remove_if_exists(path_or_paths): |
|
35 """Remove files or directories if they exist. |
|
36 @param path_or_paths: The path to remove. Can also be a list of paths.""" |
|
37 if isinstance(path_or_paths, list): |
|
38 paths = path_or_paths |
|
39 else: |
|
40 paths = [path_or_paths] |
|
41 |
|
42 for path in paths: |
|
43 if os.path.isdir(path): |
|
44 shutil.rmtree(path) |
|
45 elif os.path.isfile(path): |
|
46 os.remove(path) |