Ravenports generated: 18 May 2018 15:31
[ravenports.git] / bucket_81 / autoselect-python
1 # Buildsheet autogenerated by ravenadm tool -- Do not edit.
2
3 NAMEBASE=               autoselect-python
4 VERSION=                1
5 KEYWORDS=               lang
6 VARIANTS=               standard
7 SDESC[standard]=        Dynamic links to the latest installed python
8 HOMEPAGE=               none
9 CONTACT=                nobody
10
11 DOWNLOAD_GROUPS=        none
12 SPKGS[standard]=        single
13
14 OPTIONS_AVAILABLE=      none
15 OPTIONS_STANDARD=       none
16
17 LICENSE=                ISCL:single
18 LICENSE_FILE=           ISCL:{{FILESDIR}}/LICENSE_ISC
19 LICENSE_SCHEME=         solo
20
21 SUB_FILES=              autoselect.c
22 SUB_LIST=               ALPHA=3.6
23                         BRAVO=3.5
24                         CHARLIE=2.7
25
26 post-patch:
27         @${MKDIR} ${WRKSRC}
28         ${CP} ${WRKDIR}/autoselect.c ${WRKSRC}
29
30 do-build:
31         (cd ${WRKSRC} && ${CC} ${CFLAGS} ${LDFLAGS} -o generic autoselect.c)
32
33 do-install:
34 .for prog in 2to3 idle pydoc python python-config
35         ${INSTALL_PROGRAM} ${WRKSRC}/generic  ${STAGEDIR}${PREFIX}/bin/${prog}
36 .endfor
37
38 [FILE:570:descriptions/desc.single]
39 This package provides:
40   bin/python
41   bin/python-config
42   bin/pydoc
43   bin/idle
44   bin/2to3
45
46 It automatically selects the latest version of python available.
47 For example, if python 2.7, 3.5, and 3.6 are all installed,
48 bin/python executes bin/python3.6 with the same arguments.  If
49 python 3.6 is then deinstalled, the linkage will automatically
50 adjust to python 3.5.  The python 2.7 binaries will only be
51 executed if no python 3.x packages are installed.
52
53 The priority check can be overridden by setting AUTOPYTHON=<python version>
54 in the environment, e.g. AUTOPYTHON=2.7.
55
56
57 [FILE:47:manifests/plist.single]
58 bin/
59  2to3
60  idle
61  pydoc
62  python
63  python-config
64
65
66 [FILE:742:files/LICENSE_ISC]
67 Copyright (c) 2018, The Ravenports Project.
68
69 Permission to use, copy, modify, and/or distribute this software for any
70 purpose with or without fee is hereby granted, provided that the above
71 copyright notice and this permission notice appear in all copies.
72
73 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
74 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
75 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
76 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
77 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
78 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
79 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
80
81
82 [FILE:2280:files/autoselect.c.in]
83 /*
84  * This program will determine the latest version of python
85  * installed by checking %%PREFIX%%/bin/python-<x> where <x> checks
86  * all possible versions.
87  * 
88  * If no version is present, an error message will be displayed,
89  * otherwise the versioned counterpart of the python command
90  * requested will be will be executed with the same arguments
91  * provided to this one.  If the versioned command isn't present, an
92  * error message will be provided as a fallback.
93  */
94
95 #include <stdio.h>
96 #include <stdlib.h>
97 #include <string.h>
98 #include <unistd.h>
99
100
101 int
102 main(int argc, char **argv)
103 {
104         int x;
105         char *cmd;
106         char *override;
107         char recommand[1024];
108         char *pyver    = NULL;
109         char *PYTHON_A = "%%PREFIX%%/bin/python%%ALPHA%%";
110         char *PYTHON_B = "%%PREFIX%%/bin/python%%BRAVO%%";
111         char *PYTHON_C = "%%PREFIX%%/bin/python%%CHARLIE%%";
112         char *ALPHA    = "%%ALPHA%%";
113         char *BRAVO    = "%%BRAVO%%";
114         char *CHARLIE  = "%%CHARLIE%%";
115
116         override = getenv("AUTOPYTHON");
117         if (override != NULL) {
118                 if (strcmp (override, ALPHA) == 0) {
119                         pyver = ALPHA;
120                 } else if (strcmp (override, BRAVO) == 0) {
121                         pyver = BRAVO;
122                 } else if (strcmp (override, CHARLIE) == 0) {
123                         pyver = CHARLIE;
124                 }
125         }
126         if (pyver == NULL) {
127                 if (access(PYTHON_A, F_OK) != -1) {
128                         pyver = ALPHA;
129                 } else if (access(PYTHON_B, F_OK) != -1) {
130                         pyver = BRAVO;
131                 } else if (access(PYTHON_C, F_OK) != -1) {
132                         pyver = CHARLIE;
133                 } else {
134                         /* no versions of python are installed */
135                         printf ("There are no versions of python installed at %%PREFIX%%/bin\n");
136                         exit (1);
137                 }
138         }
139
140         /*
141          * Get the last path element of the program name being executed
142          */
143         cmd = strrchr(argv[0], '/');
144         if (cmd != NULL)
145                 cmd++;
146         else
147                 cmd = argv[0];
148
149         if (strcmp (cmd, "python-config") == 0) {
150                 snprintf(recommand, 1024,
151                         "%%PREFIX%%/bin/python%s-config", pyver);
152         } else if (strcmp (cmd, "2to3") == 0) {
153                 snprintf(recommand, 1024,
154                         "%%PREFIX%%/bin/2to3-", pyver);
155         } else {
156                 snprintf(recommand, 1024,
157                         "%%PREFIX%%/bin/%s%s", cmd, pyver);
158         }
159         argv[0] = recommand;
160         execv(recommand, argv);
161
162         /*
163          * Execution failed, so write out an error message
164          */
165         printf ("Command execution failed: %s", recommand);
166         printf ("               arguments:");
167         for (x = 1; x < argc; x++)
168                 printf (" %s", argv[x]);
169         printf ("\n");
170         exit (1);
171 }
172