Ticket #275: setup.py

File setup.py, 3.1 KB (added by Aspidites <aspidites@…>, 8 years ago)
Line 
1#!/usr/bin/env python2
2"""
3Cross-platform setup script responsible for creating source and binary
4packages for Linux, Windows, and Mac
5"""
6import logging
7import platform
8import sys
9import os
10
11from distutils.core import setup
12
13logging.basicConfig(filename='setup.log')
14
15
16
17def rename_script():
18    #TODO: flesh out for windows and mac
19    """
20    Rename the run.py script to something more suitable depending
21    on the platform.
22    """
23
24    if platform.system() == 'Linux':
25        if os.path.isfile(os.path.join('game', 'run.py')):
26            os.rename(os.path.join('game', 'run.py'), 'parpg')
27        elif os.path.isfile('parpg'):
28            os.rename('parpg', os.path.join('game', 'run.py'))
29
30def walk_and_ignore(directory, ignore):
31    """
32    Modification of os.walk that allows for directories to be ignored
33    """
34    for root, dirnames, filenames in os.walk(directory):
35        dirnames[:] = [dirname for dirname in dirnames
36                       if dirname not in ignore]
37        yield root, dirnames, filenames
38
39def files(directory):
40    """
41    Returns a list of tuples containing the directory name and the files
42    within them recursively.
43    """
44
45    files = []
46
47    for root, dirnames, filenames in walk_and_ignore(directory, ['.svn']):
48        for index, filename in enumerate(filenames[:]):
49            # expand filenames to their full paths
50            filenames[index] = os.path.abspath(os.path.join(root, filename))
51
52        root = root.replace(os.path.dirname(root), 
53                            os.path.join('share', 'parpg', 
54                                         os.path.basename(directory)))
55        print root
56        files.append((root, filenames))
57     
58    return files
59
60def cross_platform_args():
61    """
62    Returns a dictionary of arguments that are the same across all
63    operating systems.
64    """
65    args = dict(name='parpg-svn',
66                version='693',
67                description='Post-apocalyptic RPG',
68                author='mvbarracuda',
69                url='http://parpg.net',
70                package_dir={'parpg': os.path.join('game', 'parpg')},
71                packages=['parpg',
72                          'parpg.common', 'parpg.common.listeners',
73                          'parpg.gui', 'parpg.objects'],
74                requires=['yaml', 'fife'])
75
76    return args
77
78def linux_args():
79    """
80    Returns  the dictionary of cross-platform arguments with Linux-specific
81    arguments appended
82    """
83
84    args = cross_platform_args()
85    args['scripts'] = ['parpg']
86    args['data_files'] = []
87
88    for directory in ['fonts', 'gui', 'maps', 'music', 
89                      'objects', 'quests', 'saves']:
90        args['data_files'] += files(os.path.join('game', directory))
91
92    return args
93
94# rename run.py to something more platform friendly
95rename_script()
96if platform.system() == 'Linux':
97    setup(**linux_args())
98else:
99    #TODO: actually support windows and mac
100    logging.error('Sorry, {0} is currently not supported'.format(platform.system()))
101    print 'Setup failed. Please see log for more details.'
102    sys.exit(0)
103# rename platform executable back to run.py
104rename_script()