def gsql_exec(sqlcmd): logger = logging.getLogger(LOGGER_NAME) try: try: if not len(sqlcmd) > 0: throws("Missing sqlcmd in gsql_exec") logger.debug("running gerrit sql : " + str(sqlcmd)) java_bin = find_java() logger.debug('using java_bin : %s' % java_bin) gerrit_war = find_gerritwar() logger.debug('using gerrit_war : %s' % gerrit_war) gerrit_site = find_gerritsite() logger.debug('using gerrit_site : %s' % gerrit_site) # example # /usr/bin/java -jar /home/gerrit2/review_site/bin/gerrit.war gsql -d /home/gerrit2/review_site -c 'show tables' results = exec_cmd(java_bin, ["-jar", gerrit_war, "gsql", "-d", gerrit_site, "-c", "" + sqlcmd + ""]) if results.upper().rstrip('\n').find('ERROR') >= 0: throws("gerrit sql command found errors in results : " + results) return (0, results) except Exception, err: logger.error('failed to run gsql_exec : ' + str(sqlcmd)) logger.error(str(err)) return (1, str(err)) finally: logger.debug("finished gsql_exec : " + str(sqlcmd))
def main(): global LOGGER_NAME # http://docs.python.org/2/library/argparse.html parser = argparse.ArgumentParser(description='Create a server certificate using the cacerts db.') parser.add_argument('--loglevel', help='Specify the default logging level (optional).', choices=['debug', 'info', 'warning', 'error', 'DEBUG', 'INFO', 'WARNING', 'ERROR'], default='info') parser.add_argument('--logfile', help='Specify logfile name.', default='/tmp/createfirstaccount.log') parser.add_argument('--debug', help='turn on debug output', action='store_true', default=False) parser.add_argument('--working_dir', help='working directory.', default='/tmp') parser.add_argument('--username', help='change default user name to create as first account.', default='gerrit2') parser.add_argument('--email', help='specify the email address for the user.', default='*****@*****.**') parser.add_argument('--ssh_pubkey', help='pupblic key to use. Example, generate with :\n ssh-keygen -t rsa -f ~/.ssh/gerrit2 -P ""', default='/home/gerrit2/.ssh/gerrit2.pub') parser.add_argument('--check_exists', help='just check if the first account exist, if it does not, then return 1, if it does return 0', action='store_true', default=False) args = parser.parse_args() if args.debug: args.loglevel = 'debug' logger = setup_logging(args.logfile, args.loglevel, LOGGER_NAME) banner_start() logger.debug("parsed arguments") # check that we have an ssh key try: if not os.path.isfile(args.ssh_pubkey): throws('No ssh public key found : ' + args.ssh_pubkey) except Exception, err: logger.error("Problem in file check : " + str(err)) return 300
def gsql_exec(sqlcmd): logger = logging.getLogger(LOGGER_NAME) try: try: if not len(sqlcmd) > 0: throws("Missing sqlcmd in gsql_exec") logger.debug("running gerrit sql : " + str(sqlcmd)) java_bin = find_java() logger.debug('using java_bin : %s' % java_bin) gerrit_war = find_gerritwar() logger.debug('using gerrit_war : %s' % gerrit_war) gerrit_site = find_gerritsite() logger.debug('using gerrit_site : %s' % gerrit_site) # example # /usr/bin/java -jar /home/gerrit2/review_site/bin/gerrit.war gsql -d /home/gerrit2/review_site -c 'show tables' results = exec_cmd(java_bin, [ "-jar", gerrit_war, "gsql", "-d", gerrit_site, "-c", "" + sqlcmd + "" ]) if results.upper().rstrip('\n').find('ERROR') >= 0: throws("gerrit sql command found errors in results : " + results) return (0, results) except Exception, err: logger.error('failed to run gsql_exec : ' + str(sqlcmd)) logger.error(str(err)) return (1, str(err)) finally: logger.debug("finished gsql_exec : " + str(sqlcmd))
def main(): global LOGGER_NAME # http://docs.python.org/2/library/argparse.html parser = argparse.ArgumentParser( description='Create a server certificate using the cacerts db.') parser.add_argument('--loglevel', help='Specify the default logging level (optional).', choices=[ 'debug', 'info', 'warning', 'error', 'DEBUG', 'INFO', 'WARNING', 'ERROR' ], default='info') parser.add_argument('--logfile', help='Specify logfile name.', default='/tmp/createfirstaccount.log') parser.add_argument('--debug', help='turn on debug output', action='store_true', default=False) parser.add_argument('--working_dir', help='working directory.', default='/tmp') parser.add_argument( '--username', help='change default user name to create as first account.', default='gerrit2') parser.add_argument('--email', help='specify the email address for the user.', default='*****@*****.**') parser.add_argument( '--ssh_pubkey', help= 'pupblic key to use. Example, generate with :\n ssh-keygen -t rsa -f ~/.ssh/gerrit2 -P ""', default='/home/gerrit2/.ssh/gerrit2.pub') parser.add_argument( '--check_exists', help= 'just check if the first account exist, if it does not, then return 1, if it does return 0', action='store_true', default=False) args = parser.parse_args() if args.debug: args.loglevel = 'debug' logger = setup_logging(args.logfile, args.loglevel, LOGGER_NAME) banner_start() logger.debug("parsed arguments") # check that we have an ssh key try: if not os.path.isfile(args.ssh_pubkey): throws('No ssh public key found : ' + args.ssh_pubkey) except Exception, err: logger.error("Problem in file check : " + str(err)) return 300