@@ -0,0 +1,2869 @@
+#!/usr/bin/env python%0A%22%22%22A template for creating python scripts. After parsing of the command line%0Aarguments through the function parse_args, the whole application control goes%0Ato the class App's run method.%0A%0AThe template has a logger _log being ready.%0A%0ACommand line options of the script should be added to the parser of the%0Afunction parse_args.%0A%0A%0A    Copyright 2016 Heung Ming Tai%0A%0A    Licensed under the Apache License, Version 2.0 (the %22License%22);%0A    you may not use this file except in compliance with the License.%0A    You may obtain a copy of the License at%0A%0A        http://www.apache.org/licenses/LICENSE-2.0%0A%0A    Unless required by applicable law or agreed to in writing, software%0A    distributed under the License is distributed on an %22AS IS%22 BASIS,%0A    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A    See the License for the specific language governing permissions and%0A    limitations under the License.%0A%22%22%22%0Afrom __future__ import print_function%0Afrom __future__ import absolute_import%0Afrom __future__ import division%0Afrom __future__ import unicode_literals%0A%0Aimport argparse%0Aimport logging%0Aimport subprocess%0Aimport sys%0A%0Afrom sorno import loggingutil%0A%0A%0A_log = logging.getLogger()%0A%0A%0Aclass App(object):%0A    %22%22%22A console application to do work%22%22%22%0A    def __init__(self, args):%0A        %22%22%22%0A        Args:%0A            args (argparse.Namespace): The flags for the script.%0A        %22%22%22%0A        self.args = args%0A%0A    def run(self):%0A        %22%22%22The entry point of the script%0A        %22%22%22%0A        _log.info(%22hello world%22)%0A        _log.debug(%22hello world%22)%0A        return 0%0A%0A    def _run_cmd(self, cmd):%0A        %22%22%22Run a shell command%0A%0A        Args:%0A            cmd (string or a list of strings): The shell command to run. If%0A                it's a string, uses the system shell to run the command. If%0A                it's a list of strings, the first string is the program to run%0A                and the rest are its arguments. The arguments are quoted%0A                properly by the subprocess module, so the arguments do not%0A                have to be quoted when passing to this method.%0A        %22%22%22%0A        _log.info(cmd)%0A        if isinstance(cmd, list):%0A            use_shell = False%0A        else:%0A            use_shell = True%0A        return subprocess.check_call(cmd, shell=use_shell)%0A%0A%0Adef parse_args(cmd_args):%0A    description = __doc__.split(%22Copyright 2016%22)%5B0%5D.strip()%0A%0A    parser = argparse.ArgumentParser(%0A        description=description,%0A        formatter_class=argparse.RawDescriptionHelpFormatter,%0A    )%0A    parser.add_argument(%0A        %22--debug%22,%0A        action=%22store_true%22,%0A    )%0A%0A    args = parser.parse_args(cmd_args)%0A    return args%0A%0A%0Adef main():%0A    args = parse_args(sys.argv%5B1:%5D)%0A%0A    loggingutil.setup_logger(_log, debug=args.debug)%0A%0A    app = App(args)%0A    sys.exit(app.run())%0A%0A%0Aif __name__ == '__main__':%0A    main()%0A

Add script_with_simple_logging_template.py