File: main.aap

package info (click to toggle)
aap 1.072-1.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 4,976 kB
  • ctags: 2,160
  • sloc: python: 15,113; makefile: 62; sh: 13
file content (248 lines) | stat: -rwxr-xr-x 8,418 bytes parent folder | download | duplicates (2)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# Main Recipe for Aap

# These targets can be used:
:attr test {comment = Test for obvious problems}
:attr all {comment = Same as "test"}
:attr clean {comment = Cleanup after testing}
:attr fetch {comment = Obtain latest version from CVS}
:attr install {comment = Install Aap; use PREFIX=path to specify where; use FULLDOCS=no to skip installing HTML and PDF docs; use HTMLDIR=/html to install HTML files in a subdirectory}
:attr uninstall {comment = Uninstall current version of Aap; use PREFIX=path to specify where; use VERSION=1.123 to specify a different version}
:attr tags {comment = Create a tags file (requires Exuberant ctags)}

# Testing is defined in a separate recipe.  The "testall" target does the work.
:child test.aap

# The default is to run the tests, because that is harmless.
test all: testall

# Install all docs by default.
FULLDOCS ?= yes


fetch:
    @if not os.path.exists("_no.CVS"):
	:error Can only fetch after checkout from CVS.
    @else:
	:fetch {fetch = cvs://} .

# Install:
# - copy the relevant files to /usr/local or ~/.
# - compile all Python .py files to .pyc.
install:
    @if os.name == 'posix':
	PREFIX = `os.path.expanduser(_no.PREFIX)`
	@if not os.access(_no.PREFIX, os.W_OK):
	    @if os.access(_no.PREFIX, os.R_OK):
                :error Install directory is not writable: $PREFIX
            @r = raw_input(('\nThe $PREFIX directory does not exist: "%s"\n'
            @               % _no.PREFIX) +
            @           "Do you want to try creating it? (y/n) ")
            @if not r or (r[0] != 'y' and r[0] != 'Y'):
                :error Install directory does not exist: $PREFIX
            :mkdir {r} $PREFIX

	# Get the version string from AapVersion.py, because $VERSIONSTR is
	# from the current Aap, which may be older.
	:cat AapVersion.py | :eval re.search('version_string = "(\\d[^"]*)"',
				    stdin).group(1) | :assign Version

	# Directories to be used.
	dir = $PREFIX/lib/aap/Exec-$Version
	toolsdir = $dir/tools
	modulesdir = $dir/modules
	docdir = $dir/doc
	htmldocdir = $docdir$?HTMLDIR
	bindir = $PREFIX/bin
	mandir = $PREFIX/man/man1
	sharedocdir = $PREFIX/share/doc
	sharedocdiraap = $sharedocdir/aap
	sharehtmldocdir = $sharedocdiraap$?HTMLDIR

	# Copy the files.
	:mkdir {r}{f} $toolsdir $modulesdir
	:copy *.py aap $dir
	:copy tools/*.py $toolsdir
	:copy modules/*.aap $modulesdir
	:copy COPYING README.txt default.aap $dir

	# Copy the docs.  Adjust paths in aap.1 for the $PREFIX used.
	@if _no.FULLDOCS != 'no':
	    :mkdir {r}{f} $docdir $htmldocdir
	    :copy doc/exec.pdf $docdir
	    :copy doc/*.html $htmldocdir
	    # Create symbolic links for the docs dir.
	    @if os.path.exists(sharedocdir):
		:print Creating a symbolic link for "aap" in $sharedocdir
		:symlink {f} $docdir $sharedocdiraap
		indexstr = $sharehtmldocdir/index.html
		htmlstr = $sharehtmldocdir/*.html
		pdfstr = $sharedocdiraap/exec.pdf
	    @else:
		indexstr = $htmldocdir/index.html
		htmlstr = $htmldocdir/*.html
		pdfstr = $docdir/exec.pdf
	@else:
	    indexstr = "<not installed>"
	    htmlstr = "<not installed>"
	    pdfstr = "<not installed>"
        indexstr = `string.replace(indexstr, "\\", "\\\\")`
        htmlstr = `string.replace(htmlstr, "\\", "\\\\")`
        pdfstr = `string.replace(pdfstr, "\\", "\\\\")`

	# Modify the manual page to include the actually used paths.
	# Make a backup copy and restore it afterwards.
	:mkdir {r}{f} $mandir
	:copy {exist} aap.1 aap.1.orig
	:cat aap.1
	    | :eval re.sub('".*/index.html"', indexstr, stdin)
	    | :eval re.sub('".*.html"', htmlstr, stdin)
	    | :eval re.sub('".*/exec.pdf"', pdfstr, stdin)
	    >! aap.1
	:copy aap.1 $mandir
	:move {f} aap.1.orig aap.1
	
	# Compile *.py files into *.pyc.  This must be done after copying,
	# otherwise they won't be used.
        # Trick: Only compile aapre.py with Python 2.3, otherwise it generates
        # an error message. 
	@if not skipbuild() and not _no.SKIP_COMPILEALL:
	    @import compileall
            @if sys.version[0] != '2' or sys.version[2] != "3":
                :move $dir/aapre.py $dir/aapre.py.not
	    @compileall.compile_dir(dir, 1)
            @if sys.version[0] != '2' or sys.version[2] != "3":
                :move $dir/aapre.py.not $dir/aapre.py

	# Create symbolic links for the program.
	:print Creating a symbolic link for "aap" in $bindir
	:mkdir {f} $bindir
	:symlink {f} $dir/aap $bindir/aap

    @elif os.name in ["win32", "mswin", "nt"]:
	# On MS-Windows we write an aap.bat file in the Windows directory.
	# That is ugly but the only solution that works reliably everywhere.
	PREFIX = $?_arg.PREFIX
	@if not PREFIX:
	    PREFIX = `os.environ.get("WINDIR")`
	    @if not PREFIX:
		PREFIX = `os.environ.get("SystemRoot")`
	@if not PREFIX:
	    :print Do not know where to install Aap, please use a PREFIX argument.
	    :print Example: "aap install PREFIX=C:/bin".
	@else:
	    :progsearch pyloc python
	    @if pyloc:
		pyloc = python	    # "python" is in $PATH, don't add path
	    @else:
		pyloc = `sys.executable`
	    main = `string.replace(os.path.abspath("Main.py"), "\\", "\\\\")`
	    pyloc = `string.replace(pyloc, "\\", "\\\\")`
	    :cat aap.bat
		    | :eval re.sub("Main.py", '"' + main + '"', stdin)
		    | :eval re.sub("python", '"' + pyloc + '"', stdin)
		    >! $PREFIX/aap.bat
	    :print Installed $PREFIX/aap.bat.
	    # Compile *.py files into *.pyc.
	    @if not skipbuild():
		@import compileall
		@compileall.compile_dir(".", 1)
	    
    @else:
	:print On this system you will have to do this manually:
	:print 1. Add the directory "`os.getcwd()`" to your $($)PATH
	:print 2. Make sure the ".py" extension is associated with the Python program.

# Uninstall: reverse of install.
uninstall:
    @if os.name == 'posix':
	PREFIX = `os.path.expanduser(_no.PREFIX)`
	@if not os.access(_no.PREFIX, os.W_OK):
	    :error Install directory is not writable: $PREFIX

	# What version to uninstall?  Default is what we are currently running.
	VERSION ?= $VERSIONSTR

	dir = $PREFIX/lib/aap/Exec-$VERSION
	mandir = $PREFIX/man/man1

	# Only delete the bin/aap and share/doc symlinks if they point to the
	# version we uninstalled.
	@try:
	    n = $PREFIX/bin/aap
	    @if string.find(os.readlink(n), _no.VERSION) >= 0:
	        :del {f} $n
	@except:
	@   pass

	@try:
	    n = $PREFIX/share/doc/aap
	    @if string.find(os.readlink(n), _no.VERSION) >= 0:
	        :del {f} $n
	@except:
	@   pass

	# Give a message when the files for this version can't be found.
	# Don't bail out, may still want to uninstall the rest.
	@if not os.path.isdir(dir):
	    :print Aap directory not found: $dir
	@else:
	    :del {r}{f} $dir

	# We delete the manual page if there is no "aap" command to be found
	# now.  That works when you install and then uninstall the same
	# version.  When you install a new version and then uninstall an older
	# one the manual page won't be deleted.
	:progsearch Aap aap
	@if not Aap:
	    :del {f} $mandir/aap.1

    @elif os.name in ["win32", "mswin", "nt"]:
	# Delete the aap.bat file that was installed in the Windows directory.
	PREFIX = $?_arg.PREFIX
	@if not PREFIX:
	    PREFIX = `os.environ.get("WINDIR")`
	    @if not PREFIX:
		PREFIX = `os.environ.get("SystemRoot")`
	@if PREFIX:
	    aaploc = $PREFIX/aap.bat
	    @if not os.path.exists(aaploc):
		PREFIX =
	@if not PREFIX:
	    # Can't find it, try searching in $PATH.  Don't accept aap.bat in
	    # the current directory.
	    :progsearch aaploc aap.bat
	    @if aaploc == os.path.abspath("aap.bat"):
		aaploc =

	@if not (aaploc and os.path.exists(aaploc)):
	    :print Do not know where "aap.bat" is, please use a PREFIX argument.
	    :print Example: "aap uninstall PREFIX=C:/bin".
	@else:
	    :delete $aaploc
	    dir = `os.path.abspath(".")`
	    :print You can now delete the Aap directory "$dir".

    @else:
	:print On this system you will have to uninstall manually


# Reporting a problem.
report:
    tmpfile = `tempfname()`
    :print >$tmpfile  Aap version: $VERSIONSTR
    :print >>$tmpfile system type: `os.name`
    @if os.name == "posix":
	:print >>$tmpfile system details: `os.uname()`
    :print >>$tmpfile
    :print >>$tmpfile State your problem with Aap here
    :do email {subject = 'problem in Aap'}
		    {to = bugs@a-a-p.org}
		    {edit}
		    {remove}
		    $tmpfile

# Generate a tags file.  Let ctags figure out which files to scan.
tags: *.py
    :sys ctags -R .

# vim: sts=4 sw=4 :