Пример #1
0
def main():
    conf = cli.parse()

    if isinstance(conf.input, file):
        conf.input = file_by_lines(conf.input)
    
    # Columns specified by name require special treatment after we open
    # our input stream.
    by_name = [(i, f) for i, f in enumerate(conf.fields) if isinstance(f, str)]

    if by_name:
        headline = conf.input.next()
        headers  = conf.splitf(headline)
        indexed  = { name: i for i, name in enumerate(headers) }

        for i, name in by_name:
            if name not in indexed:
                raise Exception()

            conf.fields[i] = indexed[name]

        # Push the headline back. Dirty, but not that dirty
        conf.input = itertools.chain([headline], conf.input)

    if not conf.headers:
        conf.input.next()

    if not conf.fields:
        conf.fields = [slice(None)]

    conf.printf(sel(conf.input, conf.fields, conf.splitf))
Пример #2
0
def main(config, *args):
    'start a webhook server for trello'

    app = Flask(__name__)
    app.logger.addHandler(logging.StreamHandler(sys.stdout))

    with app.app_context():
        engine = Engine(config, modules)

    http_server = WSGIServer(('', 5000), app)
    if not http_server.started:
        http_server.start()

    pid = gevent.os.fork()
    if pid == 0:
        _, _, config = cli.parse()
        for name, webhook in list(engine.triggers.items()):
            if getattr(webhook, 'blueprint', None) and getattr(
                    webhook, 'register', None):
                with app.app_context():
                    webhook_url = '/'.join(
                        (config['config'][name]['webhook'], name))
                    webhook.register(webhook_url)

    try:
        http_server._stop_event.wait()
    finally:
        http_server.stop()
Пример #3
0
def main():
    conf = cli.parse()

    if isinstance(conf.input, file):
        conf.input = file_by_lines(conf.input)

    # Columns specified by name require special treatment after we open
    # our input stream.
    by_name = [(i, f) for i, f in enumerate(conf.fields) if isinstance(f, str)]

    if by_name:
        headline = conf.input.next()
        headers = conf.splitf(headline)
        indexed = {name: i for i, name in enumerate(headers)}

        for i, name in by_name:
            if name not in indexed:
                raise Exception()

            conf.fields[i] = indexed[name]

        # Push the headline back. Dirty, but not that dirty
        conf.input = itertools.chain([headline], conf.input)

    if not conf.headers:
        conf.input.next()

    if not conf.fields:
        conf.fields = [slice(None)]

    conf.printf(sel(conf.input, conf.fields, conf.splitf))
Пример #4
0
def process_loop(interfaces):
    context = zmq.Context()
    receiver = context.socket(zmq.PULL)
    cli_sock = context.socket(zmq.REP)
    receiver.bind("ipc://RPL_listeners")
    cli_sock.bind("ipc://RPL_CLI")

    poller = zmq.Poller()
    poller.register(receiver, zmq.POLLIN)
    poller.register(cli_sock, zmq.POLLIN)
    try:
        logger.info("starting message processing loop")

        # no need to send DIS message when the node is a DODAG Root
        # Note that it might not always make sense
        if gv.dodag_cache.is_empty():
            broadcast_dis(interfaces)

        while True:
            socks = dict(poller.poll())

            if receiver in socks and socks[receiver] == zmq.POLLIN:
                message = receiver.recv()
                message = loads(message)
                # this is not a self message
                if not gv.address_cache.is_assigned(message.src):
                    # do some real processing on message
                    handleMessage(interfaces, message)

                del message

            if cli_sock in socks and socks[cli_sock] == zmq.POLLIN:
                command = cli_sock.recv()
                cli.parse(cli_sock, command)

                del command

    except KeyboardInterrupt:
        global dis_timer

        try:
            dis_timer.cancel()
        except AttributeError:
            pass
Пример #5
0
def process_loop(interfaces):
    context = zmq.Context()
    receiver = context.socket(zmq.PULL)
    cli_sock = context.socket(zmq.REP)
    receiver.bind("ipc://RPL_listeners")
    cli_sock.bind("ipc://RPL_CLI")

    poller = zmq.Poller()
    poller.register(receiver, zmq.POLLIN)
    poller.register(cli_sock, zmq.POLLIN)
    try:
        logger.info("starting message processing loop")

        # no need to send DIS message when the node is a DODAG Root
        # Note that it might not always make sense
        if gv.dodag_cache.is_empty():
            broadcast_dis(interfaces)

        while True:
            socks = dict(poller.poll())

            if receiver in socks and socks[receiver] == zmq.POLLIN:
                message = receiver.recv()
                message = loads(message)
                # this is not a self message
                if not gv.address_cache.is_assigned(message.src):
                    # do some real processing on message
                    handleMessage(interfaces, message)

                del message

            if cli_sock in socks and socks[cli_sock] == zmq.POLLIN:
                command = cli_sock.recv()
                cli.parse(cli_sock, command)

                del command

    except KeyboardInterrupt:
        global dis_timer

        try:
            dis_timer.cancel()
        except AttributeError:
            pass
Пример #6
0
def do(t):
	p = parse(t)
	#or,
	if (len(p) > 1):
		for i,r in enumerate(p):
			print (i, ":", r)
			print(r.tostr())
		print( "we couldnt prove that our grammar isnt ambiguous, but we can tell that your program is!")
	else:

		for i,r in enumerate(p):
			print (i, ":", r)
			print(r.tostr())
			r = r.unparen()
		
			#type-check it before evaluating:
			print("type check:",r.type_check().tostr())
			print("eval:",r.eval().tostr())
			#what do we do up here is it like while(r.prove()) ?
			#but if it also has returns it will screw it up
			for x in r.prove():
				print("prove:",x.tostr())
Пример #7
0
            
    return contour

if __name__ == '__main__':
    # Values and helpers
    class Modes(object):
       __metaclass__ = ancillary.Enum
       __elements__ = cli.command_list
    
    def error(msg):
        print "Error: %s" % msg
        sys.exit(1)
        
    # Parse command line
    try:
        mode, _ = cli.parse(sys.argv[1:])
    except cli.CommandParsingError, e:
        cli.error(e)
            
    # No command given
    if mode is None:
        cli.error("must specify command")
        
    # Trace contour of the old world
    if mode == Modes.trace:
        print "Getting existing world contour..."
        contour = get_contour(cli.contour_reset)
        
        print "Tracing world contour..."
        try:
            contour.trace_combine(cli.world_dir, cli.contour_combine, cli.merge_types, cli.contour_select, cli.contour_join)
Пример #8
0
# 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.

import cli
import time
import logging, logging.handlers
import sysinfo

logFile = 'error.log'  #send this somewhere else for production (/tmp/?)
loglevel = cli.parse()

#TODO: Fix logging.  For now the following code puts log on the console:
#~ self.log = logging.getLogger(__name__)
#~ self.log.setLevel(logging.DEBUG)
#~ ch = logging.StreamHandler()
#~ ch.setLevel(logging.DEBUG)
#~ formatter = logging.Formatter('[%(asctime)s] %(module)-6s  [%(levelname)-8s]  %(message)s')
#~ ch.setFormatter(formatter)
#~ self.log.addHandler(ch)

#set up local file logging
logging.basicConfig(filename=logFile, filemode='a',
    format='[%(asctime)s] %(module)-6s  [%(levelname)-8s]  %(message)s',
    level=getattr(logging, loglevel.upper()))
Пример #9
0
import cli
import ci_decisiontrees
import K_ano_Census
import K_ano_Titan
import census_correlated
import titanic_correlated
import Census_Eval_NN
import Titanic_Eval_NN
import Census_Eval_NN_Synth
import Titanic_Eval_NN_Synth

data, model, anonimity, param, k_values, do_ano = cli.parse()
print('parsed')

if data == 'census':
    # anonymization part will be done here
    if anonimity == 'gen':
        if do_ano == 'yes':
            for i in range(len(k_values)):
                K_ano_Census.K_ano_Census_func(int(k_values[i]))
    elif anonimity == 'synth':
        if do_ano == 'yes':
            census_correlated.synthetize()
    else:
        print('no more anonymization methods implemented')

    ########################################
    if model == 'decisiontree':
        #ci_decisiontrees.rest()
        # call method that does training and evaluation based on parsed parameters
        print('not implemented')
Пример #10
0
            stat    = os.stat(sqlpath)
            size    = stat.st_size
            logger.debug("Size: %s b" % size)
            ctime   = int(stat.st_ctime)
            logger.debug("Last metadata changed: %s sec since epoch" % ctime)
            if sqlctime != ctime:
                logger.warn("File %s in the database has different ctime. Deleting db/real -> %s/%s" % (sqlpath,sqlctime,ctime))
                sqlobj.execute("DELETE FROM SND WHERE ID=%s" % (sqlid,))
            if sqlsize != size:
                logger.warn("File %s in the database has different size. Deleting db/real -> %s/%s" % (sqlpath,sqlsize,size))
                sqlobj.execute("DELETE FROM SND WHERE ID=%s" % (sqlid,))
    usermsg.done()
    usermsg.reset()

if __name__ == "__main__":
    options,arguments = parse(version)
    ### LOG DEF ####################################################################
    loglvl = 40 - options.verbose*10
    if loglvl <= 0: loglvl = 1
    logger = logging.getLogger(program_name)
    logger.setLevel(loglvl)
    ch = logging.StreamHandler()
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    ch.setFormatter(formatter)
    ch.setLevel(loglvl)
    logger.addHandler(ch)
    ################################################################################

    usermsg = UserMsg()
    logger.debug("optparse options: %s" % options)
    logger.debug("optparse arguments: %s" % arguments)