コード例 #1
0
def download_frappe_assets(verbose=True):
    """Downloads and sets up Frappe assets if they exist based on the current
	commit HEAD.
	Returns True if correctly setup else returns False.
	"""
    from simple_chalk import green
    from subprocess import getoutput
    from tempfile import mkdtemp

    assets_setup = False
    frappe_head = getoutput("cd ../apps/frappe && git rev-parse HEAD")

    if frappe_head:
        try:
            url = get_assets_link(frappe_head)
            click.secho("Retrieving assets...", fg="yellow")
            prefix = mkdtemp(prefix="frappe-assets-", suffix=frappe_head)
            assets_archive = download_file(url, prefix)
            print("\n{0} Downloaded Frappe assets from {1}".format(
                green('✔'), url))

            if assets_archive:
                import tarfile
                directories_created = set()

                click.secho("\nExtracting assets...\n", fg="yellow")
                with tarfile.open(assets_archive) as tar:
                    for file in tar:
                        if not file.isdir():
                            dest = "." + file.name.replace(
                                "./frappe-bench/sites", "")
                            asset_directory = os.path.dirname(dest)
                            show = dest.replace("./assets/", "")

                            if asset_directory not in directories_created:
                                if not os.path.exists(asset_directory):
                                    os.makedirs(asset_directory, exist_ok=True)
                                directories_created.add(asset_directory)

                            tar.makefile(file, dest)
                            print("{0} Restored {1}".format(green('✔'), show))

                build_missing_files()
                return True
            else:
                raise
        except Exception:
            # TODO: log traceback in bench.log
            click.secho("An Error occurred while downloading assets...",
                        fg="red")
            assets_setup = False
        finally:
            try:
                shutil.rmtree(os.path.dirname(assets_archive))
            except Exception:
                pass

    return assets_setup
コード例 #2
0
def main():
    print(">> welcome to this repetition analyzer")
    song_name = input(">> what song would you like to visualize?\n")
    print(">> loading required credentials")
    client_access_code, client_secure_code, client_auth_token = loadCredentials()
    print(">> searching through " + chalk.yellow("Genius"))
    path, name = searchSong(song_name, client_auth_token)
    print(">> match found -> \033[0;32m" + name + "\033[0m")
    print(">> scraping lyrics and removing common words")
    lyrics = getLyrics(path, client_auth_token)
    print(">> creating the self-similarity matrix")
    lyrics_list = re.split("\n| (|) | |, | ,", lyrics)
    temp_list = []
    for item in lyrics_list:
        if item != None and item != '':
            temp_list.append(item)
    lyrics_list = temp_list
    matrix = lin_alg.zeros((len(lyrics_list), len(lyrics_list)))

    ppmfile = open("repetition-matrix.ppm", 'w+')  # note the binary flag
    ppmfile.write("%s\n" % ('P3'))
    ppmfile.write("%d %d\n" % (len(lyrics_list), len(lyrics_list)))
    ppmfile.write("255\n")

    print(">> creating " + chalk.blue("repetition-matrix.ppm") + " file")
    out = 0
    ins = 0
    while out < len(lyrics_list):
        while ins < len(lyrics_list):
            if(lyrics_list[out] == lyrics_list[ins]):
                ppmfile.write("178 34 34 ")
                matrix[out, ins] = 1
                matrix[ins, out] = 1
            else:
                ppmfile.write("225 225 225 ")

            ins = ins+1
        ins = 0
        out = out+1
    ppmfile.seek(0, 2)
    size = ppmfile.tell()
    ppmfile.truncate(size - 1)
    ppmfile.seek(0, 2)
    ppmfile.write("\n")
    print(">> " + chalk.green("complete"))
コード例 #3
0
ファイル: build.py プロジェクト: DAP-official-com/frappe
def setup_assets(assets_archive):
    import tarfile
    directories_created = set()

    click.secho("\nExtracting assets...\n", fg="yellow")
    with tarfile.open(assets_archive) as tar:
        for file in tar:
            if not file.isdir():
                dest = "." + file.name.replace("./frappe-bench/sites", "")
                asset_directory = os.path.dirname(dest)
                show = dest.replace("./assets/", "")

                if asset_directory not in directories_created:
                    if not os.path.exists(asset_directory):
                        os.makedirs(asset_directory, exist_ok=True)
                    directories_created.add(asset_directory)

                tar.makefile(file, dest)
                print("{0} Restored {1}".format(green('✔'), show))

    return directories_created
コード例 #4
0
# ------- #

from difflib import Differ
from pretty_simple_namespace import format
from pretty_simple_namespace.fns import forEach, joinWith, map_, passThrough
from simple_chalk import green, red, yellowBright
from .input import input
from .expected import expected as allExpected

# ---- #
# Init #
# ---- #

_d = Differ()
x = red("✘")
o = green("✔")
greenPlus = green("+")
redMinus = red("-")

# ---- #
# Main #
# ---- #


def runTests(r):
    def testCase(formatInput, case):
        actual = format(formatInput)
        expected = getattr(allExpected, case)
        if actual != expected:
            r.addError(case)
            # print()
コード例 #5
0
# ------- #
# Imports #
# ------- #

from simple_chalk import green, red
from simple_test_default_reporter.fns import isEmpty

# ---- #
# Init #
# ---- #

x = red("✘")
o = green("✔")

# ---- #
# Main #
# ---- #


class Results:
    def __init__(self, name, *, level=0):
        self.level = level
        self.name = name
        self.errors = []

    def addError(self, e):
        self.errors.append(e)
        return self

    def shouldHaveRaisedAnError(self, code):
        self.errors.append(f"'{code}' should have raised an error")
コード例 #6
0
from .mods import (
    CarRun as run,
    servo_ultrasonic_avoid as servo,
    ServoControlColorVersion1 as ctrl1,
    ServoControlColorVersion2 as ctrl2,
)
import simple_chalk as chalk

mods = (run, servo, ctrl1, ctrl2)

print(chalk.green('Starting the program'))
while True:
    try:
        for ext in mods:
            ext.__run__()
    except KeyboardInterrupt:
        print(chalk.red('Stopping the program'))
        for ext in mods:
            ext.__stop__()
        break
コード例 #7
0
    "/html/body/form/div[1]/table/tbody/tr[4]/td[2]/table/tbody/tr/td/table[2]/tbody/tr[6]/td[2]/input[1]"
)
course_title_chosen = driver.find_element_by_xpath(
    "/html/body/form/div[1]/table/tbody/tr[4]/td[2]/table/tbody/tr/td/table[2]/tbody/tr[5]/td[2]/span"
)
course_title = course_title_chosen.text
confirm_yes_button.click()

time.sleep(2)
#Checking the result of trying to enroll in the selected course
result_of_adding_course = driver.find_element_by_xpath(
    "/html/body/form/div[1]/table/tbody/tr[4]/td[2]/table/tbody/tr/td/table[2]/tbody/tr[1]/td[2]/span/font/b"
)

if result_of_adding_course.text == error_message:
    print(
        chalk.red("The course: " + course_title +
                  " could not be added for the following reason:"))
    reason_for_failure = driver.find_element_by_xpath(
        "/html/body/form/div[1]/table/tbody/tr[4]/td[2]/table/tbody/tr/td/table[2]/tbody/tr[2]/td[2]/span/font/b"
    )
    print(chalk.red(reason_for_failure.text))
    message_to_send = "The course: " + course_title + " could not be added for the following reason:" + reason_for_failure.text
    os.system(f'text-me.py "{message_to_send}"')
else:
    print(green(result_of_adding_course.text))
    message_to_send = success_message
    os.system(f'text-me.py "{message_to_send}"')

driver.quit()