una base para cualquier script:
#!/usr/bin/env python # -*- coding: utf-8 -*- # # # Copyright 2017 # # This file is part of xxxxxx. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # ################## # # uso y funcionalidad # ################## # # to-do: # ################## import sys import logging, argparse from subprocess import Popen, PIPE # variables globales VERSION=0.1 TEMPDIR='tmp' INPUTFILE='lista.txt' LOGDEST = "/var/log/salida.log" def main(): parser = argparse.ArgumentParser() parser.add_argument('-d', '--debug', help='show debug messages', action='store_true') parser.add_argument('-v', '--version', help='show version info', action='version', version=VERSION) parser.add_argument('-i','--inputfile', action='store', help = 'input file') parser.add_argument('-l','--logdest', action='store', help = 'log file destination') parser.add_argument('-t','--tempdir', action='store', help = 'temp dir') args = parser.parse_args() if args.debug: # logging to file logging.basicConfig(filename=LOGDEST,format='%(asctime)s %(levelname)s:%(message)s',level=logging.DEBUG) # logging to stdout # logging.basicConfig(format='%(asctime)s %(levelname)s:%(message)s',level=logging.DEBUG) else: # logging to file logging.basicConfig(filename=LOGDEST,format='%(asctime)s %(levelname)s:%(message)s',level=logging.INFO) # logging to stdout # logging.basicConfig(format='%(asctime)s %(levelname)s:%(message)s',level=logging.INFO) if args.inputfile: global INPUTFILE INPUTFILE = args.inputfile if args.logdest: global LOGDEST LOGDEST = args.logdest if args.tempdir: global TEMPDIR TEMPDIR = args.tempdir (...new code here...) if __name__ == "__main__": main()