Ejemplo n.º 1
0
 def setConcurrency(self, concurrency):
     self.yamlDoc[0]['concurrency'] = concurrency
     try:
         log_update("Attempting to set concurrency to: %s" % concurrency)
         self.validateScript()
     except ConcurrencyException as e:
         log_update("Cannot set concurrency: %s" % e)
         self.setConcurrency(1)
Ejemplo n.º 2
0
 def setConcurrency(self, concurrency):
     self.yamlDoc[0]['concurrency'] = concurrency
     try:
         log_update("Attempting to set concurrency to: %s" % concurrency)
         self.validateScript()
     except ConcurrencyException as e:
         log_update("Cannot set concurrency: %s" % e)
         self.setConcurrency(1)
Ejemplo n.º 3
0
 def send_greetings(self, bot, update):
     my_upd = util.log_update('start', update)
     self.user_db.try_create(my_upd.user_id, my_upd.nick, my_upd.fullname)
     text = HELLO_TEXT + f'\n\n{self.state}'
     update.message.reply_text(text,
                               parse_mode=ParseMode.MARKDOWN,
                               disable_web_page_preview=True)
Ejemplo n.º 4
0
def main():
    """
    Main function.
    """

    dt = datetime.datetime.today()
    defaultlogfile = "taboot-%s.log" % (dt.strftime("%Y-%m-%d-%H%M%S"))
    addLogging = False
    overrideConcurrency = False

    parser = argparse.ArgumentParser(
                 formatter_class=argparse.RawDescriptionHelpFormatter,
                 description="Run a Taboot release script.",
                 epilog="""Taboot is a tool for written for scripting \
and automating the task of
performing software releases in a large-scale infrastructure. Release
scripts are written using YAML syntax.



Taboot home page: <https://fedorahosted.org/Taboot/>
Copyright 2009-2011, Red Hat, Inc
Taboot is released under the terms of the GPLv3+ license""")

    parser.add_argument('-V', '--version', action='version',
                        version='Taboot v%s' % __version__)
    parser.add_argument('-n', '--checkonly', action='store_true',
                        default=False,
                        help='Don\'t execute the release, just check \
                              script syntax.')
    parser.add_argument('-p', '--printonly', action='store_true',
                        default=False,
                        help='Don\'t execute the release, just check \
                              script syntax and print yaml to stdout.')
    parser.add_argument('-s', '--skippreflight', action='store_true',
                        default=False,
                        help='Skip preflight sections if they exist.')
    parser.add_argument('-L', '--logfile', const=defaultlogfile, nargs='?',
                        help='Adds [LogOutput: {logfile: LOGFILE}] to the \
                              script(s) being run.  If LOGFILE is not \
                              specified then taboot-YYYY-MM-DD-HHMMSS.log \
                              will be used')
    parser.add_argument('-C', '--concurrency', nargs=1, type=int,
                        help='Sets the concurrency for the input script(s)')
    parser.add_argument('-E', '--edit', action='store_true',
                        default=False,
                        help='Edit the input script(s) before running them \
                              using $EDITOR.  If $EDITOR is undefined then \
                              emacs will be used, if emacs is not found then \
                              vi will be used.')
    parser.add_argument('input_files', nargs='*', metavar='FILE',
                        help='Release file in YAML format.  Reads from stdin \
                              if FILE is \'-\' or not given.')
    args = parser.parse_args()

    if args.logfile:
        # Since we are snarfing the next positional argument after -L, we may
        # accidentally snarf up an input yaml file.  Hence the test to see if
        # our value is a .yaml file, and if it is, we will set the logfile to
        # the default and store the yaml file name to add to input_files
        pattern = re.compile(".*yaml$", re.IGNORECASE)
        if pattern.search(args.logfile):
            # We accidentally snarfed up a yaml script, add it back to
            # input_files and use the default format
            if args.input_files:
                args.input_files.insert(0, args.logfile)
            else:
                args.input_files = [args.logfile]
            logfile = defaultlogfile
        else:
            logfile = args.logfile

        # Need to print message informing user that we are adding logging and
        # to where
        log_update("Adding logging to file: %s" % logfile)
        addLogging = True

    if len(args.input_files) >= 1:
        input_files = args.input_files
    else:
        input_files = ['-']

    scripts = []

    for infile in input_files:
        # Open the input file for reading.
        try:
            if infile == '-':
                blob = sys.stdin.read()
            else:
                blob = open(infile).read()
                if args.edit:
                    tmpfile = tempfile.NamedTemporaryFile(suffix=".tmp",
                                              prefix="taboot-")
                    tmpfile.write(blob)
                    tmpfile.flush()
                    try:
                        EDITOR = os.environ.get('EDITOR', 'emacs')
                        call([EDITOR, tmpfile.name])
                    except OSError, e:
                        call(['vi', tmpfile.name])
                    blob = open(tmpfile.name).read()
                    tmpfile.close()
        except IOError, e:
            print "Failed to read input file '%s'. Are you sure it exists?" \
                  % infile
            sys.exit(1)

        # Print a helpful message when loading the YAML fails
        try:
            ds = [doc for doc in yaml.load_all(blob)]
        except yaml.YAMLError, exc:
            if hasattr(exc, 'problem_mark'):
                mark = exc.problem_mark
                probline = blob.split("\n")[mark.line]
                arrow = " " * mark.column + "^"
                msg = """
Syntax Error while loading YAML script, %s.
The problem is on line %s, column %s.

%s
%s""" % (infile, mark.line + 1, mark.column + 1, probline, arrow)
                print msg
                sys.exit(1)
            else:
                # No problem markers means we have to throw a generic
                # "stuff messed up" type message. Sry bud.
                msg = "Could not parse YAML. Check over %s again." % infile
                raise MalformedYAML(msg)