|
7 | 7 |
|
8 | 8 | import datetime |
9 | 9 | import math |
| 10 | +import os |
10 | 11 | import struct |
11 | 12 | from PIL import Image |
12 | 13 |
|
13 | 14 | YEAR_2000 = datetime.datetime(2000, 1, 1) |
14 | 15 |
|
| 16 | +# Find this script's directory, then navigate from there to the common |
| 17 | +# directory, which has some files we need to read. |
| 18 | +# This way of specifying the directory is better than '../common' since the |
| 19 | +# script's directory doesn't have to be the current working directory. |
| 20 | +# http://stackoverflow.com/a/9350788/ |
| 21 | +script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 22 | +common_dir = os.path.join(script_dir, os.pardir, 'common') |
| 23 | + |
| 24 | + |
15 | 25 | def short_filename(filename, seconds_since_start_of_2000): |
16 | 26 | if not filename: |
17 | 27 | return "fze0200002000{:14X}.dat".format(int(seconds_since_start_of_2000 * 40500000)) |
@@ -143,7 +153,8 @@ def banner(img32, alpha_threshold): |
143 | 153 | emblem file. (The left 2/3rds of the banner are the same for |
144 | 154 | every emblem.) |
145 | 155 | """ |
146 | | - banner_base_file = open("../common/emblem_banner_base", 'rb') |
| 156 | + banner_base_file = open( |
| 157 | + os.path.join(common_dir, 'emblem_banner_base'), 'rb') |
147 | 158 | banner_bytes = bytearray() |
148 | 159 | img32_data = img32.getdata() |
149 | 160 |
|
@@ -176,7 +187,7 @@ def icon(): |
176 | 187 | emblem file's icon, in the same pixel format as any emblem file. |
177 | 188 | (The icon is the same for every emblem.) |
178 | 189 | """ |
179 | | - return open("../common/emblem_icon", 'rb').read() |
| 190 | + return open(os.path.join(common_dir, 'emblem_icon'), 'rb').read() |
180 | 191 |
|
181 | 192 | def edge_options(img, edge_option): |
182 | 193 | # Image.LANCZOS constant requires Pillow 2.7 or higher. |
|
0 commit comments