summarylogtreecommitdiffstats
path: root/londonlaw-setup.py
blob: c76d8ddd9edd4960e8b6630320a220f247eb509f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python
#
# Distutils installation script for London Law
#
from setuptools import setup
import io, os, string, sys

def read(*paths, **kwargs):
    """Read the contents of a text file safely.
    >>> read("project_name", "VERSION")
    '0.1.0'
    >>> read("README.md")
    ...
    """

    content = ""
    with io.open(
        os.path.join(os.path.dirname(__file__), *paths),
        encoding=kwargs.get("encoding", "utf8"),
    ) as open_file:
        content = open_file.read().strip()
    return content


def read_requirements(path):
    return [
        line.strip()
        for line in read(path).split("\n")
        if not line.startswith(('"', "#", "-", "git+"))
    ]


# Generate the binary translation files
if 'sdist' in sys.argv:
   os.system("cd londonlaw/locale && make mo")
   os.system("cd doc && make")


# Read off the PREFIX value, so we can tell londonlaw where to find its
# data files (FIXME: is there a clean way to handle this through distutils?)
if 'sdist' not in sys.argv and 'clean' not in sys.argv:
   DATA_PREFIX=os.path.normpath(sys.prefix)+"/share/"  # default
   for arg in sys.argv:
      index = arg.find("--install-data=")
      if index > -1:
         DATA_PREFIX = os.path.normpath(arg[(index+len("--install-data=")):])

   config = open("londonlaw/common/config.py", "w")
   config.write("MEDIAROOT = \"" + os.path.join(DATA_PREFIX,"londonlaw/guiclient") + "\"\n")
   config.close()


# Append "dirname" and its datafiles to the list of files to install.
# This is called once per directory via os.path.walk().
def appendImageFiles(installList, dirname, files):
   newFiles = []
   for file in files:
      if file[-3:] != ".id" and file[-3:] != "=id":   # don't install Arch id files
         fullFile = os.path.join(dirname, file)
         if os.path.isfile(fullFile):
            newFiles.append(fullFile)
   if newFiles != []:
      splitDir = dirname.split('/')
      dirname = ('/').join(splitDir[1:])
      installList.append( (os.path.join(DATA_PREFIX, 'londonlaw', dirname), newFiles) )
      #installList.append( (dirname, newFiles) )


def appendMOFiles(installList, dirname, files):
   newFiles = []
   for file in files:
      if file[-3:] == ".mo":
         newFiles.append(os.path.join(dirname, file))
   if newFiles != []:
      splitDir = dirname.split('/')
      dirname = ('/').join(splitDir[1:])
      installList.append( (os.path.join(DATA_PREFIX, 'londonlaw', dirname), newFiles) )
      #installList.append( (dirname, newFiles) )


# Get all data files by walking through the proper directory trees
# and calling 'appendDataFiles'.
def getDataFilesList():
   installList = []
   os.walk('londonlaw/guiclient/images', appendImageFiles, installList)
   os.walk('londonlaw/locale', appendMOFiles, installList)
   return installList

## Run the distutils setup.
#setup(name = "londonlaw",
#   version = "0.3.0pre2",
#   description = "Networke clone of the famous Scotland Yard manhunt board game",
#   author = "Paul J. Pelzl",
#   author_email = "pelzlpj@eecs.umich.edu",
#   maintainer = "Paul J. Pelzl",
#   maintainer_email = "pelzlpj@eecs.umich.edu", 
#   url = "https://github.com/horald/londonlaw", 
#   license = "GNU General Public License, Version 2",
#   platforms = "*nix/X11, OS X, Win32",
#   keywords = "Scotland Yard board game multiplayer",
#   long_description = ( 
#      "London Law is a networked multiplayer adaptation of the classic\n" +
#      "Scotland Yard board game.  Mr. X must evade a number of detectives by\n" +
#      "carefully concealing his movements across London.  One of only a\n" +
#      "handful of asymmetric board games (Mr. X and the detectives have\n" +
#      "different goals and abilities)." ),
#   packages = [ 'londonlaw',                      # install all the .py files
#                'londonlaw.common',
#                'londonlaw.server',
#                'londonlaw.guiclient',
#                'londonlaw.aiclients',
#                'londonlaw.adminclient'],
#   scripts  = [ 'londonlaw/london-server',        # install the executable scripts
#                'londonlaw/london-client',
#                'londonlaw/london-admin'],
#   data_files = getDataFilesList()                # install the game media and documentation
#)


# Reset 'config.py' for the source distribution.
config = open("londonlaw/common/config.py", "w")
config.write("MEDIAROOT = \"guiclient\"\n")
config.close()
setup(
    name="londonlaw",
    version="0.3.0pre2",
    description="Clone of the famous Scotland Yard board game",
    url="https://github.com/horald/londonlaw",
    license = "GNU General Public License, Version 2",
    platforms = "*nix/X11, OS X, Win32",
    author = "Paul J. Pelzl",
    maintainer = "horald",
    keywords = "Scotland Yard board game multiplayer",
    long_description = ( 
       "London Law is a networked multiplayer adaptation of the classic\n" +
       "Scotland Yard board game.  Mr. X must evade a number of detectives by\n" +
       "carefully concealing his movements across London.  One of only a\n" +
       "handful of asymmetric board games (Mr. X and the detectives have\n" +
       "different goals and abilities)." ),
    packages = [ 'londonlaw',                      # install all the .py files
                 'londonlaw.common',
                 'londonlaw.server',
                 'londonlaw.guiclient',
                 'londonlaw.aiclients',
                 'londonlaw.adminclient'],
    scripts  = [ 'londonlaw/london-server',        # install the executable scripts
                 'londonlaw/london-client',
                 'londonlaw/london-admin.py'],
    install_requires=read_requirements("requirements.txt"),
    data_files = getDataFilesList()                # install the game media and documentation
)