Merge lp:~jamesodhunt/upstart/initctl2dot-fix-for-subdirs into lp:upstart
Proposed by
James Hunt
Status: | Merged |
---|---|
Merged at revision: | 1462 |
Proposed branch: | lp:~jamesodhunt/upstart/initctl2dot-fix-for-subdirs |
Merge into: | lp:upstart |
Diff against target: |
270 lines (+109/-30) 4 files modified
ChangeLog (+12/-0) NEWS (+1/-1) scripts/initctl2dot.py (+70/-11) scripts/man/initctl2dot.8 (+26/-18) |
To merge this branch: | bzr merge lp:~jamesodhunt/upstart/initctl2dot-fix-for-subdirs |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Dimitri John Ledkov | Approve | ||
Review via email: mp+154935@code.launchpad.net |
Description of the change
* scripts/
- 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/
- Added --user and --system options.
- Escape dashes in options.
- Update date.
To post a comment you must log in.
On 22 March 2013 12:37, James Hunt <email address hidden> wrote: ).replace( ']', 'rbracket') \ .replace( ':', 'colon' ).replace( '*', 'star') \ ).replace( '.', '_') ).replace( '.', '_').replace('/', '_')
> # 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('!', 'bang')
> - .replace('?', 'question'
> + .replace('?', 'question'
>
I wonder if we can use translate instead here: sanitize_ table)
sanitize_table = str.maketrans({
'-': '_',
'$': 'dollar_',
'[': 'lbracker',
']': 'rbracker',
'!': 'bang',
':': 'colon',
'*': 'star',
'?': 'question',
'.': '_',
'/': '_',
})
return s.translate(
Somehow this is easier to read & edit =) maybe make that translation
table global, such that we don't create that object each time
sanitized is called.
> add_argument( "--user" , 'store_ true', add_argument( "--system" , 'store_ true', set_defaults( color_emits= default_ color_emits, on=default_ color_start_ on, on=default_ color_stop_ on, restrictions: restrictions. split(" ,") get('UPSTART_ SESSION' )
> + parser.
> + dest="user",
> + action=
> + help="Connect to Upstart user session (default if running within a user session).")
> +
> + parser.
> + dest="system",
> + action=
> + help="Connect to Upstart system session.")
> +
> parser.
> color_start_
> color_stop_
> @@ -504,6 +535,25 @@
> if options.
> restrictions_list = options.
>
> + upstart_session = os.environ.
> +
I'd change it to be os.environ. get('UPSTART_ SESSION' , False), such
that we get explicit False, instead of vague None when it's not
defined.
> + 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 foo == True" is not pythonic, simply use "if foo:"
Further more you are using if comparison to derive and assign a bollean value.
Why not just assign it?
use_system = options.system or not options.user or not upstart_session
Or you can make it easier by defining the option --user to be 'store_ false' & --system to be
dest='use_system', action=
dest='use_system', action='store_true' then you will only need to test
for the environment variable.
(It will give less flexibility in the future, but I don't think these
two options will evolve beyond simple binary choice).
Regards,
Dmitrijs.