James Hunt has proposed merging lp:~jamesodhunt/upstart/initctl2dot-fix-for-subdirs into lp:upstart.
Requested reviews: Upstart Reviewers (upstart-reviewers) For more details, see: https://code.launchpad.net/~jamesodhunt/upstart/initctl2dot-fix-for-subdirs/+merge/154935 * scripts/initctl2dot.py: - footer(): Add details of session. - sanitise(): Handle jobs in sub-directories. - main(): Add --user and --system options and determine correct session to connect to. * scripts/man/initctl2dot.8: - Added --user and --system options. - Escape dashes in options. - Update date. -- https://code.launchpad.net/~jamesodhunt/upstart/initctl2dot-fix-for-subdirs/+merge/154935 Your team Upstart Reviewers is requested to review the proposed merge of lp:~jamesodhunt/upstart/initctl2dot-fix-for-subdirs into lp:upstart.
=== modified file 'ChangeLog' --- ChangeLog 2013-03-22 10:55:18 +0000 +++ ChangeLog 2013-03-22 12:36:21 +0000 @@ -1,3 +1,15 @@ +2013-03-22 James Hunt <[email protected]> + + * scripts/initctl2dot.py: + - footer(): Add details of session. + - sanitise(): Handle jobs in sub-directories. + - main(): Add --user and --system options and determine correct + session to connect to. + * scripts/man/initctl2dot.8: + - Added --user and --system options. + - Escape dashes in options. + - Update date. + 2013-03-21 James Hunt <[email protected]> * po/POTFILES.in: === modified file 'scripts/initctl2dot.py' (properties changed: -x to +x) --- scripts/initctl2dot.py 2012-12-07 18:26:43 +0000 +++ scripts/initctl2dot.py 2013-03-22 12:36:21 +0000 @@ -57,9 +57,12 @@ options = None jobs = {} events = {} -cmd = "initctl --system show-config -e" script_name = os.path.basename(sys.argv[0]) +cmd = None +use_system = True +upstart_session = None + # list of jobs to restict output to restrictions_list = [] @@ -86,10 +89,20 @@ def footer(ofh): + global upstart_session + global use_system + + details = '' + + if use_system == True: + details += "\\nfor the system\\n" + else: + details += "\\nfor session '%s'\\n" % upstart_session + if options.restrictions: - details = "(subset, " + details += "(subset, " else: - details = "(" + details += "(" if options.infile: details += "from file data)." @@ -110,12 +123,13 @@ # Map dash to underscore since graphviz node names cannot -# contain dashes. Also remove dollars and colons +# contain dashes. Also remove dollars and colons and replace other +# punctuation with graphiviz-safe names. def sanitise(s): return s.replace('-', '_').replace('$', 'dollar_') \ .replace('[', 'lbracket').replace(']', 'rbracket') \ .replace('!', 'bang').replace(':', 'colon').replace('*', 'star') \ - .replace('?', 'question').replace('.', '_') + .replace('?', 'question').replace('.', '_').replace('/', '_') # Convert a dollar in @name to a unique-ish new name, based on @job and @@ -334,6 +348,10 @@ def read_data(): + global cmd + global upstart_session + global use_system + if options.infile: try: ifh = open(options.infile, 'r') @@ -412,6 +430,9 @@ def main(): global options global restrictions_list + global cmd + global use_system + global upstart_session description = "Convert initctl(8) output to GraphViz dot(1) format." epilog = "See http://www.graphviz.org/doc/info/colors.html " \ @@ -426,8 +447,8 @@ parser.add_argument("-f", "--infile", dest="infile", - help="File to read '%s' output from. If not specified" - ", initctl will be run automatically." % cmd) + help="File to read output from. If not specified" + ", initctl will be run automatically.") parser.add_argument("-o", "--outfile", dest="outfile", @@ -479,6 +500,16 @@ help="Specify color for job boxes (default=%s)." % default_color_job) + parser.add_argument("--user", + dest="user", + action='store_true', + help="Connect to Upstart user session (default if running within a user session).") + + parser.add_argument("--system", + dest="system", + action='store_true', + help="Connect to Upstart system session.") + parser.set_defaults(color_emits=default_color_emits, color_start_on=default_color_start_on, color_stop_on=default_color_stop_on, @@ -504,6 +535,25 @@ if options.restrictions: restrictions_list = options.restrictions.split(",") + upstart_session = os.environ.get('UPSTART_SESSION') + + use_system = True + + if options.system == False and options.user == False: + if upstart_session: + use_system = False + else: + use_system = True + elif options.system == True: + use_system = True + elif options.user == True: + use_system = False + + if use_system: + cmd = "initctl --system show-config -e" + else: + cmd = "initctl show-config -e" + read_data() for job in restrictions_list: === modified file 'scripts/man/initctl2dot.8' --- scripts/man/initctl2dot.8 2011-06-01 14:28:20 +0000 +++ scripts/man/initctl2dot.8 2013-03-22 12:36:21 +0000 @@ -1,4 +1,4 @@ -.TH initctl2dot 8 2011-03-07 "Upstart" +.TH initctl2dot 8 2013-03-22 "Upstart" .\" .SH NAME initctl2dot \- manual page for initctl2dot @@ -17,56 +17,64 @@ With no options, .BR initctl (8) will be invoked automatically and the output written to file -\fIupstart.dot\fP. +\fIupstart.dot\fP. If run from within an Upstart user session, unless +.B \-\-system +is specified, the data generated will be for the user session. .\" .SH OPTIONS .TP -.B -h -Display usage statement. -.TP -\fB-f\fP \fIINFILE\fP , \fP--infile\fP=\fIINFILE\fP +\fB\-f\fP \fIINFILE\fP , \fP\-\-infile\fP=\fIINFILE\fP File to read .BR initctl (8) output from ("initctl show-config -e"). If not specified, .BR initctl (8) will be run automatically. .TP -\fB-w\fP \fIOUTFILE\fP , \fP--outfile\fP=\fIOUTFILE\fP -File to write output to. +.B \-h +Display usage statement. .TP -\fB-r\fP \fIRESTRICTIONS\fP , \fP--restrict-to-jobs\fP=\fIRESTRICTIONS\fP +\fB\-r\fP \fIRESTRICTIONS\fP , \fP\-\-restrict-to-jobs\fP=\fIRESTRICTIONS\fP Limit display of .B start on and .B stop on conditions to comma-separated list of jobs. .TP -\fB--color-emits\fP=\fICOLOR_EMITS\fP +\fB\-w\fP \fIOUTFILE\fP , \fP\-\-outfile\fP=\fIOUTFILE\fP +File to write output to. +.TP +\fB\-\-color-emits\fP=\fICOLOR_EMITS\fP Specify color for 'emits' lines. .TP -\fB--color-start-on\fP=\fICOLOR_START_ON\fP +\fB\-\-color-start-on\fP=\fICOLOR_START_ON\fP Specify color for 'start on' lines. .TP -\fB--color-stop-on\fP=\fICOLOR_STOP_ON\fP +\fB\-\-color-stop-on\fP=\fICOLOR_STOP_ON\fP Specify color for 'stop on' lines. .TP -\fB--color-event\fP=\fICOLOR_EVENT\fP +\fB\-\-color-event\fP=\fICOLOR_EVENT\fP Specify color for event boxes. .TP -\fB--color-text\fP=\fICOLOR_TEXT\fP +\fB\-\-color-text\fP=\fICOLOR_TEXT\fP Specify color for summary text. .TP -\fB--color-bg\fP=\fICOLOR_BG\fP +\fB\-\-color-bg\fP=\fICOLOR_BG\fP Specify background color for diagram. .TP -\fB--color-event-text\fP=\fICOLOR_EVENT_TEXT\fP +\fB\-\-color-event-text\fP=\fICOLOR_EVENT_TEXT\fP Specify color for text in event boxes. .TP -\fB--color-job-text\fP=\fICOLOR_JOB_TEXT\fP +\fB\-\-color-job-text\fP=\fICOLOR_JOB_TEXT\fP Specify color for text in job boxes. .TP -\fB--color-job\fP=\fICOLOR_JOB\fP +\fB\-\-color-job\fP=\fICOLOR_JOB\fP Specify color for job boxes. +.TP +\fB\-\-system\fP +Connect to the Upstart system session. +.TP +\fB\-\-user\fP +Connect to the Upstart user session. .\" .SH AUTHOR Written by James Hunt
-- upstart-devel mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/upstart-devel
