Пример #1
0
def simple_main(createOptionParserFn, createCommandFn, mainOptions=None):
    """
     createOptionParserFn : a function that takes no arguments and returns an OptParser
     createCommandFn : a function that takes two argument (the options and the args (those that are not processed into
                       options) and returns an object that has "run" and "cleanup" functions.  Its "run" function must
                       run and return an exit code.  "cleanup" will be called to clean up before the program exits;
                       this can be used to clean up, for example, to clean up a worker pool

     mainOptions can include: forceQuietOutput (map to bool),
                              programNameOverride (map to string)
                              suppressStartupLogMessage (map to bool)
                              useHelperToolLogging (map to bool)
                              setNonuserOnToolLogger (map to bool, defaults to false)
                              pidfilename (string)
                              parentpidvar (string)

    """
    coverage = GpCoverage()
    coverage.start()
    try:
        simple_main_internal(createOptionParserFn, createCommandFn,
                             mainOptions)
    finally:
        coverage.stop()
        coverage.generate_report()
Пример #2
0
def simple_main(createOptionParserFn, createCommandFn, mainOptions=None):
    """
     createOptionParserFn : a function that takes no arguments and returns an OptParser
     createCommandFn : a function that takes two argument (the options and the args (those that are not processed into
                       options) and returns an object that has "run" and "cleanup" functions.  Its "run" function must
                       run and return an exit code.  "cleanup" will be called to clean up before the program exits;
                       this can be used to clean up, for example, to clean up a worker pool

     mainOptions can include: forceQuietOutput (map to bool),
                              programNameOverride (map to string)
                              suppressStartupLogMessage (map to bool)
                              useHelperToolLogging (map to bool)
                              setNonuserOnToolLogger (map to bool, defaults to false)
                              pidfilename (string)
                              parentpidvar (string)

    """
    coverage = GpCoverage()
    coverage.start()
    try:
        simple_main_internal(createOptionParserFn, createCommandFn, mainOptions)
    finally:
        coverage.stop()
        coverage.generate_report()
    analyze_tables(table_list[::-1], options.dbname, options.nthreads, dburl,
                   options.stat_mem)
    logger.info('=== Analysis complete ===')


def store_results_to_fs(q, location, dbname, filenam):
    result_file = open(dbname + "_" + filenam + ".csv", 'w+')
    while not q.empty():
        result_file.write(q.get() + "\n")
    result_file.close()


#------------------------------- Mainline --------------------------------

#Initialization
coverage = GpCoverage()
coverage.start()
logger = get_default_logger()
res_queue = Queue()
err_queue = Queue()
#Parse input parameters and check for validity
options = parseargs()

#Print the partition list
orchestrator(options)

store_results_to_fs(res_queue, options.location, options.dbname,
                    options.filename)
#while not res_queue.empty():
#print res_queue.get()
Пример #4
0
# Line too long - pylint: disable=C0301
# Invalid name  - pylint: disable=C0103
"""
mainUtils.py
------------

This file provides a rudimentary framework to support top-level option
parsing, initialization and cleanup logic common to multiple programs.

It also implements workarounds to make other modules we use like
GpCoverage() work properly.

The primary interface function is 'simple_main'.  For an example of
how it is expected to be used, see gprecoverseg.

It is anticipated that the functionality of this file will grow as we
extend common functions of our gp utilities.  Please keep this in mind
and try to avoid placing logic for a specific utility here.
"""

import os, sys, signal, errno, yaml

gProgramName = os.path.split(sys.argv[0])[-1]
if sys.version_info < (2, 5, 0):
    sys.exit('''Error: %s is supported on Python versions 2.5 or greater
Please upgrade python installed on this machine.''' % gProgramName)

from gppylib import gplog
from gppylib.commands import gp, unix
from gppylib.commands.base import ExecutionError
from gppylib.system import configurationInterface, configurationImplGpdb, fileSystemInterface, \
Пример #5
0
sys.stdout = NullDevice()

# log initialization must be done only AFTER rerouting stdout
from gppylib import gplog
from gppylib.mainUtils import getProgramName
from gppylib.commands import unix
hostname = unix.getLocalHostname()
username = unix.getUserName()
execname = pickle.load(sys.stdin)
gplog.setup_tool_logging(execname, hostname, username)
logger = gplog.get_default_logger()

operation = pickle.load(sys.stdin)

from gppylib.gpcoverage import GpCoverage
coverage = GpCoverage()
coverage.start()

try:
    ret = operation.run()
except Exception, e:
    exc_type, exc_value, exc_traceback = sys.exc_info()
    tb_list = traceback.extract_tb(exc_traceback)
    try:
        # TODO: Build an ExceptionCapsule that can return the traceback
        # to RemoteOperation as well. See Pyro.

        # logger.exception(e)               # logging 'e' could be necessary for traceback

        pickled_ret = pickle.dumps(e)       # Pickle exception for stdout transmission
    except Exception, f: