Exemplo n.º 1
0
    def GET(self, token=None):

        if token != cherrystrap.API_TOKEN:
            return "{\"status\": \"error\", \"message\": \"Invalid Token\"}"

        configuration = {
            "server": {
                "appName": cherrystrap.APP_NAME,
                "logDir": cherrystrap.LOGDIR,
                "httpHost": cherrystrap.HTTP_HOST,
                "httpPort": int(cherrystrap.HTTP_PORT),
                "sslEnabled": bool(cherrystrap.HTTPS_ENABLED),
                "sslKey": cherrystrap.HTTPS_KEY,
                "sslCert": cherrystrap.HTTPS_CERT,
                "sslVerify": bool(cherrystrap.VERIFY_SSL),
                "launchBrowser": bool(cherrystrap.LAUNCH_BROWSER)
            },
            "interface": {
                "httpUser": cherrystrap.HTTP_USER,
                "httpPass": cherrystrap.HTTP_PASS,
                "httpLook": cherrystrap.HTTP_LOOK,
                "apiToken": cherrystrap.API_TOKEN
            },
            "database": {
                "dbType": cherrystrap.DATABASE_TYPE,
                "mysqlHost": cherrystrap.MYSQL_HOST,
                "mysqlPort": int(cherrystrap.MYSQL_PORT),
                "mysqlUser": cherrystrap.MYSQL_USER,
                "mysqlPass": cherrystrap.MYSQL_PASS
            },
            "git": {
                "gitEnabled": bool(cherrystrap.GIT_ENABLED),
                "gitPath": cherrystrap.GIT_PATH,
                "gitUser": cherrystrap.GIT_USER,
                "gitRepo": cherrystrap.GIT_REPO,
                "gitBranch": cherrystrap.GIT_BRANCH,
                "gitUpstream": cherrystrap.GIT_UPSTREAM,
                "gitLocal": cherrystrap.GIT_LOCAL,
                "gitStartup": bool(cherrystrap.GIT_STARTUP),
                "gitInterval": int(cherrystrap.GIT_INTERVAL),
                "gitOverride": bool(cherrystrap.GIT_OVERRIDE)
            }
        }

        #===============================================================
        # Import a variable injector from your app's __init__.py
        try:
            from jiraappy import injectApiConfigGet
            configuration.update(injectApiConfigGet())
        except Exception, e:
            logger.debug(
                "There was a problem injection application variables into API-GET: %s"
                % e)
Exemplo n.º 2
0
def check_setting_int(config, cfg_name, item_name, def_val):
    try:
        my_val = int(config[cfg_name][item_name])
    except:
        my_val = def_val
        try:
            config[cfg_name][item_name] = my_val
        except:
            config[cfg_name] = {}
            config[cfg_name][item_name] = my_val
    logger.debug(item_name + " -> " + str(my_val))
    return my_val
Exemplo n.º 3
0
    def GET(self, token=None):

        if token != cherrystrap.API_TOKEN:
            return "{\"status\": \"error\", \"message\": \"Invalid Token\"}"

        configuration = {
            "server": {
                "appName":  cherrystrap.APP_NAME,
                "logDir": cherrystrap.LOGDIR,
                "httpHost": cherrystrap.HTTP_HOST,
                "httpPort": int(cherrystrap.HTTP_PORT),
                "sslEnabled": bool(cherrystrap.HTTPS_ENABLED),
                "sslKey": cherrystrap.HTTPS_KEY,
                "sslCert": cherrystrap.HTTPS_CERT,
                "sslVerify": bool(cherrystrap.VERIFY_SSL),
                "launchBrowser": bool(cherrystrap.LAUNCH_BROWSER)
            },
            "interface": {
                "httpUser": cherrystrap.HTTP_USER,
                "httpPass": cherrystrap.HTTP_PASS,
                "httpLook": cherrystrap.HTTP_LOOK,
                "apiToken": cherrystrap.API_TOKEN
            },
            "database": {
                "dbType": cherrystrap.DATABASE_TYPE,
                "mysqlHost": cherrystrap.MYSQL_HOST,
                "mysqlPort": int(cherrystrap.MYSQL_PORT),
                "mysqlUser": cherrystrap.MYSQL_USER,
                "mysqlPass": cherrystrap.MYSQL_PASS
            },
            "git": {
                "gitEnabled": bool(cherrystrap.GIT_ENABLED),
                "gitPath": cherrystrap.GIT_PATH,
                "gitUser": cherrystrap.GIT_USER,
                "gitRepo": cherrystrap.GIT_REPO,
                "gitBranch": cherrystrap.GIT_BRANCH,
                "gitUpstream": cherrystrap.GIT_UPSTREAM,
                "gitLocal": cherrystrap.GIT_LOCAL,
                "gitStartup": bool(cherrystrap.GIT_STARTUP),
                "gitInterval": int(cherrystrap.GIT_INTERVAL),
                "gitOverride": bool(cherrystrap.GIT_OVERRIDE)
            }
        }

        #===============================================================
        # Import a variable injector from your app's __init__.py
        try:
            from jiraappy import injectApiConfigGet
            configuration.update(injectApiConfigGet())
        except Exception, e:
            logger.debug("There was a problem injection application variables into API-GET: %s" % e)
Exemplo n.º 4
0
def config_write():
    new_config = ConfigObj()
    new_config.filename = CONFIGFILE

    new_config['Server'] = {}
    new_config['Server']['appName'] = APP_NAME
    new_config['Server']['httpRoot'] = HTTP_ROOT
    new_config['Server']['logDir'] = LOGDIR
    new_config['Server']['httpHost'] = HTTP_HOST
    new_config['Server']['httpPort'] = HTTP_PORT
    new_config['Server']['sslEnabled'] = HTTPS_ENABLED
    new_config['Server']['sslKey'] = HTTPS_KEY
    new_config['Server']['sslCert'] = HTTPS_CERT
    new_config['Server']['sslVerify'] = VERIFY_SSL
    new_config['Server']['launchBrowser'] = LAUNCH_BROWSER

    new_config['Interface'] = {}
    new_config['Interface']['httpUser'] = HTTP_USER
    new_config['Interface']['httpPass'] = HTTP_PASS
    new_config['Interface']['httpLook'] = HTTP_LOOK
    new_config['Interface']['apiToken'] = API_TOKEN

    new_config['Database'] = {}
    new_config['Database']['dbType'] = DATABASE_TYPE
    new_config['Database']['mysqlHost'] = MYSQL_HOST
    new_config['Database']['mysqlPort'] = MYSQL_PORT
    new_config['Database']['mysqlUser'] = MYSQL_USER
    new_config['Database']['mysqlPass'] = MYSQL_PASS

    new_config['Git'] = {}
    new_config['Git']['gitEnabled'] = GIT_ENABLED
    new_config['Git']['gitPath'] = GIT_PATH
    new_config['Git']['gitUser'] = GIT_USER
    new_config['Git']['gitRepo'] = GIT_REPO
    new_config['Git']['gitBranch'] = GIT_BRANCH
    new_config['Git']['gitUpstream'] = GIT_UPSTREAM
    new_config['Git']['gitLocal'] = GIT_LOCAL
    new_config['Git']['gitStartup'] = GIT_STARTUP
    new_config['Git']['gitInterval'] = GIT_INTERVAL
    new_config['Git']['gitOverride'] = GIT_OVERRIDE

    #===============================================================
    # Import a variable writer from your app's __init__.py
    try:
        from jiraappy import injectVarWrite
        injectVarWrite(new_config)
    except Exception, e:
        logger.debug(
            "There was a problem importing application variables to write: %s"
            % e)
Exemplo n.º 5
0
def check_setting_str(config, cfg_name, item_name, def_val):
    try:
        my_val = str(config[cfg_name][item_name])
    except:
        my_val = def_val
        try:
            config[cfg_name][item_name] = ast.literal_eval(my_val)
            logger.warn("Bad value for %s in config.ini. Reverting to default" % item_name)
        except:
            config[cfg_name] = {}
            config[cfg_name][item_name] = my_val
            logger.error("Bad default value for %s. Application may break" % item_name)
    logger.debug(item_name + " -> " + str(my_val))
    return my_val
Exemplo n.º 6
0
def config_write():
    new_config = ConfigObj()
    new_config.filename = CONFIGFILE

    new_config['Server'] = {}
    new_config['Server']['appName'] = APP_NAME
    new_config['Server']['httpRoot'] = HTTP_ROOT
    new_config['Server']['logDir'] = LOGDIR
    new_config['Server']['httpHost'] = HTTP_HOST
    new_config['Server']['httpPort'] = HTTP_PORT
    new_config['Server']['sslEnabled'] = HTTPS_ENABLED
    new_config['Server']['sslKey'] = HTTPS_KEY
    new_config['Server']['sslCert'] = HTTPS_CERT
    new_config['Server']['sslVerify'] = VERIFY_SSL
    new_config['Server']['launchBrowser'] = LAUNCH_BROWSER

    new_config['Interface'] = {}
    new_config['Interface']['httpUser'] = HTTP_USER
    new_config['Interface']['httpPass'] = HTTP_PASS
    new_config['Interface']['httpLook'] = HTTP_LOOK
    new_config['Interface']['apiToken'] = API_TOKEN

    new_config['Database'] = {}
    new_config['Database']['dbType'] = DATABASE_TYPE
    new_config['Database']['mysqlHost'] = MYSQL_HOST
    new_config['Database']['mysqlPort'] = MYSQL_PORT
    new_config['Database']['mysqlUser'] = MYSQL_USER
    new_config['Database']['mysqlPass'] = MYSQL_PASS

    new_config['Git'] = {}
    new_config['Git']['gitEnabled'] = GIT_ENABLED
    new_config['Git']['gitPath'] = GIT_PATH
    new_config['Git']['gitUser'] = GIT_USER
    new_config['Git']['gitRepo'] = GIT_REPO
    new_config['Git']['gitBranch'] = GIT_BRANCH
    new_config['Git']['gitUpstream'] = GIT_UPSTREAM
    new_config['Git']['gitLocal'] = GIT_LOCAL
    new_config['Git']['gitStartup'] = GIT_STARTUP
    new_config['Git']['gitInterval'] = GIT_INTERVAL
    new_config['Git']['gitOverride'] = GIT_OVERRIDE

    #===============================================================
    # Import a variable writer from your app's __init__.py
    try:
        from jiraappy import injectVarWrite
        injectVarWrite(new_config)
    except Exception, e:
        logger.debug("There was a problem importing application variables to write: %s" % e)
Exemplo n.º 7
0
def check_setting_str(config, cfg_name, item_name, def_val, log=True):
    try:
        my_val = config[cfg_name][item_name]
    except:
        my_val = def_val
        try:
            config[cfg_name][item_name] = my_val
        except:
            config[cfg_name] = {}
            config[cfg_name][item_name] = my_val

    if log:
        logger.debug(item_name + " -> " + my_val)
    else:
        logger.debug(item_name + " -> ******")

    return my_val
Exemplo n.º 8
0
def runGit(args):

    if cherrystrap.GIT_PATH:
        git_locations = ['"' + cherrystrap.GIT_PATH + '"']
    else:
        git_locations = ['git']

    if platform.system().lower() == 'darwin':
        git_locations.append('/usr/local/git/bin/git')

    output = err = None

    for cur_git in git_locations:
        cmd = cur_git + ' ' + args

        try:
            logger.debug('Trying to execute: "' + cmd + '" with shell in ' + cherrystrap.PROG_DIR)
            p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, cwd=cherrystrap.PROG_DIR)
            output, err = p.communicate()
            output = output.strip()

            logger.debug('Git output: ' + output)
        except OSError:
            logger.debug('Command failed: %s', cmd)
            continue

        if 'not found' in output or "not recognized as an internal or external command" in output:
            logger.debug('Unable to find git with command ' + cmd)
            output = None
        elif 'fatal:' in output or err:
            logger.error('Git returned bad info. Are you sure this is a git installation?')
            output = None
        elif output:
            break

    return (output, err)
Exemplo n.º 9
0
            except:
                cherrystrap.GIT_INTERVAL = 12
                errorList.append("gitInterval must be an integer")
                kwargs.pop('gitInterval', 12)
        if 'gitOverride' in kwargs:
            cherrystrap.GIT_OVERRIDE = kwargs.pop('gitOverride', False) == 'true'
        elif 'gitOverrideHidden' in kwargs:
            cherrystrap.GIT_OVERRIDE = kwargs.pop('gitOverrideHidden', False) == 'true'

        #===============================================================
        # Import a variable injector from your app's __init__.py
        try:
            from jiraappy import injectApiConfigPut
            kwargs, errorList = injectApiConfigPut(kwargs, errorList)
        except Exception, e:
            logger.debug("There was a problem injection application variables into API-PUT: %s" % e)
        #================================================================

        if len(kwargs) != 0:
            for key, value in kwargs.items():
                errorList.append("Key %s not expected" % key)

        cherrystrap.config_write()
        if not errorList:
            logger.info("All configuration settings successfully updated")
            return "{\"status\": \"success\", \
                \"message\": \"All configuration settings successfully updated\"}"
        else:
            logger.warn("The following error(s) occurred while attempting to update settings: %s" % errorList)
            return "{\"status\": \"warning\", \
                \"message\": \"The following error(s) occurred while attempting to update settings: %s\"}" % errorList
Exemplo n.º 10
0
def initialize():

    with INIT_LOCK:

        global __INITIALIZED__, FULL_PATH, PROG_DIR, LOGLEVEL, DAEMON, \
        DATADIR, CONFIGFILE, CFG, LOGDIR, APP_NAME, HTTP_HOST, HTTP_PORT, \
        HTTP_USER, HTTP_PASS, HTTP_ROOT, HTTP_LOOK, VERIFY_SSL, \
        LAUNCH_BROWSER, HTTPS_ENABLED, HTTPS_KEY, HTTPS_CERT, API_TOKEN, \
        DATABASE_TYPE, MYSQL_HOST, MYSQL_PORT, MYSQL_USER, MYSQL_PASS, \
        GIT_ENABLED, GIT_PATH, GIT_BRANCH, GIT_USER, GIT_STARTUP, GIT_INTERVAL, \
        GIT_OVERRIDE, GIT_REPO, GIT_UPSTREAM, GIT_LOCAL, GIT_EXISTS

        if __INITIALIZED__:
            return False

        CheckSection(CFG, 'Server')
        CheckSection(CFG, 'Interface')
        CheckSection(CFG, 'Database')
        CheckSection(CFG, 'Git')

        LOGDIR = check_setting_str(CFG, 'Server', 'logDir', '')

        if not LOGDIR:
            LOGDIR = os.path.join(DATADIR, 'Logs')

        # Create logdir
        if not os.path.exists(LOGDIR):
            try:
                os.makedirs(LOGDIR)
            except OSError:
                if LOGLEVEL:
                    print LOGDIR + ":"
                    print ' Unable to create folder for logs. Only logging to console.'

        # Start the logger, silence console logging if we need to
        logger.cherrystrap_log.initLogger(loglevel=LOGLEVEL)

        # Put the cache dir in the data dir for now
        CACHEDIR = os.path.join(DATADIR, 'cache')
        if not os.path.exists(CACHEDIR):
            try:
                os.makedirs(CACHEDIR)
            except OSError:
                logger.error(
                    'Could not create cachedir. Check permissions of: ' +
                    DATADIR)

        GIT_EXISTS = os.path.isdir(os.path.join(DATADIR, '.git'))

        # Attempt to find location of git in this environment
        if GIT_EXISTS:
            output = err = None
            cmd = 'which git'
            try:
                logger.debug('Trying to execute: "' + cmd +
                             '" with shell in ' + os.getcwd())
                p = subprocess.Popen(cmd,
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.STDOUT,
                                     shell=True,
                                     cwd=os.getcwd())
                output, err = p.communicate()
                output = output.strip()
                logger.debug('Git output: ' + output)
            except OSError:
                logger.debug('Command failed: %s', cmd)

            if not output or 'not found' in output or "not recognized as an internal or external command" in output:
                logger.debug('Unable to find git with command ' + cmd)
                git_enabled = False
                git_path = ''
                git_startup = False
                git_interval = 0
            else:
                git_enabled = True
                git_path = output
                git_startup = True
                git_interval = 12
        else:
            git_enabled = False
            git_path = ''
            git_startup = False
            git_interval = 0

        try:
            HTTP_PORT = check_setting_int(CFG, 'Server', 'httpPort', 7889)
        except:
            HTTP_PORT = 7889

        if HTTP_PORT < 21 or HTTP_PORT > 65535:
            HTTP_PORT = 7889

        APP_NAME = check_setting_str(CFG, 'Server', 'appName', 'CherryStrap')
        HTTP_ROOT = check_setting_str(CFG, 'Server', 'httpRoot', '')
        HTTP_HOST = check_setting_str(CFG, 'Server', 'httpHost', '0.0.0.0')
        HTTPS_ENABLED = check_setting_bool(CFG, 'Server', 'sslEnabled', False)
        HTTPS_KEY = check_setting_str(CFG, 'Server', 'sslKey',
                                      'keys/server.key')
        HTTPS_CERT = check_setting_str(CFG, 'Server', 'sslCert',
                                       'keys/server.crt')
        VERIFY_SSL = check_setting_bool(CFG, 'Server', 'sslVerify', True)
        LAUNCH_BROWSER = check_setting_bool(CFG, 'Server', 'launchBrowser',
                                            False)

        HTTP_USER = check_setting_str(CFG, 'Interface', 'httpUser', '')
        HTTP_PASS = check_setting_str(CFG, 'Interface', 'httpPass', '')
        HTTP_LOOK = check_setting_str(CFG, 'Interface', 'httpLook',
                                      'bootstrap')
        API_TOKEN = check_setting_str(CFG, 'Interface', 'apiToken',
                                      uuid.uuid4().hex)

        DATABASE_TYPE = check_setting_str(CFG, 'Database', 'dbType', '')
        MYSQL_HOST = check_setting_str(CFG, 'Database', 'mysqlHost',
                                       'localhost')
        MYSQL_PORT = check_setting_int(CFG, 'Database', 'mysqlPort', 3306)
        MYSQL_USER = check_setting_str(CFG, 'Database', 'mysqlUser', '')
        MYSQL_PASS = check_setting_str(CFG, 'Database', 'mysqlPass', '')

        GIT_ENABLED = check_setting_bool(CFG, 'Git', 'gitEnabled', git_enabled)
        GIT_PATH = check_setting_str(CFG, 'Git', 'gitPath', git_path)
        GIT_USER = check_setting_str(CFG, 'Git', 'gitUser', 'theguardian')
        GIT_REPO = check_setting_str(CFG, 'Git', 'gitRepo', 'CherryStrap')
        GIT_BRANCH = check_setting_str(CFG, 'Git', 'gitBranch', 'master')
        GIT_UPSTREAM = check_setting_str(CFG, 'Git', 'gitUpstream', '')
        GIT_LOCAL = check_setting_str(CFG, 'Git', 'gitLocal', '')
        GIT_STARTUP = check_setting_bool(CFG, 'Git', 'gitStartup', git_startup)
        GIT_INTERVAL = check_setting_int(CFG, 'Git', 'gitInterval',
                                         git_interval)
        GIT_OVERRIDE = check_setting_bool(CFG, 'Git', 'gitOverride', False)

        #===============================================================
        # Import a variable definer / checker from your app's __init__.py
        try:
            from jiraappy import injectVarCheck
            injectVarCheck(CFG)
        except Exception, e:
            logger.debug(
                "There was a problem importing application variable definitions: %s"
                % e)
        #================================================================

        # Initialize the database
        try:
            createDb(DATABASE_TYPE, DATADIR, APP_NAME, MYSQL_HOST, MYSQL_PORT,
                     MYSQL_USER, MYSQL_PASS)
        except Exception, e:
            logger.error("Error initializing the database: %s" % e)
Exemplo n.º 11
0
    os.umask(prev and int('077', 8))

    # Make the child a session-leader by detaching from the terminal
    try:
        pid = os.fork()  #@UndefinedVariable - only available in UNIX
        if pid != 0:
            sys.exit(0)
    except OSError, e:
        raise RuntimeError("2st fork failed: %s [%d]" % (e.strerror, e.errno))

    dev_null = file('/dev/null', 'r')
    os.dup2(dev_null.fileno(), sys.stdin.fileno())

    if PIDFILE:
        pid = str(os.getpid())
        logger.debug(u"Writing PID " + pid + " to " + str(PIDFILE))
        file(PIDFILE, 'w').write("%s\n" % pid)


def launch_browser(host, port, root):
    if host == '0.0.0.0':
        host = 'localhost'

    if HTTPS_ENABLED:
        protocol = 'https'
    else:
        protocol = 'http'

    try:
        import webbrowser
        webbrowser.open('%s://%s:%i%s' % (protocol, host, port, root))
Exemplo n.º 12
0
def checkGithub():
    cherrystrap.COMMITS_BEHIND = 0

    # Get the latest version available from github
    logger.info('Retrieving latest version information from GitHub')
    url = 'https://api.github.com/repos/%s/%s/commits/%s' % (cherrystrap.GIT_USER, cherrystrap.GIT_REPO, cherrystrap.GIT_BRANCH)
    try:
        result = urllib2.urlopen(url).read()
        version = json.JSONDecoder().decode(result)
    except Exception, e:
        logger.warn('Could not get the latest version from GitHub. Are you running a local development version?: %s' % e)
        return cherrystrap.GIT_LOCAL

    cherrystrap.GIT_UPSTREAM = version['sha']
    logger.debug("Latest version is %s" % cherrystrap.GIT_UPSTREAM)

    # See how many commits behind we are
    if not cherrystrap.GIT_LOCAL:
        logger.info('You are running an unknown version of %s. Run the updater to identify your version' % cherrystrap.APP_NAME)
        return cherrystrap.GIT_UPSTREAM

    if cherrystrap.GIT_UPSTREAM == cherrystrap.GIT_LOCAL:
        logger.info('%s is up to date' % cherrystrap.APP_NAME)
        return cherrystrap.GIT_UPSTREAM

    logger.info('Comparing currently installed version with latest GitHub version')
    url = 'https://api.github.com/repos/%s/%s/compare/%s...%s' % (cherrystrap.GIT_USER, cherrystrap.GIT_REPO, cherrystrap.GIT_UPSTREAM, cherrystrap.GIT_LOCAL)
    try:
        result = urllib2.urlopen(url).read()
        commits = json.JSONDecoder().decode(result)
Exemplo n.º 13
0
def initialize():

    with INIT_LOCK:

        global __INITIALIZED__, FULL_PATH, PROG_DIR, LOGLEVEL, DAEMON, \
        DATADIR, CONFIGFILE, CFG, LOGDIR, APP_NAME, HTTP_HOST, HTTP_PORT, \
        HTTP_USER, HTTP_PASS, HTTP_ROOT, HTTP_LOOK, VERIFY_SSL, \
        LAUNCH_BROWSER, HTTPS_ENABLED, HTTPS_KEY, HTTPS_CERT, API_TOKEN, \
        DATABASE_TYPE, MYSQL_HOST, MYSQL_PORT, MYSQL_USER, MYSQL_PASS, \
        GIT_ENABLED, GIT_PATH, GIT_BRANCH, GIT_USER, GIT_STARTUP, GIT_INTERVAL, \
        GIT_OVERRIDE, GIT_REPO, GIT_UPSTREAM, GIT_LOCAL, GIT_EXISTS

        if __INITIALIZED__:
            return False

        CheckSection(CFG, 'Server')
        CheckSection(CFG, 'Interface')
        CheckSection(CFG, 'Database')
        CheckSection(CFG, 'Git')

        LOGDIR = check_setting_str(CFG, 'Server', 'logDir', '')

        if not LOGDIR:
            LOGDIR = os.path.join(DATADIR, 'Logs')

        # Create logdir
        if not os.path.exists(LOGDIR):
            try:
                os.makedirs(LOGDIR)
            except OSError:
                if LOGLEVEL:
                    print LOGDIR + ":"
                    print ' Unable to create folder for logs. Only logging to console.'

        # Start the logger, silence console logging if we need to
        logger.cherrystrap_log.initLogger(loglevel=LOGLEVEL)

        # Put the cache dir in the data dir for now
        CACHEDIR = os.path.join(DATADIR, 'cache')
        if not os.path.exists(CACHEDIR):
            try:
                os.makedirs(CACHEDIR)
            except OSError:
                logger.error('Could not create cachedir. Check permissions of: ' + DATADIR)

        GIT_EXISTS = os.path.isdir(os.path.join(DATADIR, '.git'))

        # Attempt to find location of git in this environment
        if GIT_EXISTS:
            output = err = None
            cmd = 'which git'
            try:
                logger.debug('Trying to execute: "' + cmd + '" with shell in ' + os.getcwd())
                p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, cwd=os.getcwd())
                output, err = p.communicate()
                output = output.strip()
                logger.debug('Git output: ' + output)
            except OSError:
                logger.debug('Command failed: %s', cmd)

            if not output or 'not found' in output or "not recognized as an internal or external command" in output:
                logger.debug('Unable to find git with command ' + cmd)
                git_enabled = False
                git_path = ''
                git_startup = False
                git_interval = 0
            else:
                git_enabled = True
                git_path = output
                git_startup = True
                git_interval = 12
        else:
                git_enabled = False
                git_path = ''
                git_startup = False
                git_interval = 0

        try:
            HTTP_PORT = check_setting_int(CFG, 'Server', 'httpPort', 7889)
        except:
            HTTP_PORT = 7889

        if HTTP_PORT < 21 or HTTP_PORT > 65535:
            HTTP_PORT = 7889

        APP_NAME = check_setting_str(CFG, 'Server', 'appName', 'CherryStrap')
        HTTP_ROOT = check_setting_str(CFG, 'Server', 'httpRoot', '')
        HTTP_HOST = check_setting_str(CFG, 'Server', 'httpHost', '0.0.0.0')
        HTTPS_ENABLED = check_setting_bool(CFG, 'Server', 'sslEnabled', False)
        HTTPS_KEY = check_setting_str(CFG, 'Server', 'sslKey', 'keys/server.key')
        HTTPS_CERT = check_setting_str(CFG, 'Server', 'sslCert', 'keys/server.crt')
        VERIFY_SSL = check_setting_bool(CFG, 'Server', 'sslVerify', True)
        LAUNCH_BROWSER = check_setting_bool(CFG, 'Server', 'launchBrowser', False)

        HTTP_USER = check_setting_str(CFG, 'Interface', 'httpUser', '')
        HTTP_PASS = check_setting_str(CFG, 'Interface', 'httpPass', '')
        HTTP_LOOK = check_setting_str(CFG, 'Interface', 'httpLook', 'bootstrap')
        API_TOKEN = check_setting_str(CFG, 'Interface', 'apiToken', uuid.uuid4().hex)

        DATABASE_TYPE = check_setting_str(CFG, 'Database', 'dbType', '')
        MYSQL_HOST = check_setting_str(CFG, 'Database', 'mysqlHost', 'localhost')
        MYSQL_PORT = check_setting_int(CFG, 'Database', 'mysqlPort', 3306)
        MYSQL_USER = check_setting_str(CFG, 'Database', 'mysqlUser', '')
        MYSQL_PASS = check_setting_str(CFG, 'Database', 'mysqlPass', '')

        GIT_ENABLED = check_setting_bool(CFG, 'Git', 'gitEnabled', git_enabled)
        GIT_PATH = check_setting_str(CFG, 'Git', 'gitPath', git_path)
        GIT_USER = check_setting_str(CFG, 'Git', 'gitUser', 'theguardian')
        GIT_REPO = check_setting_str(CFG, 'Git', 'gitRepo', 'CherryStrap')
        GIT_BRANCH = check_setting_str(CFG, 'Git', 'gitBranch', 'master')
        GIT_UPSTREAM = check_setting_str(CFG, 'Git', 'gitUpstream', '')
        GIT_LOCAL = check_setting_str(CFG, 'Git', 'gitLocal', '')
        GIT_STARTUP = check_setting_bool(CFG, 'Git', 'gitStartup', git_startup)
        GIT_INTERVAL = check_setting_int(CFG, 'Git', 'gitInterval', git_interval)
        GIT_OVERRIDE = check_setting_bool(CFG, 'Git', 'gitOverride', False)

        #===============================================================
        # Import a variable definer / checker from your app's __init__.py
        try:
            from jiraappy import injectVarCheck
            injectVarCheck(CFG)
        except Exception, e:
            logger.debug("There was a problem importing application variable definitions: %s" % e)
        #================================================================


        # Initialize the database
        try:
            createDb(DATABASE_TYPE, DATADIR, APP_NAME, MYSQL_HOST, MYSQL_PORT,
                MYSQL_USER, MYSQL_PASS)
        except Exception, e:
            logger.error("Error initializing the database: %s" % e)
Exemplo n.º 14
0
    os.umask(prev and int('077', 8))

    # Make the child a session-leader by detaching from the terminal
    try:
        pid = os.fork() #@UndefinedVariable - only available in UNIX
        if pid != 0:
            sys.exit(0)
    except OSError, e:
        raise RuntimeError("2st fork failed: %s [%d]" % (e.strerror, e.errno))

    dev_null = file('/dev/null', 'r')
    os.dup2(dev_null.fileno(), sys.stdin.fileno())

    if PIDFILE:
        pid = str(os.getpid())
        logger.debug(u"Writing PID " + pid + " to " + str(PIDFILE))
        file(PIDFILE, 'w').write("%s\n" % pid)

def launch_browser(host, port, root):
    if host == '0.0.0.0':
        host = 'localhost'

    if HTTPS_ENABLED:
        protocol = 'https'
    else:
        protocol = 'http'

    try:
        import webbrowser
        webbrowser.open('%s://%s:%i%s' % (protocol, host, port, root))
    except Exception, e:
Exemplo n.º 15
0
                kwargs.pop('gitInterval', 12)
        if 'gitOverride' in kwargs:
            cherrystrap.GIT_OVERRIDE = kwargs.pop('gitOverride',
                                                  False) == 'true'
        elif 'gitOverrideHidden' in kwargs:
            cherrystrap.GIT_OVERRIDE = kwargs.pop('gitOverrideHidden',
                                                  False) == 'true'

        #===============================================================
        # Import a variable injector from your app's __init__.py
        try:
            from jiraappy import injectApiConfigPut
            kwargs, errorList = injectApiConfigPut(kwargs, errorList)
        except Exception, e:
            logger.debug(
                "There was a problem injection application variables into API-PUT: %s"
                % e)
        #================================================================

        if len(kwargs) != 0:
            for key, value in kwargs.items():
                errorList.append("Key %s not expected" % key)

        cherrystrap.config_write()
        if not errorList:
            logger.info("All configuration settings successfully updated")
            return "{\"status\": \"success\", \
                \"message\": \"All configuration settings successfully updated\"}"

        else:
            logger.warn(