[ba924ed] | 1 | |
---|
| 2 | |
---|
| 3 | import os |
---|
| 4 | from distutils.filelist import findall |
---|
| 5 | |
---|
| 6 | def get_data_path(media): |
---|
| 7 | """ |
---|
| 8 | """ |
---|
| 9 | # Check for data path in the package |
---|
| 10 | path = os.path.join(os.path.dirname(__file__), media) |
---|
| 11 | if os.path.isdir(path): |
---|
| 12 | return path |
---|
| 13 | |
---|
| 14 | # Check for data path next to exe/zip file. |
---|
| 15 | # If we are inside a py2exe zip file, we need to go up |
---|
| 16 | # to get to the directory containing |
---|
| 17 | # the media for this module |
---|
| 18 | path = os.path.dirname(__file__) |
---|
| 19 | #Look for maximum n_dir up of the current dir to find media |
---|
| 20 | n_dir = 12 |
---|
| 21 | for i in range(n_dir): |
---|
| 22 | path, _ = os.path.split(path) |
---|
| 23 | media_path = os.path.join(path, media) |
---|
| 24 | if os.path.isdir(media_path): |
---|
[631be82] | 25 | module_media_path = os.path.join(media_path, 'icons') |
---|
[ba924ed] | 26 | if os.path.isdir(module_media_path): |
---|
| 27 | return module_media_path |
---|
| 28 | return media_path |
---|
| 29 | |
---|
| 30 | raise RuntimeError('Could not find guiframe images files') |
---|
| 31 | |
---|
[823859a] | 32 | def get_media_path(media): |
---|
| 33 | """ |
---|
| 34 | """ |
---|
| 35 | # Check for data path in the package |
---|
| 36 | path = os.path.join(os.path.dirname(__file__), media) |
---|
| 37 | if os.path.isdir(path): |
---|
| 38 | return path |
---|
| 39 | |
---|
| 40 | # Check for data path next to exe/zip file. |
---|
| 41 | # If we are inside a py2exe zip file, we need to go up |
---|
| 42 | # to get to the directory containing |
---|
| 43 | # the media for this module |
---|
| 44 | path = os.path.dirname(__file__) |
---|
| 45 | #Look for maximum n_dir up of the current dir to find media |
---|
| 46 | n_dir = 12 |
---|
| 47 | for i in range(n_dir): |
---|
| 48 | path, _ = os.path.split(path) |
---|
| 49 | media_path = os.path.join(path, media) |
---|
| 50 | if os.path.isdir(media_path): |
---|
| 51 | module_media_path = os.path.join(media_path, 'guiframe_media') |
---|
| 52 | if os.path.isdir(module_media_path): |
---|
| 53 | return module_media_path |
---|
| 54 | return media_path |
---|
| 55 | raise RuntimeError('Could not find guiframe media files') |
---|
| 56 | |
---|
[ba924ed] | 57 | def data_files(): |
---|
| 58 | """ |
---|
| 59 | Return the data files associated with guiframe images . |
---|
| 60 | |
---|
| 61 | The format is a list of (directory, [files...]) pairs which can be |
---|
| 62 | used directly in setup(...,data_files=...) for setup.py. |
---|
| 63 | |
---|
| 64 | """ |
---|
| 65 | data_files = [] |
---|
| 66 | path = get_data_path(media="images") |
---|
| 67 | for f in findall(path): |
---|
[631be82] | 68 | data_files.append(('images/icons', [f])) |
---|
[823859a] | 69 | path = get_media_path(media="media") |
---|
[b2629b4] | 70 | for f in findall(path): |
---|
[823859a] | 71 | data_files.append(('media/guiframe_media', [f])) |
---|
[ba924ed] | 72 | return data_files |
---|