Skip to content

Commit db9c03f

Browse files
author
Matthias Koeppe
committed
build/bin/sage-spkg, build/sage_bootstrap/uninstall.py: Prefix spkg-... script messages by '[spkg-...] ' instead of announcing 'Running spkg-... script'
1 parent 03a858a commit db9c03f

File tree

2 files changed

+52
-49
lines changed

2 files changed

+52
-49
lines changed

build/bin/sage-spkg

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ fi
480480
extract_the_package() { ##########################################
481481

482482
cd "$SAGE_BUILD_DIR" || exit $?
483-
echo "Setting up build directory for $PKG_NAME"
483+
echo "Setting up build directory $SAGE_BUILD_DIR/$PKG_NAME"
484484
if [ -z "$PKG_NAME_UPSTREAM" ]; then
485485
# Not a normal or wheel package.
486486
# Transplant the 'src' symlink, copy scripts.
@@ -672,16 +672,15 @@ fi
672672

673673
# First uninstall the previous version of this package, if any
674674
if [ "$KEEP_EXISTING" != "yes" ]; then
675-
sage-spkg-uninstall "$PKG_BASE" "$SAGE_INST_LOCAL"
675+
sage-spkg-uninstall "$PKG_BASE" "$SAGE_INST_LOCAL" --log-directory .
676676
fi
677677

678678
# To work around #26996: Create lib and set a symlink so that writes into lib64/ end up in lib/
679679
(mkdir -p "$SAGE_DESTDIR_LOCAL/lib" && cd "$SAGE_DESTDIR_LOCAL" && ln -sf lib lib64)
680680

681681
# Run the pre-install script, if any
682682
if [ -f spkg-preinst ]; then
683-
echo "Running pre-install script for $PKG_NAME."
684-
time $SAGE_SUDO ./spkg-preinst
683+
sage-logger -p "$SAGE_SUDO ./spkg-preinst" spkg-preinst.log
685684
if [ $? -ne 0 ]; then
686685
error_msg "Error running the preinst script for $PKG_NAME."
687686
exit 1
@@ -690,19 +689,19 @@ fi
690689

691690
if [ -f spkg-build ]; then
692691
# Package has both spkg-build and spkg-install; execute the latter with SAGE_SUDO
693-
time ./spkg-build
692+
sage-logger -p "./spkg-build" spkg-build.log
694693
if [ $? -ne 0 ]; then
695694
error_msg "Error building package $PKG_NAME" "make"
696695
exit 1
697696
fi
698-
time $SAGE_SUDO ./spkg-install
697+
sage-logger -p "$SAGE_SUDO ./spkg-install" spkg-install.log
699698
if [ $? -ne 0 ]; then
700699
error_msg "Error installing package $PKG_NAME" "make"
701700
exit 1
702701
fi
703702
else
704703
# Package only has spkg-install
705-
time ./spkg-install
704+
sage-logger -p "./spkg-install" spkg-install.log
706705
if [ $? -ne 0 ]; then
707706
error_msg "Error installing package $PKG_NAME" "make"
708707
exit 1
@@ -788,16 +787,14 @@ post_install() { #################################################
788787
# Run the post-install script, if any
789788
# But first complete the delayed installation of wheels.
790789
if [ -f spkg-pipinst ]; then
791-
echo "Running pip-install script for $PKG_NAME."
792-
$SAGE_SUDO ./spkg-pipinst
790+
sage-logger -p "$SAGE_SUDO ./spkg-pipinst" spkg-pipinst.log
793791
if [ $? -ne 0 ]; then
794792
error_msg "Error running the pipinst script for $PKG_NAME."
795793
exit 1
796794
fi
797795
fi
798796
if [ -f spkg-postinst ]; then
799-
echo "Running post-install script for $PKG_NAME."
800-
time $SAGE_SUDO ./spkg-postinst
797+
sage-logger -p "$SAGE_SUDO ./spkg-postinst" spkg-postinst.log
801798
if [ $? -ne 0 ]; then
802799
error_msg "Error running the postinst script for $PKG_NAME."
803800
exit 1
@@ -817,7 +814,7 @@ run_test_suite() { ###############################################
817814
if [ -f "$INSTALLED_SCRIPTS_DEST"/spkg-check ]; then
818815
echo "Running the test suite for $PKG_NAME..."
819816
export PKG_BASE
820-
time "$INSTALLED_SCRIPTS_DEST"/spkg-check
817+
sage-logger -p "$INSTALLED_SCRIPTS_DEST"/spkg-check spkg-check.log
821818
if [ $? -ne 0 ]; then
822819
TEST_SUITE_RESULT="failed"
823820
if [ "$SAGE_CHECK" = "warn" ]; then
@@ -873,8 +870,7 @@ __EOF__
873870
} ###################################### write_installation_record
874871

875872
delete_the_temporary_build_directory() { #########################
876-
echo "Deleting temporary build directory"
877-
echo "$SAGE_BUILD_DIR/$PKG_NAME"
873+
echo "Deleting temporary build directory $SAGE_BUILD_DIR/$PKG_NAME"
878874
# On Solaris, the current working directory cannot be deleted,
879875
# so we "cd" out of $SAGE_BUILD_DIR/$PKG_NAME. See #12637.
880876
cd "$SAGE_BUILD_DIR"
@@ -885,8 +881,7 @@ delete_the_temporary_build_directory_if_required() { #############
885881
if [ ! -e "$SAGE_BUILD_DIR/$PKG_NAME/.keep" ]; then
886882
delete_the_temporary_build_directory
887883
else
888-
echo "You can safely delete the temporary build directory"
889-
echo "$SAGE_BUILD_DIR/$PKG_NAME"
884+
echo "You can safely delete the temporary build directory $SAGE_BUILD_DIR/$PKG_NAME"
890885
fi
891886
} ############### delete_the_temporary_build_directory_if_required
892887

build/sage_bootstrap/uninstall.py

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
"""Directory where all spkg sources are found."""
5050

5151

52-
def uninstall(spkg_name, sage_local, keep_files=False, verbose=False):
52+
def uninstall(spkg_name, sage_local, keep_files=False,
53+
verbose=False, log_directory=None):
5354
"""
5455
Given a package name and path to an installation tree (SAGE_LOCAL or SAGE_VENV),
5556
uninstall that package from that tree if it is currently installed.
@@ -85,51 +86,44 @@ def uninstall(spkg_name, sage_local, keep_files=False, verbose=False):
8586

8687
if 'files' not in spkg_meta:
8788
if stamp_file:
88-
print("Old-style or corrupt stamp file '{0}'"
89+
print("Old-style or corrupt stamp file {0}"
8990
.format(stamp_file), file=sys.stderr)
9091
else:
9192
print("Package '{0}' is currently not installed"
9293
.format(spkg_name), file=sys.stderr)
9394

9495
# Run legacy uninstaller even if there is no stamp file: the
9596
# package may be partially installed without a stamp file
96-
legacy_uninstall(spkg_name, verbose=verbose)
97+
legacy_uninstall(spkg_name,
98+
verbose=verbose, log_directory=log_directory)
9799
else:
98100
files = spkg_meta['files']
99101
if not files:
100102
print("Warning: No files to uninstall for "
101103
"'{0}'".format(spkg_name), file=sys.stderr)
102104

103-
modern_uninstall(spkg_name, sage_local, files, verbose=verbose)
105+
modern_uninstall(spkg_name, sage_local, files,
106+
verbose=verbose, log_directory=log_directory)
104107

105108
remove_stamp_files(stamp_files, verbose=verbose)
106109

107110

108-
def legacy_uninstall(spkg_name, verbose=False):
111+
def legacy_uninstall(spkg_name,
112+
verbose=False, log_directory=None):
109113
"""
110114
Run the spkg's legacy uninstall script, if one exists; otherwise do
111115
nothing.
112116
"""
113-
114117
spkg_dir = pth.join(PKGS, spkg_name)
115-
legacy_uninstall = pth.join(spkg_dir, 'spkg-legacy-uninstall')
116-
117-
if not pth.isfile(legacy_uninstall):
118-
print("No legacy uninstaller found for '{0}'; nothing to "
119-
"do".format(spkg_name), file=sys.stderr)
120-
return
121-
122-
print("Uninstalling '{0}' with legacy uninstaller".format(spkg_name))
123-
if verbose:
124-
with open(legacy_uninstall) as f:
125-
print(f.read())
126118

127119
# Any errors from this, including a non-zero return code will
128120
# bubble up and exit the uninstaller
129-
subprocess.check_call([legacy_uninstall])
121+
run_spkg_script(spkg_name, spkg_dir, 'legacy-uninstall',
122+
if_does_not_exist='log', log_directory=log_directory)
130123

131124

132-
def modern_uninstall(spkg_name, sage_local, files, verbose=False):
125+
def modern_uninstall(spkg_name, sage_local, files,
126+
verbose=False, log_directory=None):
133127
"""
134128
Remove all listed files from the given installation tree (SAGE_LOCAL or SAGE_VENV).
135129
@@ -150,15 +144,17 @@ def modern_uninstall(spkg_name, sage_local, files, verbose=False):
150144
# so that we can easily remove a directory once it's been emptied
151145
files.sort(key=lambda f: (-f.count(os.sep), f))
152146

153-
print("Uninstalling existing '{0}'".format(spkg_name))
147+
if verbose:
148+
print("Uninstalling existing '{0}'".format(spkg_name))
154149

155150
# Run the package's prerm script, if it exists.
156151
# If an error occurs here we abort the uninstallation for now.
157152
# This means a prerm script actually has the ability to abort an
158153
# uninstallation, for example, if some manual intervention is needed
159154
# to proceed.
160155
try:
161-
run_spkg_script(spkg_name, spkg_scripts, 'prerm', 'pre-uninstall')
156+
run_spkg_script(spkg_name, spkg_scripts, 'prerm',
157+
log_directory=log_directory)
162158
except Exception as exc:
163159
script_path = pth.join(spkg_scripts, 'spkg-prerm')
164160
print("Error: The pre-uninstall script for '{0}' failed; the "
@@ -177,7 +173,7 @@ def modern_uninstall(spkg_name, sage_local, files, verbose=False):
177173
# manifest, so this step has to happen before removing the files.
178174
try:
179175
run_spkg_script(spkg_name, spkg_scripts, 'piprm',
180-
'pip-uninstall')
176+
log_directory=log_directory)
181177
except Exception:
182178
print("Warning: Error running the pip-uninstall script for "
183179
"'{0}'; uninstallation may have left behind some files".format(
@@ -190,7 +186,7 @@ def rmdir(dirname):
190186
print('rmdir "{}"'.format(dirname))
191187
os.rmdir(dirname)
192188
else:
193-
print("Warning: Directory '{0}' not found".format(
189+
print("Warning: Directory {0} not found".format(
194190
dirname), file=sys.stderr)
195191

196192
# Remove the files; if a directory is empty after removing a file
@@ -205,7 +201,7 @@ def rmdir(dirname):
205201
print('rm "{}"'.format(filename))
206202
os.remove(filename)
207203
else:
208-
print("Warning: File '{0}' not found".format(filename),
204+
print("Warning: File {0} not found".format(filename),
209205
file=sys.stderr)
210206

211207
# Remove file's directory if it is now empty
@@ -218,7 +214,7 @@ def rmdir(dirname):
218214
# files removed.
219215
try:
220216
run_spkg_script(spkg_name, spkg_scripts, 'postrm',
221-
'post-uninstall')
217+
log_directory=log_directory)
222218
except Exception:
223219
print("Warning: Error running the post-uninstall script for "
224220
"'{0}'; the package will still be uninstalled, but "
@@ -234,20 +230,30 @@ def rmdir(dirname):
234230
def remove_stamp_files(stamp_files, verbose=False):
235231
# Finally, if all went well, delete all the stamp files.
236232
for stamp_file in stamp_files:
237-
print("Removing stamp file '{0}'".format(stamp_file))
233+
print("Removing stamp file {0}".format(stamp_file))
238234
os.remove(stamp_file)
239235

240236

241-
def run_spkg_script(spkg_name, path, script_name, script_descr):
237+
def run_spkg_script(spkg_name, path, script_name,
238+
if_does_not_exist='ignore', log_directory=None):
242239
"""
243240
Runs the specified ``spkg-<foo>`` script under the given ``path``,
244241
if it exists.
245242
"""
246-
247-
script = pth.join(path, 'spkg-{0}'.format(script_name))
243+
script_name = 'spkg-{0}'.format(script_name)
244+
script = pth.join(path, script_name)
248245
if pth.exists(script):
249-
print("Running {0} script for '{1}'".format(script_descr, spkg_name))
250-
subprocess.check_call([script])
246+
if log_directory:
247+
log_file = pth.join(log_directory, script + '.log')
248+
subprocess.check_call(['sage-logger', '-p', script, log_file])
249+
else:
250+
subprocess.check_call([script])
251+
elif if_does_not_exist == 'ignore':
252+
pass
253+
elif if_does_not_exist == 'log':
254+
print('No {0} script; nothing to do'.format(script_name), file=sys.stderr)
255+
else:
256+
raise ValueError('unknown if_does_not_exist value: {0}'.format(if_does_not_exist))
251257

252258

253259
def dir_type(path):
@@ -257,7 +263,7 @@ def dir_type(path):
257263

258264
if path and not pth.isdir(path):
259265
raise argparse.ArgumentTypeError(
260-
"'{0}' is not a directory".format(path))
266+
"{0} is not a directory".format(path))
261267

262268
return path
263269

@@ -284,6 +290,8 @@ def make_parser():
284290
"but do not remove files installed by the "
285291
"package")
286292
parser.add_argument('--debug', action='store_true', help=argparse.SUPPRESS)
293+
parser.add_argument('--log-directory', type=str,
294+
help="directory where to create log files (default: none)")
287295

288296
return parser
289297

@@ -301,7 +309,7 @@ def run(argv=None):
301309

302310
try:
303311
uninstall(args.spkg, args.sage_local, keep_files=args.keep_files,
304-
verbose=args.verbose)
312+
verbose=args.verbose, log_directory=args.log_directory)
305313
except Exception as exc:
306314
print("Error during uninstallation of '{0}': {1}".format(
307315
args.spkg, exc), file=sys.stderr)

0 commit comments

Comments
 (0)