Mercurial > p > roundup > code
annotate roundup/dist/command/build_scripts.py @ 5548:fea11d05110e
Avoid errors from selecting "no selection" on multilink (issue2550722).
As discussed in issue 2550722 there are various cases where selecting
"no selection" on a multilink can result in inappropriate errors from
Roundup:
* If selecting "no selection" produces a null edit (a value was set in
the multilink in an edit with an error, then removed again, along
with all other changes, in the next form submission), so the page is
rendered from the form contents including the "-<id>" value for "no
selection" for the multilink.
* If creating an item with a nonempty value for a multilink has an
error, and the resubmission changes that multilink to "no selection"
(and this in turn has subcases, according to whether the creation
then succeeds or fails on the resubmission, which need fixes in
different places in the Roundup code).
All of these cases have in common that it is expected and OK to have a
"-<id>" value for a submission for a multilink when <id> is not set in
that multilink in the database (because the original attempt to set
<id> in that multilink had an error), so the hyperdb.py logic to give
an error in that case is thus removed. In the subcase of the second
case where the resubmission with "no selection" has an error, the
templating code tries to produce a menu entry for the "-<id>"
multilink value, which also results in an error, hence the
templating.py change to ignore such values in the list for a
multilink.
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Thu, 27 Sep 2018 11:33:01 +0000 |
| parents | 12baa5b9b597 |
| children |
| rev | line source |
|---|---|
| 4068 | 1 # |
| 2 # Copyright (C) 2009 Stefan Seefeld | |
| 3 # All rights reserved. | |
| 4 # For license terms see the file COPYING.txt. | |
| 5 # | |
| 6 from distutils.command.build_scripts import build_scripts as base | |
|
5023
5e2888db6c48
build_scripts: self.announce --> log.info because it is visible
anatoly techtonik <techtonik@gmail.com>
parents:
5022
diff
changeset
|
7 from distutils import log |
| 4068 | 8 import sys, os, string |
| 9 | |
| 10 class build_scripts(base): | |
| 11 """ Overload the build_scripts command and create the scripts | |
| 12 from scratch, depending on the target platform. | |
| 13 | |
| 14 You have to define the name of your package in an inherited | |
| 15 class (due to the delayed instantiation of command classes | |
| 16 in distutils, this cannot be passed to __init__). | |
| 17 | |
| 18 The scripts are created in an uniform scheme: they start the | |
| 19 run() function in the module | |
| 20 | |
| 21 <packagename>.scripts.<mangled_scriptname> | |
| 22 | |
| 23 The mangling of script names replaces '-' and '/' characters | |
| 24 with '-' and '.', so that they are valid module paths. | |
| 25 | |
| 26 If the target platform is win32, create .bat files instead of | |
| 27 *nix shell scripts. Target platform is set to "win32" if main | |
| 28 command is 'bdist_wininst' or if the command is 'bdist' and | |
| 29 it has the list of formats (from command line or config file) | |
| 30 and the first item on that list is wininst. Otherwise | |
| 31 target platform is set to current (build) platform. | |
| 32 """ | |
| 33 package_name = 'roundup' | |
| 34 | |
| 35 def initialize_options(self): | |
| 36 base.initialize_options(self) | |
| 37 self.script_preamble = None | |
| 38 self.target_platform = None | |
| 39 self.python_executable = None | |
| 40 | |
| 41 def finalize_options(self): | |
| 42 base.finalize_options(self) | |
| 43 cmdopt=self.distribution.command_options | |
| 44 | |
| 45 # find the target platform | |
| 46 if self.target_platform: | |
| 47 # TODO? allow explicit setting from command line | |
| 48 target = self.target_platform | |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5380
diff
changeset
|
49 if "bdist_wininst" in cmdopt: |
| 4068 | 50 target = "win32" |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5380
diff
changeset
|
51 elif "formats" in cmdopt.get("bdist", {}): |
| 4068 | 52 formats = cmdopt["bdist"]["formats"][1].split(",") |
| 53 if formats[0] == "wininst": | |
| 54 target = "win32" | |
| 55 else: | |
| 56 target = sys.platform | |
| 57 if len(formats) > 1: | |
| 58 self.warn( | |
| 59 "Scripts are built for %s only (requested formats: %s)" | |
| 60 % (target, ",".join(formats))) | |
| 61 else: | |
| 62 # default to current platform | |
| 63 target = sys.platform | |
|
5022
9250620c7219
build_scripts: Fix long term bug with setting self.target_platform
anatoly techtonik <techtonik@gmail.com>
parents:
4068
diff
changeset
|
64 self.target_platform = target |
| 4068 | 65 |
| 66 # for native builds, use current python executable path; | |
| 67 # for cross-platform builds, use default executable name | |
| 68 if self.python_executable: | |
| 69 # TODO? allow command-line option | |
| 70 pass | |
| 71 if target == sys.platform: | |
| 72 self.python_executable = os.path.normpath(sys.executable) | |
| 73 else: | |
| 74 self.python_executable = "python" | |
| 75 | |
| 76 # for windows builds, add ".bat" extension | |
| 77 if target == "win32": | |
| 78 # *nix-like scripts may be useful also on win32 (cygwin) | |
| 79 # to build both script versions, use: | |
| 80 #self.scripts = list(self.scripts) + [script + ".bat" | |
| 81 # for script in self.scripts] | |
| 82 self.scripts = [script + ".bat" for script in self.scripts] | |
| 83 | |
| 84 # tweak python path for installations outside main python library | |
|
5381
0942fe89e82e
Python 3 preparation: change "x.has_key(y)" to "y in x".
Joseph Myers <jsm@polyomino.org.uk>
parents:
5380
diff
changeset
|
85 if "prefix" in cmdopt.get("install", {}): |
| 4068 | 86 prefix = os.path.expanduser(cmdopt['install']['prefix'][1]) |
| 87 version = '%d.%d'%sys.version_info[:2] | |
| 88 self.script_preamble = """ | |
| 89 import sys | |
| 90 sys.path.insert(1, "%s/lib/python%s/site-packages") | |
| 91 """%(prefix, version) | |
| 92 else: | |
| 93 self.script_preamble = '' | |
| 94 | |
| 95 def copy_scripts(self): | |
| 96 """ Create each script listed in 'self.scripts' | |
| 97 """ | |
| 98 | |
|
5435
12baa5b9b597
Python 3 preparation: avoid string.translate() and string.maketrans().
Joseph Myers <jsm@polyomino.org.uk>
parents:
5381
diff
changeset
|
99 try: |
|
12baa5b9b597
Python 3 preparation: avoid string.translate() and string.maketrans().
Joseph Myers <jsm@polyomino.org.uk>
parents:
5381
diff
changeset
|
100 # Python 3. |
|
12baa5b9b597
Python 3 preparation: avoid string.translate() and string.maketrans().
Joseph Myers <jsm@polyomino.org.uk>
parents:
5381
diff
changeset
|
101 maketrans = str.maketrans |
|
12baa5b9b597
Python 3 preparation: avoid string.translate() and string.maketrans().
Joseph Myers <jsm@polyomino.org.uk>
parents:
5381
diff
changeset
|
102 except AttributeError: |
|
12baa5b9b597
Python 3 preparation: avoid string.translate() and string.maketrans().
Joseph Myers <jsm@polyomino.org.uk>
parents:
5381
diff
changeset
|
103 # Python 2. |
|
12baa5b9b597
Python 3 preparation: avoid string.translate() and string.maketrans().
Joseph Myers <jsm@polyomino.org.uk>
parents:
5381
diff
changeset
|
104 maketrans = string.maketrans |
|
12baa5b9b597
Python 3 preparation: avoid string.translate() and string.maketrans().
Joseph Myers <jsm@polyomino.org.uk>
parents:
5381
diff
changeset
|
105 to_module = maketrans('-/', '_.') |
| 4068 | 106 |
| 107 self.mkpath(self.build_dir) | |
| 108 for script in self.scripts: | |
| 109 outfile = os.path.join(self.build_dir, os.path.basename(script)) | |
| 110 | |
| 111 #if not self.force and not newer(script, outfile): | |
| 112 # self.announce("not copying %s (up-to-date)" % script) | |
| 113 # continue | |
| 114 | |
| 115 if self.dry_run: | |
|
5023
5e2888db6c48
build_scripts: self.announce --> log.info because it is visible
anatoly techtonik <techtonik@gmail.com>
parents:
5022
diff
changeset
|
116 log.info("would create %s" % outfile) |
| 4068 | 117 continue |
| 118 | |
| 119 module = os.path.splitext(os.path.basename(script))[0] | |
|
5435
12baa5b9b597
Python 3 preparation: avoid string.translate() and string.maketrans().
Joseph Myers <jsm@polyomino.org.uk>
parents:
5381
diff
changeset
|
120 module = module.translate(to_module) |
| 4068 | 121 script_vars = { |
| 122 'python': self.python_executable, | |
| 123 'package': self.package_name, | |
| 124 'module': module, | |
| 125 'prefix': self.script_preamble, | |
| 126 } | |
| 127 | |
|
5023
5e2888db6c48
build_scripts: self.announce --> log.info because it is visible
anatoly techtonik <techtonik@gmail.com>
parents:
5022
diff
changeset
|
128 log.info("writing %s" % outfile) |
| 4068 | 129 file = open(outfile, 'w') |
| 130 | |
| 131 try: | |
| 132 # could just check self.target_platform, | |
| 133 # but looking at the script extension | |
| 134 # makes it possible to build both *nix-like | |
| 135 # and windows-like scripts on win32. | |
| 136 # may be useful for cygwin. | |
| 137 if os.path.splitext(outfile)[1] == ".bat": | |
| 138 file.write('@echo off\n' | |
| 139 'if NOT "%%_4ver%%" == "" "%(python)s" -c "from %(package)s.scripts.%(module)s import run; run()" %%$\n' | |
| 140 'if "%%_4ver%%" == "" "%(python)s" -c "from %(package)s.scripts.%(module)s import run; run()" %%*\n' | |
| 141 % script_vars) | |
| 142 else: | |
| 143 file.write('#! %(python)s\n%(prefix)s' | |
| 144 'from %(package)s.scripts.%(module)s import run\n' | |
| 145 'run()\n' | |
| 146 % script_vars) | |
| 147 finally: | |
| 148 file.close() | |
|
5380
64c4e43fbb84
Python 3 preparation: numeric literal syntax.
Joseph Myers <jsm@polyomino.org.uk>
parents:
5023
diff
changeset
|
149 os.chmod(outfile, 0o755) |
