ยปCore Development>Code coverage>Mac/Modules/launch/launchsupport.py

Python code coverage for Mac/Modules/launch/launchsupport.py

#countcontent
1n/a# This script generates a Python interface for an Apple Macintosh Manager.
2n/a# It uses the "bgen" package to generate C code.
3n/a# The function specifications are generated by scanning the mamager's header file,
4n/a# using the "scantools" package (customized for this particular manager).
5n/a
6n/aimport string
7n/a
8n/a# Declarations that change for each manager
9n/aMODNAME = '_Launch' # The name of the module
10n/aOBJECTNAME = 'UNUSED' # The basic name of the objects used here
11n/aKIND = 'Record' # Usually 'Ptr' or 'Handle'
12n/a
13n/a# The following is *usually* unchanged but may still require tuning
14n/aMODPREFIX = 'Launch' # The prefix for module-wide routines
15n/aOBJECTTYPE = OBJECTNAME + KIND # The C type used to represent them
16n/aOBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
17n/aINPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
18n/aOUTPUTFILE = MODNAME + "module.c" # The file generated by this program
19n/a
20n/afrom macsupport import *
21n/a
22n/a# Create the type objects
23n/aLSAcceptanceFlags = Type("LSAcceptanceFlags", "l")
24n/aLSInitializeFlags = Type("LSInitializeFlags", "l")
25n/aLSRequestedInfo = Type("LSRequestedInfo", "l")
26n/aLSRolesMask = Type("LSRolesMask", "l")
27n/aUniCharCount = Type("UniCharCount", "l")
28n/aOptCFStringRef = OpaqueByValueType("CFStringRef", "OptCFStringRefObj")
29n/aLSItemInfoRecord = OpaqueType("LSItemInfoRecord", "LSItemInfoRecord")
30n/a
31n/aincludestuff = includestuff + """
32n/a#if PY_VERSION_HEX < 0x02040000
33n/aPyObject *PyMac_GetOSErrException(void);
34n/a#endif
35n/a
36n/a#include <ApplicationServices/ApplicationServices.h>
37n/a
38n/a/*
39n/a** Optional CFStringRef. None will pass NULL
40n/a*/
41n/astatic int
42n/aOptCFStringRefObj_Convert(PyObject *v, CFStringRef *spec)
43n/a{
44n/a if (v == Py_None) {
45n/a *spec = NULL;
46n/a return 1;
47n/a }
48n/a return CFStringRefObj_Convert(v, spec);
49n/a}
50n/a
51n/aPyObject *
52n/aOptCFStringRefObj_New(CFStringRef it)
53n/a{
54n/a if (it == NULL) {
55n/a Py_INCREF(Py_None);
56n/a return Py_None;
57n/a }
58n/a return CFStringRefObj_New(it);
59n/a}
60n/a
61n/a/*
62n/a** Convert LSItemInfoRecord to Python.
63n/a*/
64n/aPyObject *
65n/aLSItemInfoRecord_New(LSItemInfoRecord *it)
66n/a{
67n/a return Py_BuildValue("{s:is:O&s:O&s:O&s:O&s:i}",
68n/a "flags", it->flags,
69n/a "filetype", PyMac_BuildOSType, it->filetype,
70n/a "creator", PyMac_BuildOSType, it->creator,
71n/a "extension", OptCFStringRefObj_New, it->extension,
72n/a "iconFileName", OptCFStringRefObj_New, it->iconFileName,
73n/a "kindID", it->kindID);
74n/a}
75n/a"""
76n/a
77n/a# From here on it's basically all boiler plate...
78n/aexecfile(string.lower(MODPREFIX) + 'typetest.py')
79n/a
80n/a# Create the generator groups and link them
81n/amodule = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
82n/a##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
83n/a##module.addobject(object)
84n/a
85n/a# Create the generator classes used to populate the lists
86n/aFunction = OSErrFunctionGenerator
87n/a##Method = OSErrMethodGenerator
88n/a
89n/a# Create and populate the lists
90n/afunctions = []
91n/a##methods = []
92n/aexecfile(INPUTFILE)
93n/a
94n/a# add the populated lists to the generator groups
95n/a# (in a different wordl the scan program would generate this)
96n/afor f in functions: module.add(f)
97n/a##for f in methods: object.add(f)
98n/a
99n/a# generate output (open the output file as late as possible)
100n/aSetOutputFileName(OUTPUTFILE)
101n/amodule.generate()