예제 #1
0
 def setUp(self):
     creator.create("FitnessMax", base.Fitness, weights=(1.0,))
     creator.create("IndList", list, fitness=creator.FitnessMax)
     creator.create("IndArray", array.array, typecode="f", fitness=creator.FitnessMax)
     creator.create("IndTree", gp.PrimitiveTree, fitness=creator.FitnessMax)
     self.toolbox = base.Toolbox()
     self.toolbox.register("func", func)
     self.toolbox.register("lambda_func", lambda: "True")
예제 #2
0
 def setUp(self):
     creator.create("FitnessMax", base.Fitness, weights=(1.0, ))
     creator.create("IndList", list, fitness=creator.FitnessMax)
     creator.create("IndArray", array.array, fitness=creator.FitnessMax)
     creator.create("IndTree", base.Tree, fitness=creator.FitnessMax)
     self.toolbox = toolbox.Toolbox()
     self.toolbox.register("func", func)
     self.toolbox.register("lambda_func", lambda: "True")
예제 #3
0
def main():
    # Get arguments
    args = get_args()

    if args.isGUI is True:
        print("--------------")
        # allow overwrite of parameters by zmq
        gsettings.modify_settings_by_gui()

    # parse doxygen class xml
    [classList] = creator.create()

    # Start Jinja for the parsed class
    for cl in classList:
        # TODO: after knowing the best conventions for templating,
        # 		IF POSSIBLE, unify it and move template printing out of the switch for languages

        lang = settings.OUTPUT_LANGUAGE

        if (lang == Language.PYTHON_SIMPLE):
            presenter = ClassyPresenter(cl)
            template_process.print_to_template_simple(
                settings.OUTPUT_DIR + cl.name + ".py", presenter)

        elif (lang == Language.PYTHON):
            presenter = Classy2Presenter(cl)
            template_process.print_to_template(
                settings.OUTPUT_DIR + cl.name + ".py", presenter)
예제 #4
0
def create_cmp(env, headers):
    cookies = _get_cookies(env)
    user_id = auth.is_logined(cookies)
    if user_id is not None:
        if auth.is_op(user_id):
            post_data = _get_post_data(env)
            checks = ('title' in post_data) and ('description' in post_data)
            if checks and ('qnumber' in post_data):
                title = common.escape(post_data['title'][0])
                description = common.escape(post_data['description'][0])
                qnumber = int(common.escape(post_data['qnumber'][0]))
                format_q = 'question-{}'
                format_a = 'answer-{}'
                tasks = []
                for i in range(qnumber):
                    question_tpl = format_q.format(i)
                    answer_tpl = format_a.format(i)
                    if (answer_tpl in post_data) and (question_tpl in post_data):
                        q = post_data[question_tpl][0]
                        a = post_data[answer_tpl][0]
                        answers = common.escape(a).split('##')
                        answers = [j for j in answers if j]
                        tasks.append(
                            tuple(
                                [common.escape(q)] + answers
                            ))
                username = db.username_by_id(user_id)
                creator.create(title, description, username, tuple(tasks))
                headers.append(('Location', '/dashboard'))
        else:
            err_msg = "User ID {} tried to create cmp without op"
            err_msg = err_msg.format(str(user_id))
            common.dbg_log(err_msg)
            em = '403: You don\'t have permissions to create competition'
            return (ui.error_page({'error_msg': em}), '403 Forbidden')
    else:
        headers.append(('Location', '/'))
    return ''
예제 #5
0
import boto3, json, time
from mail import send_email
from uuid import uuid4
from creator import create

s3 = boto3.resource('s3')
def upload_s3(source_file, filename):
  bucket_name = '191621'
  destination_filename = "albums/%s/%s" % (uuid4().hex, filename)
  print destination_filename
  bucket = s3.Bucket(bucket_name)
  bucket.put_object(Key=destination_filename, Body=source_file, ACL='public-read')
  return destination_filename

sqs = boto3.resource('sqs')
albumRequests = sqs.get_queue_by_name(QueueName='tomek-album')
bucket_address = 'https://s3.eu-central-1.amazonaws.com/191621'

while True:
  for albumRequest in albumRequests.receive_messages():
    print('processing request ..........')
    albumData = json.loads(albumRequest.body)
    pdf = create(albumData)
    dest = upload_s3(pdf.getvalue(), 'album.pdf')
    send_email(albumData['sent_to'], 'Your album', 'download here: %s/%s' % (
    bucket_address, dest))
    albumRequest.delete()
    print('request processing finished [X]')
  time.sleep(1)
예제 #6
0
from creator import create
s3 = boto3.resource('s3')


def upload_s3(source_file, filename):
    bucket_name = '167762-pexy'
    destination_filename = "albums/%s/%s" % (uuid4().hex, filename)
    print destination_filename
    bucket = s3.Bucket(bucket_name)
    bucket.put_object(Key=destination_filename,
                      Body=source_file,
                      ACL='public-read')
    return destination_filename


sqs = boto3.resource('sqs')
albumRequests = sqs.get_queue_by_name(QueueName='pexy-album')
bucket_address = 'https://s3.eu-central-1.amazonaws.com/167762-pexy'

while True:
    for albumRequest in albumRequests.receive_messages():
        print('in progress ...')
        albumData = json.loads(albumRequest.body)
        pdf = create(albumData)
        dest = upload_s3(pdf.getvalue(), 'album.pdf')
        send_email(albumData['sent_to'], 'Album',
                   'download here: %s/%s' % (bucket_address, dest))
        albumRequest.delete()
        print('request processing finished [X]')
    time.sleep(1)
예제 #7
0
def main():
    # Get arguments
    args = get_args()

    parentPID = os.getppid()

    print parentPID

    fh = open("parentPID.txt", "w")
    fh.write(str(parentPID))
    fh.close()

    if args.isGUI is True:
        print "--------------"
        socket = interpc.open_and_get_socket()
        # allow overwrite of parameters by zmq
        # gsettings.modify_settings_by_gui(socket)

    # parse doxygen class xml
    [pyFileList] = creator.create()

    # Create output dir if not found
    f = open(settings.LOG_FILE, "w")
    f.write("Started logging\n")
    if args.isGUI is True:
        index = -1

        # won't work, we need the grandparent, or better, get it in a zmq message
        # while(check_pid(parentPID)):
        # 	socket.RCVTIMEO = 1000

        # 	socket.recv()

        # 	if (msg == "init_req_pyfile"):
        # 		[pyFileList] = creator.create()

        # 		for pyFile in pyFileList:
        # 			index = index + 1
        # 			# receive before each sending
        # 			msg = socket.recv()
        # 			f.write("Received message: " + msg + " through zmq.\n")

        # 			if (msg == "init_req_pyfile") or (msg == "req_pyfile"):
        # 				gfunctions.provide_pyfile(socket, pyFile)

        # 			else:
        # 				socket.send("Sent message wasn't expected")

        # 		# receive before each sending
        # 		msg = socket.recv()
        # 		if (msg == "init_req_pyfile") or (msg == "req_pyfile"):
        # 			f.write("Sending closure message\n")
        # 			gfunctions.provide_pyfile_are_over(socket)

        # 		f.close()
        # 		socket.close()

        for pyFile in pyFileList:
            index = index + 1
            # receive before each sending
            msg = socket.recv()
            f.write("Received message: " + msg + " through zmq.\n")

            if (msg == "init_req_pyfile") or (msg == "req_pyfile"):
                gfunctions.provide_pyfile(socket, pyFile)

            else:
                socket.send("Sent message wasn't expected")

        # receive before each sending
        msg = socket.recv()
        if (msg == "init_req_pyfile") or (msg == "req_pyfile"):
            f.write("Sending closure message\n")
            gfunctions.provide_pyfile_are_over(socket)

        f.close()
        socket.close()

    else:
        print "Run with --isGUI=true!"
예제 #8
0
파일: main.py 프로젝트: vipmath/pyrite
      sys.exit(1)
    elif o == '--test':
      arg_hash['in_dir'] = os.path.join( 
          file_util.get_module_dir(), "test_files")
      arg_hash['out_dir'] = os.path.join(
          file_util.get_module_dir(), "test_files", "pyrite_blog")
      arg_hash['test'] = True
    elif o == "--stress":
      arg_hash['in_dir'] = "stress_files"
      arg_hash['out_dir'] = "stress_files/test_blog_dir"
    elif o == "--clean_init":
      arg_hash['clean_init'] = True
    elif o == '-o':
      arg_hash['out_dir'] = v
    elif o == '-c' or o == '--clean':
      arg_hash['clean'] = True
    elif o == '-v' or o == '--version':
      print 'Pyrite Version %s' % __init__.__version__ 
      sys.exit(0)
    else:
      assert False, 'Unknown option'  + o

  creator.create(arg_hash)

def display_help():
  print "Usage: <dirname> <opts>"

# Execut the main func
if __name__ == "__main__":
  main()