And after discussion with Danek on #pkg5, the test webrev is updated in place, and I have attached a patch that is (at least as of this moment) ready for import.
--Mark On Wed, Jan 20, 2010 at 01:32:39PM -0700, Mark J. Nelson wrote: > Addendum: I felt that I should extend the tests for these. > > http://cr.opensolaris.org/~mjnelson/webrev.pkgmog.tests/ > > (the script and manpage changes have already been reviewed, the new > tests and baseline have not.) > > --Mark > > On Tue, Jan 19, 2010 at 10:14:54AM -0800, Bart Smaalders wrote: > > On 01/15/10 17:31, Mark J. Nelson wrote: > > >This is for the work discussed here: > > > > > >http://mail.opensolaris.org/pipermail/pkg-discuss/2010-January/019874.html > > > > > >The webrev: http://cr.opensolaris.org/~mjnelson/webrev.pkgmog.ops/ > > > > > >After I send this note, I'll send the on_ips code review request for > > >our use of the new functionality, and will cc pkg-discuss. > > > > > >--Mark > > >_______________________________________________ > > >pkg-discuss mailing list > > >[email protected] > > >http://mail.opensolaris.org/mailman/listinfo/pkg-discuss > > > > A couple of nits: > > > > This code creates the printfile empty even if there's no > > print action. Is this desirable/intentional? > > > > Original proposal suggested that print and output would be > > intermixed... this is not the case in this code. > > > > If the above is what you want, this is fine. > > > > - Bart > > > > > > > > -- > > Bart Smaalders Solaris Kernel Performance > > [email protected] http://blogs.sun.com/barts > > "You will contribute more with mercurial than with thunderbird." > _______________________________________________ > pkg-discuss mailing list > [email protected] > http://mail.opensolaris.org/mailman/listinfo/pkg-discuss
# HG changeset patch # User Mark J. Nelson <[email protected]> # Date 1264052599 25200 # Node ID 9d02bb1c9298eb34ed890488f48c31db247b3a03 # Parent faf48475446532fd7a4e72c99f23c78da66d6541 13792 on_ips needs abort and print operations for pkgmogrify's transform directive diff --git a/src/man/pkgmogrify.1.txt b/src/man/pkgmogrify.1.txt --- a/src/man/pkgmogrify.1.txt +++ b/src/man/pkgmogrify.1.txt @@ -6,7 +6,7 @@ SYNOPSIS /usr/bin/pkgmogrify [-v] [-I includedir ...] [-D macro=value ...] - [ -O outputfile] [inputfile ...] + [-O outputfile] [-P printfile] [inputfile ...] DESCRIPTION pkgmogrify provides for the automated editing of package manifests @@ -58,8 +58,17 @@ directives. -O outputfile - Write output to the specified file. The file is not written - if an error occurs. + Write manifest output to the specified file. The file is not + written if an error occurs or if a transform directive + causes an abort operation. By default, manifest output is + written to stdout. + + -P printfile + Write output resulting from transform directive print + operations to the specified file. The file is not written + if an error occurs or if a transform directive causes an + abort operation. By default, print output is written to + stdout. -v Write out comments into output manifest showing effect of transforms to aid debugging. @@ -107,6 +116,8 @@ Operation synatx is of the form: + abort # immediately exit with status 0 + # and no manifest or print output drop # discard this action edit attribute regexp replace # apply regexp to value of attribute; # if match occurs, substitute replace for @@ -114,7 +125,10 @@ delete attribute regexp # remove attribute values matching regexp set attribute value # set specified attribute to value add attribute value # add value to attribute - default attribute value # if attribute is missing, add w/ specified value + default attribute value # if attribute is missing, add with + # specified value + print message # send message to output file + # specified via -P The order of processing is as follows: diff --git a/src/tests/baseline.txt b/src/tests/baseline.txt --- a/src/tests/baseline.txt +++ b/src/tests/baseline.txt @@ -597,6 +597,8 @@ cli.t_pkgmogrify.py TestPkgMogrify.test_5|pass cli.t_pkgmogrify.py TestPkgMogrify.test_6|pass cli.t_pkgmogrify.py TestPkgMogrify.test_7|pass +cli.t_pkgmogrify.py TestPkgMogrify.test_8|pass +cli.t_pkgmogrify.py TestPkgMogrify.test_9|pass cli.t_pkgrecv.py TestPkgrecvMulti.test_0_opts|pass cli.t_pkgrecv.py TestPkgrecvMulti.test_1_recv_pkgsend|pass cli.t_pkgrecv.py TestPkgrecvMulti.test_2_recv_compare|pass diff --git a/src/tests/cli/t_pkgmogrify.py b/src/tests/cli/t_pkgmogrify.py --- a/src/tests/cli/t_pkgmogrify.py +++ b/src/tests/cli/t_pkgmogrify.py @@ -20,7 +20,7 @@ # CDDL HEADER END # -# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Copyright 2010 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. import testutils @@ -49,8 +49,8 @@ depend [email protected]$(BUILDID) type=require $(i386_ONLY)depend [email protected]$(BUILDID) type=require file NOHASH elfarch=i386 elfbits=32 group=bin mode=0755 \ - owner=root path=usr/X11/bin/xkbprint -file NOHASH group=bin mode=0755 owner=root path=usr/X11/bin/Xserver + owner=root path=usr/X11/bin/xkbprint +file NOHASH group=bin mode=0755 owner=root path=usr/X11/bin/Xserver file group=bin mode=0755 owner=root path=usr/X11/bin/bdftopcf link path=usr/X11/lib/libXdmcp.so target=./libXdmcp.so.6 link path=usr/X11/lib/libXevie.so target=./libXevie.so.1 @@ -61,18 +61,20 @@ link path=usr/X11/lib/libXmu.so target=./libXmu.so.4 """ transforms = [ \ -""" """, -"""<transform file link dir -> edit path X11 Y11>""", -"""<transform file path='.*xkbprint.*' -> drop>""", -"""<transform file path='usr/X11/bin/.*' -> set mode 0555>""", -"""<transform file -> delete mode 0755> """, -"""<transform file >""", +""" """, +"""<transform file link dir -> edit path X11 Y11>""", +"""<transform file path='.*xkbprint.*' -> drop>""", +"""<transform file path='usr/X11/bin/.*' -> set mode 0555>""", +"""<transform file -> delete mode 0755> """, +"""<transform file >""", """<transform file -> edit bar >""", """<include transform_1> <include transform_3>""", """<include transform_9>""", """<include transform_5>""", -"""<transform file -> add bobcat 1>""" +"""<transform file -> add bobcat 1>""", +"""<transform file bobcat=1 -> print "ouch" >""", +"""<transform file bobcat=1 -> abort >""" ] transform_files = [] @@ -96,12 +98,13 @@ f.close() for i, s in enumerate(self.transforms): - fname = os.path.join(self.__test_dir, "transform_%s" % i) + fname = os.path.join(self.__test_dir, + "transform_%s" % i) self.transform_files.append(fname) f = file(fname, "wb") f.write(s) f.close() - + def pkgmogrify(self, args, exit=0): cmd="%s/usr/bin/pkgmogrify %s" % (testutils.g_proto_area, args) self.cmdline_run(cmd, exit=exit) @@ -109,72 +112,128 @@ def tearDown(self): #shutil.rmtree(self.__test_dir) pass - + def test_1(self): """demonstrate macros working""" source_file = os.path.join(self.__test_dir, "source_file") output_file = os.path.join(self.__test_dir, "output_file") - - self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 %s | egrep -v SUNWxorg-mesa" % source_file) - self.pkgmogrify("-Di386_ONLY=' ' -DBUILDID=0.126 %s | egrep [email protected]" % source_file) + + self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 %s |" \ + "egrep -v SUNWxorg-mesa" % source_file) + self.pkgmogrify("-Di386_ONLY=' ' -DBUILDID=0.126 %s |" \ + "egrep [email protected]" % source_file) # nested macros - self.pkgmogrify("-Di386_ONLY=' ' -DBUILDID='$(FOO)' -DFOO=0.126 %s | egrep [email protected]" % source_file) + self.pkgmogrify("-Di386_ONLY=' ' -DBUILDID='$(FOO)' " \ + "-DFOO=0.126 %s | egrep [email protected]" % + source_file) def test_2(self): """display output to files """ source_file = os.path.join(self.__test_dir, "source_file") output_file = os.path.join(self.__test_dir, "output_file") - self.pkgmogrify("-Di386_ONLY=' ' -DBUILDID=0.126 -O %s %s ; egrep [email protected] %s" % ( - output_file, source_file, output_file)) - + self.pkgmogrify("-Di386_ONLY=' ' -DBUILDID=0.126 -O %s %s ;" \ + "egrep [email protected] %s" % + (output_file, source_file, output_file)) + def test_3(self): source_file = os.path.join(self.__test_dir, "source_file") output_file = os.path.join(self.__test_dir, "output_file") - - self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 %s %s | egrep -v X11" % (self.transform_files[1], source_file)) - self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 %s %s | egrep Y11" % (self.transform_files[1], source_file)) - self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 %s %s | egrep bobcat | wc | egrep '3'" % (self.transform_files[10], source_file)) - self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 %s %s | egrep -v mode=0755" % (self.transform_files[4], source_file)) - + self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 %s %s |" \ + "egrep -v X11" % + (self.transform_files[1], source_file)) + self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 %s %s |" \ + "egrep Y11" % (self.transform_files[1], source_file)) + self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 %s %s |" \ + "egrep bobcat | wc -l | grep -w '3'" % + (self.transform_files[10], source_file)) + self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 %s %s |" \ + "egrep -v mode=0755" % + (self.transform_files[4], source_file)) + def test_4(self): source_file = os.path.join(self.__test_dir, "source_file") output_file = os.path.join(self.__test_dir, "output_file") - self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 %s %s | egrep -v xkbprint" % (self.transform_files[2], source_file)) - + self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 %s %s |" \ + "egrep -v xkbprint" % + (self.transform_files[2], source_file)) + def test_5(self): source_file = os.path.join(self.__test_dir, "source_file") output_file = os.path.join(self.__test_dir, "output_file") - self.pkgmogrify(("-Di386_ONLY='#' -DBUILDID=0.126 %s %s |" + - "egrep 'file NOHASH group=bin mode=0555 owner=root path=usr\/X11\/bin\/Xserver'") % (self.transform_files[3], - source_file)) - self.pkgmogrify(("-Di386_ONLY='#' -DBUILDID=0.126 %s %s %s|" + - "egrep 'file NOHASH group=bin mode=0755 owner=root path=usr\/Y11\/bin\/Xserver'") % \ - (self.transform_files[1], self.transform_files[3], source_file)) - self.pkgmogrify(("-Di386_ONLY='#' -DBUILDID=0.126 -I %s %s %s |" + - "egrep 'file NOHASH group=bin mode=0755 owner=root path=usr\/Y11\/bin\/Xserver'") % \ - (self.__test_dir, self.transform_files[7], source_file)) - # check multiple modes to the same attribute on same action - self.pkgmogrify(("-Di386_ONLY='#' -DBUILDID=0.126 %s %s %s |" + - "egrep 'file NOHASH group=bin mode=0555 owner=root path=usr\/Y11\/bin\/Xserver'") % \ - (self.transform_files[3], self.transform_files[1], source_file)) - + self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 %s %s |" \ + "egrep 'file NOHASH group=bin mode=0555 owner=root " \ + "path=usr\/X11\/bin\/Xserver'" % + (self.transform_files[3], source_file)) + self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 %s %s %s|" \ + "egrep 'file NOHASH group=bin mode=0755 owner=root " \ + "path=usr\/Y11\/bin\/Xserver'" % (self.transform_files[1], + self.transform_files[3], source_file)) + self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 -I %s %s %s" \ + " |egrep 'file NOHASH group=bin mode=0755 owner=root " \ + "path=usr\/Y11\/bin\/Xserver'" % (self.__test_dir, + self.transform_files[7], source_file)) + # check multiple modes to the same attribute on same action + self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 %s %s %s |" \ + "egrep 'file NOHASH group=bin mode=0555 owner=root " \ + "path=usr\/Y11\/bin\/Xserver'" % (self.transform_files[3], + self.transform_files[1], source_file)) + def test_6(self): source_file = os.path.join(self.__test_dir, "source_file") output_file = os.path.join(self.__test_dir, "output_file") - # check omitted NOHASH - self.pkgmogrify(("-Di386_ONLY='#' -DBUILDID=0.126 %s %s %s |" + - "egrep 'file NOHASH group=bin mode=0555 owner=root path=usr\/Y11\/bin\/bdftopcf") % \ - (self.transform_files[3], self.transform_files[1], source_file)) + # check omitted NOHASH + self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 %s %s %s |" \ + "egrep 'file NOHASH group=bin mode=0555 owner=root " \ + "path=usr\/Y11\/bin\/bdftopcf" % (self.transform_files[3], + self.transform_files[1], source_file)) - def test_7(self): source_file = os.path.join(self.__test_dir, "source_file") output_file = os.path.join(self.__test_dir, "output_file") - + # check error handling - self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 --froob", exit=2) - self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 %s" % self.transform_files[8], exit=1) # file not found - self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 -I %s %s" % (self.__test_dir, self.transform_files[8]), exit=1) # nested tranform error - self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 %s %s" % (self.transform_files[6], source_file), exit=1) # bad transform + self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 --froob", + exit=2) + # file not found + self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 %s" % + self.transform_files[8], exit=1) + # nested tranform error + self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 -I %s %s" % + (self.__test_dir, self.transform_files[8]), exit=1) + # bad transform + self.pkgmogrify("-Di386_ONLY='#' -DBUILDID=0.126 %s %s" % + (self.transform_files[6], source_file), exit=1) self.pkgmogrify("/wombat-farm", exit=1) + + def test_8(self): + """test for graceful exit with no output on abort""" + source_file = os.path.join(self.__test_dir, "source_file") + no_output = os.path.join(self.__test_dir, "no_output") + no_print = os.path.join(self.__test_dir, "no_print") + # + # add an abort transform that's expected to trigger + # this should cover the "exit gracefully" part of abort + # + self.pkgmogrify("-Di386_ONLY=' ' -DBUILDID=0.126 -P %s " \ + "-O %s %s %s %s" % (no_print, no_output, + self.transform_files[10], self.transform_files[12], + source_file)) + # make sure neither output nor print file was created + self.failIf(os.access(no_output, os.F_OK)) + self.failIf(os.access(no_print, os.F_OK)) + + def test_9(self): + """test for print output to specified file""" + source_file = os.path.join(self.__test_dir, "source_file") + output_file = os.path.join(self.__test_dir, "output_file") + print_file = os.path.join(self.__test_dir, "print_file") + # + # generate output for each file action, and count resulting + # lines in print file to be sure it matches our expectations + # + self.pkgmogrify("-Di386_ONLY=' ' -DBUILDID=0.126 -P %s " \ + "-O %s %s %s %s; egrep ouch %s | wc -l |" \ + "grep -w '3'" % (print_file, output_file, + self.transform_files[10], self.transform_files[11], + source_file, print_file)) diff --git a/src/util/publish/pkgmogrify.py b/src/util/publish/pkgmogrify.py --- a/src/util/publish/pkgmogrify.py +++ b/src/util/publish/pkgmogrify.py @@ -19,7 +19,7 @@ # # CDDL HEADER END # -# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Copyright 2010 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # @@ -37,6 +37,7 @@ includes = [] appends = [] transforms = [] +printinfo = [] @@ -49,7 +50,7 @@ print _( "/usr/bin/pkgmogrify [-v] [-I includedir ...] [-D macro=value ...] " - "[ -O outputfile] [inputfile ...]") + "[-O outputfile] [-P printfile] [inputfile ...]") sys.exit(exitcode) def add_transform(transform, filename, lineno): @@ -113,6 +114,15 @@ return action operation = default_func + if op[0] == "abort": + if len(op) > 1: + raise RuntimeError, \ + _("transform (%s) has 'abort' operation syntax error" + ) % transform + def abort_func(action): + sys.exit(0) + operation = abort_func + if op[0] == "add": try: attr, value = shlex.split(op[1]) @@ -207,6 +217,17 @@ operation = delete_func + if op[0] == "print": + if len(op) != 2: + raise RuntimeError, \ + _("transform (%s) has 'print' operation syntax error" + ) % transform + msg = op[1] + def print_func(action): + printinfo.append("%s" % msg) + return action + operation = print_func + transforms.append((types, attrdict, operation, filename, lineno, transform)) def attrval_as_list(attrdict, key): @@ -356,10 +377,11 @@ gettext.install("pkgmogrify", "/usr/lib/locale") outfilename = None + printfilename = None verbose = False try: - opts, pargs = getopt.getopt(sys.argv[1:], "vD:I:O:?", ["help"]) + opts, pargs = getopt.getopt(sys.argv[1:], "vD:I:O:P:?", ["help"]) for opt, arg in opts: if opt == "-D": if "=" not in arg: @@ -372,6 +394,8 @@ includes.append(arg) if opt == "-O": outfilename = arg + if opt == "-P": + printfilename = arg if opt == "-v": verbose = True @@ -413,6 +437,17 @@ error("File %s line %d: %s" % (filename, lineno, e)) try: + if printfilename == None: + printfile = sys.stdout + else: + printfile = file(printfilename, "w") + + for p in printinfo: + print >> printfile, "%s" % p + except IOError, e: + error(_("Cannot write extra data %s") % e) + + try: if outfilename == None: outfile = sys.stdout else: @@ -424,7 +459,6 @@ print >> outfile, "%s" % l if action: print >> outfile, "%s" % action - except IOError, e: error(_("Cannot write output %s") % e) @@ -442,5 +476,3 @@ exit_code = 99 sys.exit(exit_code) - -
_______________________________________________ pkg-discuss mailing list [email protected] http://mail.opensolaris.org/mailman/listinfo/pkg-discuss
