Esempio n. 1
0
# load weights
print("\n\n---- Loading AI model\n\n")
model.load_weights(str(MODEL_OUTPUT + MODEL_NAME + '.h5'))

# Generate poem
while True:
    try:
        seed = input('How do you want to start the poem?\n\n')
        # create poem
        print("\n\n---- Creative moment - I'm thinking ...")
        print('\n\n\nWriting poem ... \n\n')
        poem = write_poem(seed,
                          model,
                          n_to_char,
                          char_to_n,
                          max_seq=MAX_SEQ,
                          max_words=MAX_WORDS,
                          creativity=CREATIVITY)
        # write poem as .txt in putpus
        filename = valid_name(poem.split('\n')[0])
        with open(PATH_POEMS + filename + '.txt', "w") as text_file:
            text_file.write(poem)
        # another poem?
        repeat = input('Do you want another poem? (Y/N) ')
        if repeat.lower() == 'n':
            print("Bye")
            break
    except KeyboardInterrupt:
        print("Bye")
        break
Esempio n. 2
0
def import_single_build(json_obj, db_options, base_path=utils.BASE_PATH):
    """Import a single build from the file system.

    :param json_obj: The json object containing the necessary data.
    :type json_obj: dictionary
    :param db_options: The database connection options.
    :type db_options: dictionary
    :param base_path: The base path on the file system where to look for.
    :type base_path: string
    :return The defconfig ID, the job ID and the errors data structure.
    """
    errors = {}
    job_id = None
    build_doc = None
    build_id = None
    j_get = json_obj.get

    arch = j_get(models.ARCHITECTURE_KEY)
    job = j_get(models.JOB_KEY)
    kernel = j_get(models.KERNEL_KEY)
    defconfig = j_get(models.DEFCONFIG_KEY)
    git_branch = j_get(models.GIT_BRANCH_KEY)
    build_environment = j_get(models.BUILD_ENVIRONMENT_KEY)
    defconfig_full = j_get(models.DEFCONFIG_FULL_KEY, None)

    if (utils.valid_name(job) and utils.valid_name(kernel)):
        file_server_resource = j_get(models.FILE_SERVER_RESOURCE_KEY)
        build_dir = os.path.join(base_path, file_server_resource)

        if os.path.isdir(build_dir):
            try:
                database = utils.db.get_db_connection(db_options)

                ret_val, job_doc, job_id = _get_or_create_job(
                    job, kernel, git_branch, database, db_options)
                if ret_val != 201 and job_id is None:
                    err_msg = (
                        "Error saving/finding job document '%s-%s-%s' for "
                        "'%s-%s' might not be linked to its job")
                    utils.LOG.error(err_msg, job, kernel, git_branch, arch,
                                    defconfig, build_environment)
                    ERR_ADD(
                        errors, ret_val,
                        err_msg % (job, kernel, git_branch, arch, defconfig,
                                   build_environment))

                build_doc = _traverse_build_dir(build_dir, job_doc, errors,
                                                database)

                ret_val = _update_job_doc(job_doc, job_id, job_doc.status,
                                          build_doc, database)
                if ret_val != 201:
                    err_msg = (
                        "Error updating job document '%s-%s-%s' with values "
                        "from build doc")
                    utils.LOG.error(err_msg, job, git_branch, kernel)
                    ERR_ADD(errors, ret_val,
                            err_msg % (job, git_branch, kernel))
                if build_doc:
                    ret_val, build_id = utils.db.save(database, build_doc)
                if ret_val != 201:
                    err_msg = "Error saving build document '%s-%s-%s-%s-%s-%s'"
                    utils.LOG.error(err_msg, job, git_branch, kernel, arch,
                                    defconfig, build_environment)
                    ERR_ADD(
                        errors, ret_val,
                        err_msg % (job, git_branch, kernel, arch, defconfig,
                                   build_environment))
            except pymongo.errors.ConnectionFailure, ex:
                utils.LOG.exception(ex)
                utils.LOG.error("Error getting database connection")
                utils.LOG.warn(
                    "Build for '%s-%s-%s-%s-%s-%s' will not be imported", job,
                    git_branch, kernel, arch, defconfig, build_environment)
                ERR_ADD(
                    errors, 500,
                    "Internal server error: build for '%s-%s-%s-%s-%s-%s' "
                    "will not be imported" % (job, git_branch, kernel, arch,
                                              defconfig, build_environment))
        else:
            err_msg = ("No build directory found for '%s-%s-%s-%s-%s-%s': "
                       "has everything been uploaded?")
            utils.LOG.error(err_msg, job, git_branch, kernel, arch, defconfig,
                            build_environment)
            ERR_ADD(
                errors, 500, err_msg %
                (job, git_branch, kernel, arch, defconfig, build_environment))
Esempio n. 3
0
def import_single_build(json_obj, db_options, base_path=utils.BASE_PATH):
    """Import a single build from the file system.

    :param json_obj: The json object containing the necessary data.
    :type json_obj: dictionary
    :param db_options: The database connection options.
    :type db_options: dictionary
    :param base_path: The base path on the file system where to look for.
    :type base_path: string
    :return The defconfig ID, the job ID and the errors data structure.
    """
    errors = {}
    job_id = None
    build_doc = None
    build_id = None
    j_get = json_obj.get

    arch = j_get(models.ARCHITECTURE_KEY)
    job = j_get(models.JOB_KEY)
    kernel = j_get(models.KERNEL_KEY)
    defconfig = j_get(models.DEFCONFIG_KEY)
    git_branch = j_get(models.GIT_BRANCH_KEY)
    build_environment = j_get(models.BUILD_ENVIRONMENT_KEY)
    defconfig_full = j_get(models.DEFCONFIG_FULL_KEY, None)

    # Clean up the branch name so we don't have "local/*" anymore.
    git_branch = utils.clean_branch_name(git_branch)

    if (utils.valid_name(job) and utils.valid_name(kernel)):
        # New directory structure:
        # $job/$branch/$kernel/$arch/$defconfig/$environment

        parent_dir = os.path.join(base_path, job, git_branch, kernel, arch)
        build_dir = os.path.join(
            parent_dir, defconfig_full or defconfig, build_environment)

        if os.path.isdir(build_dir):
            try:
                database = utils.db.get_db_connection(db_options)

                ret_val, job_doc, job_id = _get_or_create_job(
                    job, kernel, git_branch, database, db_options)
                if ret_val != 201 and job_id is None:
                    err_msg = (
                        "Error saving/finding job document '%s-%s-%s' for "
                        "'%s-%s' might not be linked to its job")
                    utils.LOG.error(
                        err_msg, job, kernel, git_branch, arch, defconfig,
                        build_environment)
                    ERR_ADD(
                        errors,
                        ret_val,
                        err_msg % (job, kernel, git_branch, arch, defconfig,
                                   build_environment)
                    )

                build_doc = _traverse_build_dir(
                    build_dir, job_doc, errors, database)

                ret_val = _update_job_doc(
                    job_doc,
                    job_id, job_doc.status, build_doc, database)
                if ret_val != 201:
                    err_msg = (
                        "Error updating job document '%s-%s-%s' with values "
                        "from build doc")
                    utils.LOG.error(err_msg, job, git_branch, kernel)
                    ERR_ADD(
                        errors, ret_val, err_msg % (job, git_branch, kernel))
                if build_doc:
                    ret_val, build_id = utils.db.save(
                        database, build_doc, manipulate=True)
                if ret_val != 201:
                    err_msg = "Error saving build document '%s-%s-%s-%s-%s-%s'"
                    utils.LOG.error(
                        err_msg, job, git_branch, kernel, arch, defconfig,
                        build_environment)
                    ERR_ADD(
                        errors,
                        ret_val, err_msg % (
                            job, git_branch, kernel, arch, defconfig))
            except pymongo.errors.ConnectionFailure, ex:
                utils.LOG.exception(ex)
                utils.LOG.error("Error getting database connection")
                utils.LOG.warn(
                    "Build for '%s-%s-%s-%s-%s-%s' will not be imported",
                    job, git_branch, kernel, arch, defconfig,
                    build_environment)
                ERR_ADD(
                    errors, 500,
                    "Internal server error: build for '%s-%s-%s-%s-%s-%s' "
                    "will not be imported" % (
                        job, git_branch, kernel, arch, defconfig,
                        build_environment)
                )
        else:
            err_msg = (
                "No build directory found for '%s-%s-%s-%s-%s-%s': "
                "has everything been uploaded?")
            utils.LOG.error(
                err_msg, job, git_branch, kernel, arch, defconfig,
                build_environment)
            ERR_ADD(errors, 500, err_msg % (
                job, git_branch, kernel, arch, defconfig, build_environment))
Esempio n. 4
0
    def test_valid_name(self):
        self.assertTrue(utils.valid_name("foo"))
        self.assertTrue(utils.valid_name("foo.bar"))
        self.assertTrue(utils.valid_name("foo+bar"))
        self.assertTrue(utils.valid_name("foo-bar"))
        self.assertTrue(utils.valid_name("foo_bar"))
        self.assertTrue(utils.valid_name("foo=bar"))

        self.assertFalse(utils.valid_name("foo*bar"))
        self.assertFalse(utils.valid_name("foo'bar"))
        self.assertFalse(utils.valid_name("foo\"bar"))
        self.assertFalse(utils.valid_name("foo~bar"))
        self.assertFalse(utils.valid_name("[foobar"))
        self.assertFalse(utils.valid_name("foobar]"))
        self.assertFalse(utils.valid_name("{foobar"))
        self.assertFalse(utils.valid_name("~foobar"))
        self.assertFalse(utils.valid_name("foobar~"))
        self.assertFalse(utils.valid_name("foo?bar"))
        self.assertFalse(utils.valid_name("foo/bar"))
        self.assertFalse(utils.valid_name(".foo/bar"))
        self.assertFalse(utils.valid_name("$foobar"))
        self.assertFalse(utils.valid_name("foo$bar"))
Esempio n. 5
0
    def post(self):
		if self.request.get('login_email') and self.request.get('login_password'):
			user_email = self.request.get('login_email')
			user_psswrd = self.request.get('login_password')

			print user_email

			valid_pwd = False
			valid_email = False

			q = mydb.User.get_by_email(user_email)
			if not(q is None):
				valid_email = True
				valid_pwd = utils.valid_pw(user_email, user_psswrd, q.password_hash)

				if valid_pwd and valid_email:
					self.response.headers.add_header('Set-Cookie', "user_id=%s;Path=/" % utils.make_secure_val(str(q.key().id())))
					self.redirect('/hello')
				else:
					self.render_signup(email=cgi.escape(user_email), login_err="Invalid username or password. Please sign up or try again.")
		else:
			user_email = self.request.get('email')
			user_psswrd = self.request.get('password')
			user_first_name = self.request.get('first_name')
			user_last_name = self.request.get('last_name')
			user_dob = self.request.get('dob')
			user_gender = self.request.get('gender')
			user_occupation = self.request.get('occupation')
			user_confirmation = self.request.get('confirmation')

			print user_email
			print user_psswrd
			print user_first_name
			print user_last_name
			print utils.convert_dob(user_dob)
			print user_gender
			print user_occupation
			print user_confirmation

			name = utils.valid_name(user_first_name) and utils.valid_name(user_last_name)
			user_ex = utils.user_exists(user_email)
			psswrd = utils.valid_psswrd(user_psswrd)
			email = utils.valid_email(user_email)

			# this will store the values to be returned
			#ret = {"uname":cgi.escape(user_uname), "uname_err":"", "psswrd_err":"", "verify_err":"", "email":cgi.escape(user_email), "email_err":""}

			if not name or user_ex or not psswrd or not email:
				input_err = "Some input was incorrect. Further details to come soon."
			if not(name and not user_ex and psswrd and email):
				self.render_signup(first_name=first_name,
				login_err=login_err,
				input_err=input_err,
				email=email,
				last_name=last_name,
				gender=gender,
				occupation=occupation)
			else:
				password_hash = utils.make_pw_hash(user_email, user_psswrd)
				user = mydb.User(first_name=user_first_name, last_name=user_last_name, dob=utils.convert_dob(user_dob), gender=user_gender, occupation=user_occupation, password_hash=password_hash, salt=password_hash.split('|')[1], email=user_email)
				user.put()
				print "added new user %s" % user.email
				#mydb.allusers(True, user)
				time.sleep(0.2)
				self.response.headers.add_header('Set-Cookie', "user_id=%s;Path=/" % utils.make_secure_val(str(user.key().id())))
				self.redirect('/hello')
Esempio n. 6
0
    def test_valid_name(self):
        self.assertTrue(utils.valid_name("foo"))
        self.assertTrue(utils.valid_name("foo.bar"))
        self.assertTrue(utils.valid_name("foo+bar"))
        self.assertTrue(utils.valid_name("foo-bar"))
        self.assertTrue(utils.valid_name("foo_bar"))
        self.assertTrue(utils.valid_name("foo=bar"))

        self.assertFalse(utils.valid_name("foo*bar"))
        self.assertFalse(utils.valid_name("foo'bar"))
        self.assertFalse(utils.valid_name("foo\"bar"))
        self.assertFalse(utils.valid_name("foo~bar"))
        self.assertFalse(utils.valid_name("[foobar"))
        self.assertFalse(utils.valid_name("foobar]"))
        self.assertFalse(utils.valid_name("{foobar"))
        self.assertFalse(utils.valid_name("~foobar"))
        self.assertFalse(utils.valid_name("foobar~"))
        self.assertFalse(utils.valid_name("foo?bar"))
        self.assertFalse(utils.valid_name("foo/bar"))
        self.assertFalse(utils.valid_name(".foo/bar"))
        self.assertFalse(utils.valid_name("$foobar"))
        self.assertFalse(utils.valid_name("foo$bar"))