示例#1
0
def main():
    """Set up jinga2 enviroment, extract data and save down to html files."""
    env = Environment(
        loader=FileSystemLoader(str(TEMPLATES)),
        autoescape=select_autoescape(["html", "xml"]),
    )
    env.filters["petl2html"] = get_html

    data = petl.fromjson(INPUT)
    data_processed = process_data(data)

    # Refresh the output directory
    OUTPUT.mkdir(exist_ok=True)
    clear_directory(OUTPUT)

    # Save home page
    home_template = env.get_template("about.html")
    html_output = home_template.render(pages=pages)
    (OUTPUT / "about.html").write_text(html_output, encoding="utf-8")

    # Save data-driven pages
    for page in pages:
        process_page(page, data_processed, pages, env)

    copy_tree(str(STATIC), str(OUTPUT))
def build_all_resources():
    mod_structure.cleanup_build_target("resource_directory")
    mod_structure.cleanup_build_target("gui")
    mod_structure.cleanup_build_target("minecraft_resource_pack")
    mod_structure.cleanup_build_target("minecraft_behavior_pack")

    overall_result = 0
    for resource in make_config.get_value("resources", fallback=[]):
        if "path" not in resource or "type" not in resource:
            print("skipped invalid source json", resource, file=sys.stderr)
            overall_result = 1
            continue
        for source_path in make_config.get_paths(resource["path"]):
            if not exists(source_path):
                print("skipped non-existing resource path",
                      resource["path"],
                      file=sys.stderr)
                overall_result = 1
                continue
            resource_type = resource["type"]
            if resource_type not in ("resource_directory", "gui",
                                     "minecraft_resource_pack",
                                     "minecraft_behavior_pack"):
                print("skipped invalid resource with type",
                      resource_type,
                      file=sys.stderr)
                overall_result = 1
                continue
            resource_name = resource[
                "target"] if "target" in resource else basename(source_path)
            resource_name += "{}"

            if resource_type in ("resource_directory", "gui"):
                target = mod_structure.new_build_target(
                    resource_type,
                    resource_name,
                    declare={
                        "type": {
                            "resource_directory": "resource",
                            "gui": "gui"
                        }[resource_type]
                    })
            else:
                target = mod_structure.new_build_target(
                    resource_type,
                    resource_name,
                    exclude=True,
                    declare_default={
                        "resourcePacksDir":
                        mod_structure.get_target_directories(
                            "minecraft_resource_pack")[0],
                        "behaviorPacksDir":
                        mod_structure.get_target_directories(
                            "minecraft_behavior_pack")[0]
                    })
            clear_directory(target)
            copy_directory(source_path, target)

    mod_structure.update_build_config_list("resources")
    return overall_result
示例#3
0
def download_and_extract_toolchain(directory):
    import urllib.request
    import zipfile
    archive = path.join(directory, 'update.zip')

    if not path.exists(archive):
        url = "https://codeload.github.com/80LK/innercore-mod-toolchain/zip/master"
        print("downloading toolchain archive from " + url)
        urllib.request.urlretrieve(url, archive)
    else:
        print("toolchain archive already exists in " + directory)

    print("extracting toolchain to " + directory)

    with zipfile.ZipFile(archive, 'r') as zip_ref:
        zip_ref.extractall(directory)

    try:
        utils.copy_directory(path.join(
            directory, "innercore-mod-toolchain-master/toolchain-mod"),
                             directory,
                             ignore=["make.json", "*/adb/*"],
                             ignoreEx=True)
        utils.clear_directory(
            path.join(directory, "innercore-mod-toolchain-master"))
    except Exception as ex:
        print(ex)
    finally:
        os.remove(archive)
        if not path.exists(path.join(directory, "toolchain")):
            print(
                "an error occured while extracting toolchain archive, please, retry the operation"
            )
            exit()
示例#4
0
def skipto(skip_val):
    if YoutubeHelper.music_thread is not None:
        if YoutubeHelper.queue_instance.is_empty():
            GM.gui.quick_gui(
                "The youtube queue is empty, so I can't skip tracks.",
                text_type='header',
                box_align='left')
            return
        if skip_val > YoutubeHelper.queue_instance.size() - 1:
            GM.gui.quick_gui(
                f"You can't skip beyond the length of the current queue.",
                text_type='header',
                box_align='left')
            return
        if skip_val < 1:
            next()
            return
        GM.gui.quick_gui(f"Skipping to track {skip_val} in the queue.",
                         text_type='header',
                         box_align='left')
        for i in range(skip_val):
            YoutubeHelper.queue_instance.pop()

        GM.logger.info("The youtube audio queue skipped tracks.")
        utils.clear_directory(utils.get_temporary_img_dir())
        stop_audio()
        download_next()
        play_audio()
        return
示例#5
0
def task_cleanup():
    config = get_make_config()
    clear_directory(config.get_path("toolchain/build/gcc"))
    clear_directory(config.get_path("toolchain/build/gradle"))
    import java.java_build
    java.java_build.cleanup_gradle_scripts()
    return 0
示例#6
0
def generate_zip_files_with_random_documents(
    dir_path: str,
    quantity: int,
    documents_per_file: int,
    verbose: bool = True,
) -> None:
    if os.path.exists(dir_path):
        clear_directory(dir_path)
    else:
        os.makedirs(dir_path)

    zip_file_paths = (os.path.join(dir_path, f'{zip_file_num}.zip')
                      for zip_file_num in range(quantity))

    generate_zip_file = partial(
        generate_zip_file_with_random_documents,
        documents_per_file=documents_per_file,
        verbose=verbose,
    )

    with Pool() as pool:
        # TODO: Добавить расчет `chunksize`
        pool.imap_unordered(generate_zip_file, zip_file_paths)
        pool.close()
        pool.join()
示例#7
0
	def cleanup_build_target(self, target_type_name):
		target_type = BUILD_TARGETS[target_type_name]
		self.targets[target_type_name] = []
		if target_type.directory == "":
			return
		directory = os.path.join(self.directory, target_type.directory)
		clear_directory(directory)
		ensure_directory(directory)
示例#8
0
def task_exclude_directories():
    config = get_make_config()
    for path in config.get_value("make.excludeFromRelease", []):
        for exclude in config.get_paths(os.path.join("output", path)):
            if os.path.isdir(exclude):
                clear_directory(exclude)
            elif os.path.isfile(exclude):
                os.remove(exclude)
    return 0
示例#9
0
 def write_build_config(self):
     if self.build_config is None:
         return
     build_config_file = os.path.join(self.directory, "build.config")
     if os.path.isdir(build_config_file):
         clear_directory(build_config_file)
         os.remove(build_config_file)
     ensure_file_dir(build_config_file)
     with open(build_config_file, "w", encoding="utf-8") as build_config:
         build_config.write(json.dumps(self.build_config, indent=" " * 4))
示例#10
0
def upload_files_from_directory(directory, database):
    """
    scans files in the directory and loads them in to database
    :param database:  target database
    :param directory: target directory
    """
    files = os.listdir(directory)
    for file in files:
        upload_to_database(os.path.join(directory, file), db_name=database)
    clear_directory(directory)
示例#11
0
def assemble_assets():
    asset_directories = get_asset_directories()
    if asset_directories is None:
        print("some asset directories are invalid")
        return -1

    output_dir = make_config.get_path("output/assets")
    clear_directory(output_dir)
    for asset_dir in asset_directories:
        copy_directory(asset_dir, output_dir)
    return 0
示例#12
0
def download_image_stream(img_url):
    utils.clear_directory(utils.get_temporary_img_dir())
    img_ext = img_url.rsplit('.', 1)[1]
    with open(f"{utils.get_temporary_img_dir()}image.{img_ext}",
              'wb') as img_file:
        resp = requests.get(img_url, stream=True)
        for block in resp.iter_content(1024):
            if not block:
                break
            img_file.write(block)
    debug_print(f"Downloaded image from: {img_url}")
示例#13
0
    def test_clear_non_existent_directory(self):
        with tempfile.TemporaryDirectory() as temp_dir_path:
            non_existent_dir_path = os.path.join(
                temp_dir_path,
                'non_existent_directory',
            )

            self.assertFalse(os.path.exists(non_existent_dir_path))
            clear_directory(non_existent_dir_path)
            self.assertFalse(os.path.exists(non_existent_dir_path))

        self.assertFalse(os.path.exists(temp_dir_path))
示例#14
0
def download_image_requests(img_url):
    utils.clear_directory(utils.get_temporary_img_dir())
    img_ext = img_url.rsplit('.', 1)[1]
    s = requests.Session()
    r = s.get(img_url, headers={'User-Agent': 'Mozilla/5.0'})
    if r.status_code == 200:
        with open(f"image.{img_ext}", 'wb') as f:
            r.raw.decode_content = True
            shutil.copyfileobj(r.raw, f)
        debug_print(f"Downloaded image from: {img_url}")
    else:
        debug_print(f"403 Error! - {img_url}")
示例#15
0
def init_java_and_native(make_file, directory):
    compile_dirs = []

    src_dir = os.path.join(directory, "src")

    sample_native_module = os.path.join(src_dir, "native", "sample")
    if not os.path.exists(sample_native_module):
        print("native sample module is unavailable")

    else:
        res = input(
            "Do you want to initialize a new native directory? [y/N]: ")
        if res.lower() == 'y':
            module_name = input("Enter the new native module name [sample]: ")
            if module_name != "":
                os.rename(sample_native_module,
                          os.path.join(src_dir, "native", module_name))
        else:
            if (os.path.isdir(sample_native_module)):
                clear_directory(sample_native_module)

    sample_java_archive = os.path.join(src_dir, "java.zip")
    if (not os.path.exists(sample_java_archive)):
        print("java sample module is unavailable")
    else:
        res = input("Do you want to initialize a new java directory? [y/N]: ")
        if res.lower() == 'y':
            module_name = input("Enter the new java module name [sample]: ")
            if module_name == "":
                module_name = "sample"

            with zipfile.ZipFile(sample_java_archive, 'r') as zip_ref:
                zip_ref.extractall(os.path.join(src_dir))

            os.rename(os.path.join(src_dir, "java", "sample"),
                      os.path.join(src_dir, "java", module_name))

            # write info to .classpath
            import xml.etree.ElementTree as etree
            classpath = os.path.join(directory, ".classpath")
            tree = etree.parse(classpath)
            for classpathentry in tree.getroot():
                if (classpathentry.attrib["kind"] == "src"):
                    classpathentry.attrib[
                        "path"] = "src/java/" + module_name + "/src"

            tree.write(classpath, encoding="utf-8", xml_declaration=True)

        else:
            if (os.path.isfile(sample_java_archive)):
                os.remove(sample_java_archive)
示例#16
0
    def test_clear_empty_directory(self):
        with tempfile.TemporaryDirectory() as temp_dir_path:
            empty_dir_path = os.path.join(temp_dir_path, 'empty_directory')

            os.makedirs(empty_dir_path)
            self.assertTrue(os.path.exists(empty_dir_path))
            self.assertFalse(os.listdir(empty_dir_path))

            clear_directory(empty_dir_path)

            self.assertTrue(os.path.exists(empty_dir_path))
            self.assertFalse(os.listdir(empty_dir_path))

        self.assertFalse(os.path.exists(temp_dir_path))
示例#17
0
def init_directories(directory):
    assets_dir = join(directory, "src", "assets")
    clear_directory(assets_dir)
    os.makedirs(join(assets_dir, "gui"))
    os.makedirs(join(assets_dir, "res", "items-opaque"))
    os.makedirs(join(assets_dir, "res", "terran-atlas"))
    libs_dir = join(directory, "src", "lib")
    clear_directory(libs_dir)
    os.makedirs(libs_dir)
    os.makedirs(join(directory, "src", "preloader"))
    os.makedirs(join(assets_dir, "resource_packs"))
    os.makedirs(join(assets_dir, "behavior_packs"))
    with (open(join(directory, "src", "dev", "header.js"),
               "w",
               encoding="utf-8")) as file:
        file.write("")
示例#18
0
def init_directories(make_file, directory):
    assets_dir = os.path.join(directory, "src", "assets")
    clear_directory(assets_dir)
    os.makedirs(os.path.join(assets_dir, "gui"))
    os.makedirs(os.path.join(assets_dir, "res", "items-opaque"))
    os.makedirs(os.path.join(assets_dir, "res", "terran-atlas"))
    libs_dir = os.path.join(directory, "src", "lib")
    clear_directory(libs_dir)
    os.makedirs(libs_dir)
    os.makedirs(os.path.join(directory, "src", "preloader"))
    os.makedirs(os.path.join(assets_dir, "resource_packs"))
    os.makedirs(os.path.join(assets_dir, "behavior_packs"))
    with (open(os.path.join(directory, "src", "dev", "header.js"),
               "w",
               encoding="utf-8")) as file:
        file.write("")
    make_file["sources"][0]["language"] = get_language()
示例#19
0
 def exit(self):
     GM.gui.quick_gui(
         f"{utils.get_bot_name()} is being shutdown.",
         text_type='header',
         box_align='left',
         ignore_whisper=True,
     )
     for plugin in self.bot_plugins.values():
         plugin.quit()
     utils.clear_directory(utils.get_temporary_img_dir())
     reg_print("Cleared temporary directories.")
     if self.web_thr:
         from helpers.web_handler import stop_web
         stop_web()
         self.web_thr.join()
         reg_print("JJMumbleBot Web Interface was disconnected.")
         GM.logger.info("JJMumbleBot Web Interface was disconnected.")
     self.exit_flag = True
示例#20
0
def task_cleanup():
    config = get_make_config()
    clear_directory(config.get_path("toolchain/build/gcc"))
    clear_directory(config.get_path("toolchain/build/gradle"))
    clear_directory(config.get_path("toolchain/build/typescript-headers"))
    clear_directory(config.get_path("toolchain/build/typescript"))

#                               not working
#     import java.java_build
#     java.java_build.cleanup_gradle_scripts()
    return 0
示例#21
0
    def test_clear_directory(self):
        with tempfile.TemporaryDirectory() as temp_dir_path:
            non_empty_dir_path = os.path.join(
                temp_dir_path,
                'non_empty_directory',
            )

            os.makedirs(non_empty_dir_path)
            self.assertTrue(os.path.exists(non_empty_dir_path))
            self.create_empty_file(non_empty_dir_path, 'some_file_1')
            self.create_empty_file(non_empty_dir_path, 'some_file_2')
            os.makedirs(os.path.join(non_empty_dir_path, 'some_directory'))
            self.assertTrue(os.listdir(non_empty_dir_path))

            clear_directory(non_empty_dir_path)

            self.assertTrue(os.path.exists(non_empty_dir_path))
            self.assertFalse(os.listdir(non_empty_dir_path))

        self.assertFalse(os.path.exists(temp_dir_path))
示例#22
0
def assemble_additional_directories():
    result = 0
    output_dir = make_config.get_path("output")
    for additional_dir in make_config.get_value("additional", []):
        if "sources" not in additional_dir or "pushTo" not in additional_dir:
            print("invalid formatted additional directory json",
                  additional_dir)
            result = -1
            break
        dst_dir = join(output_dir, additional_dir["pushTo"])
        clear_directory(dst_dir)
        source_directories = get_path_set(additional_dir["sources"],
                                          error_sensitive=True)
        if source_directories is None:
            print("some additional directories are invalid")
            result = -1
            break
        for source_dir in source_directories:
            copy_directory(source_dir, dst_dir)
    return result
示例#23
0
文件: rodent.py 项目: kod3r/rodent
def motion_detection(camera, folder, until):
    """
    Uses 3 frames to look for motion, can't remember where
    I found it but it gives better result than my first try
    with comparing 2 frames.
    """
    utils.clear_directory(folder)

    # Need to get 2 images to start with
    previous_image = cv2.cvtColor(camera.read()[1], cv2.cv.CV_RGB2GRAY)
    current_image = cv2.cvtColor(camera.read()[1], cv2.cv.CV_RGB2GRAY)
    purple = (140, 25, 71)

    while True:
        now = datetime.datetime.now()
        _, image = camera.read()
        gray_image = cv2.cvtColor(image, cv2.cv.CV_RGB2GRAY)

        difference1 = cv2.absdiff(previous_image, gray_image)
        difference2 = cv2.absdiff(current_image, gray_image)
        result = cv2.bitwise_and(difference1, difference2)

        # Basic threshold, turn the bitwise_and into a black or white (haha)
        # result, white (255) being a motion
        _, result = cv2.threshold(result, 40, 255, cv2.THRESH_BINARY)

        # Let's show a square around the detected motion in the original pic
        low_point, high_point = utils.find_motion_boundaries(result.tolist())
        if low_point is not None and high_point is not None:
            cv2.rectangle(image, low_point, high_point, purple, 3)
            print 'Motion detected ! Taking picture'
            utils.save_image(image, folder, now)

        previous_image = current_image
        current_image = gray_image

        if utils.time_over(until, now):
            break

    del (camera)
示例#24
0
文件: rodent.py 项目: Keats/rodent
def motion_detection(camera, folder, until):
    """
    Uses 3 frames to look for motion, can't remember where
    I found it but it gives better result than my first try
    with comparing 2 frames.
    """
    utils.clear_directory(folder)

    # Need to get 2 images to start with
    previous_image = cv2.cvtColor(camera.read()[1], cv2.cv.CV_RGB2GRAY)
    current_image = cv2.cvtColor(camera.read()[1], cv2.cv.CV_RGB2GRAY)
    purple = (140, 25, 71)

    while True:
        now = datetime.datetime.now()
        _, image = camera.read()
        gray_image = cv2.cvtColor(image, cv2.cv.CV_RGB2GRAY)

        difference1 = cv2.absdiff(previous_image, gray_image)
        difference2 = cv2.absdiff(current_image, gray_image)
        result = cv2.bitwise_and(difference1, difference2)

        # Basic threshold, turn the bitwise_and into a black or white (haha)
        # result, white (255) being a motion
        _, result = cv2.threshold(result, 40, 255, cv2.THRESH_BINARY)

        # Let's show a square around the detected motion in the original pic
        low_point, high_point = utils.find_motion_boundaries(result.tolist())
        if low_point is not None and high_point is not None:
            cv2.rectangle(image, low_point, high_point, purple, 3)
            print 'Motion detected ! Taking picture'
            utils.save_image(image, folder, now)

        previous_image = current_image
        current_image = gray_image

        if utils.time_over(until, now):
            break

    del(camera)
    def removeProject(self, index=None, folder=None):
        if len(self.__projects) == 1:
            raise Exception("Unable to delete a single project")

        index, folder = self.getFolder(index, folder)

        if folder == self.config.get_value("currentProject"):
            raise Exception("The current project cannot be deleted")

        clear_directory(self.config.get_path(folder))
        del self.__projects[index]

        vsc_settings_path = self.config.get_path(".vscode/settings.json")
        with open(vsc_settings_path, "r",
                  encoding="utf-8") as vsc_settings_file:
            vsc_settings_obj = json.loads(vsc_settings_file.read())

        del vsc_settings_obj["files.exclude"][folder]
        with open(vsc_settings_path, "w",
                  encoding="utf-8") as vsc_settings_file:
            vsc_settings_file.write(
                json.dumps(vsc_settings_obj, indent=" " * 4))
示例#26
0
def start_camera(camera, folder, interval, until=None):
    """
    Start taking pictures every interval.
    If until is specified, it will take pictures
    until that time is reached (24h format).
    Needs to be of the following format: HH:MM
    """
    utils.clear_directory(folder)
    number = 0

    while True:
        _, image = camera.read()
        now = datetime.datetime.now()

        number += 1
        print('Taking picture number %d at %s' % (number, now.isoformat()))
        utils.save_image(image, folder, now)

        if utils.time_over(until, now):
            break

        time.sleep(interval)

    del (camera)
示例#27
0
文件: rodent.py 项目: Keats/rodent
def start_camera(camera, folder, interval, until=None):
    """
    Start taking pictures every interval.
    If until is specified, it will take pictures
    until that time is reached (24h format).
    Needs to be of the following format: HH:MM
    """
    utils.clear_directory(folder)
    number = 0

    while True:
        _, image = camera.read()
        now = datetime.datetime.now()

        number += 1
        print 'Taking picture number %d at %s' % (number, now.isoformat())
        utils.save_image(image, folder, now)

        if utils.time_over(until, now):
            break

        time.sleep(interval)

    del(camera)
示例#28
0
def task_clear_output():
    clear_directory(get_make_config().get_path("output"))
    return 0
示例#29
0
    def start_suite(self, name, attributes):

        self.SuitSrc = BuiltIn().get_variable_value('${SUITE_SOURCE}')

        # Reading the Allure Properties file for the Issue Id regular expression
        # for the Issues and the URL to where the Issues/Test Man links should go.
        if (self.AllurePropPath is None):
            self.AllurePropPath = os.path.join(self.SuitSrc,
                                               'allure.properties')

        if os.path.exists(self.AllurePropPath) is True:
            self.AllureProperties = AllureProperties(self.AllurePropPath)
            self.AllureIssueIdRegEx = self.AllureProperties.get_property(
                'allure.issues.id.pattern')

        # Not using &{ALLURE} as this is throwing an error and ${ALLURE} gives the
        # desired dictionary in Allure as well.
        BuiltIn().set_global_variable('${ALLURE}',
                                      self.AllureProperties.get_properties())

        # When running a Robot folder, the folder itself is also considered a Suite
        # The full check depends on the availability of all the vars which are
        # only available when a Robot file has started.

        IsSuiteDirectory = os.path.isdir(self.SuitSrc)
        if (not (IsSuiteDirectory)):
            ''' Check if class received Output Directory Path in the properties file. '''
            if self.AllureProperties.get_property(
                    'allure.cli.logs.xml') is None:
                ''' No Path was provided, so using output dir with additional sub folder. '''
                self.allurelogdir = BuiltIn().get_variable_value(
                    '${OUTPUT_DIR}') + "\\Allure"
            else:
                self.allurelogdir = self.AllureProperties.get_property(
                    'allure.cli.logs.xml')

            self.AllureImplc = AllureImpl(self.allurelogdir)
        ''' Clear the directory but not if run in parallel mode in Pabot'''
        PabotPoolId = BuiltIn().get_variable_value('${PABOTEXECUTIONPOOLID}')
        try:
            if (self.isFirstSuite == True
                    and self.AllureProperties.get_property(
                        'allure.cli.logs.xml.clear') == 'True'
                    and PabotPoolId is None):
                clear_directory(
                    self.AllureProperties.get_property('allure.cli.logs.xml'))
        except Exception as e:
            logger.console(pprint.pformat(e))
        finally:
            self.isFirstSuite = False

        if attributes.get('doc') is not '':
            description = attributes.get('doc')
        else:
            description = name

        self.testsuite = TestSuite(name=name,
                                   title=attributes['longname'],
                                   description=description,
                                   tests=[],
                                   labels=[],
                                   start=now())

        return
示例#30
0
def build_native_dir(directory, output_dir, cache_dir, abis, std_includes_path, rules: BaseConfig):
	executables = {}
	for abi in abis:
		executable = prepare_compiler_executable(abi)
		if executable is None:
			print("failed to acquire GCC executable from NDK for abi " + abi)
			return CODE_FAILED_NO_GCC
		executables[abi] = executable

	try:
		manifest = get_manifest(directory)
		targets = {}
		soname = "lib" + manifest["shared"]["name"] + ".so"
		for abi in abis:
			targets[abi] = os.path.join(output_dir, "so/" + abi + "/" + soname)
	except Exception as err:
		print("failed to read manifest for directory " + directory + " error: " + str(err))
		return CODE_FAILED_INVALID_MANIFEST

	keep_sources = rules.get_value("keepSources", fallback=False)
	if keep_sources:
		# copy everything and clear build files
		copy_directory(directory, output_dir, clear_dst=True)
		clear_directory(os.path.join(output_dir, "so"))
		os.remove(os.path.join(output_dir, soname))
	else:
		clear_directory(output_dir)

		# copy manifest
		copy_file(os.path.join(directory, "manifest"), os.path.join(output_dir, "manifest"))

		# copy includes
		keep_includes = rules.get_value("keepIncludes", fallback=True)
		for include_path in manifest["shared"]["include"]:
			src_include_path = os.path.join(directory, include_path)
			output_include_path = os.path.join(output_dir, include_path)
			if keep_includes:
				copy_directory(src_include_path, output_include_path, clear_dst=True)
			else:
				clear_directory(output_include_path)

	std_includes = []
	for std_includes_dir in os.listdir(std_includes_path):
		std_includes.append(os.path.abspath(os.path.join(std_includes_path, std_includes_dir)))

	# compile for every abi
	overall_result = CODE_OK
	for abi in abis:
		printed_compilation_title = f"compiling {os.path.basename(directory)} for {abi}"
		print("\n")
		print(f"{'=' * (48 - len(printed_compilation_title) // 2)} {printed_compilation_title} {'=' * (48 - (1 + len(printed_compilation_title)) // 2)}")

		executable = executables[abi]
		gcc = [executable, "-std=c++11"]
		includes = []
		for std_includes_dir in std_includes:
			includes.append(f'-I{std_includes_dir}')
		dependencies = [f'-L{get_fake_so_dir(abi)}', "-landroid", "-lm", "-llog"]
		for link in rules.get_value("link", fallback=[]) + make_config.get_value("make.linkNative", fallback=[]) + ["horizon"]:
			add_fake_so(executable, abi, link)
			dependencies.append(f'-l{link}')
		if "depends" in manifest:
			search_dir = os.path.abspath(os.path.join(directory, ".."))  # always search for dependencies in current dir
			for dependency in manifest["depends"]:
				if dependency is not None:
					add_fake_so(executable, abi, dependency)
					dependencies.append("-l" + dependency)
					dependency_dir = search_directory(search_dir, dependency)
					if dependency_dir is not None:
						try:
							for include_dir in get_manifest(dependency_dir)["shared"]["include"]:
								includes.append("-I" + os.path.join(dependency_dir, include_dir))
						except KeyError:
							pass
				else:
					print(f"ERROR: dependency directory {dependency} is not found, it will be skipped")

		# prepare directories
		source_files = get_all_files(directory, extensions=(".cpp", ".c"))
		preprocessed_dir = os.path.abspath(os.path.join(cache_dir, "preprocessed", abi))
		ensure_directory(preprocessed_dir)
		object_dir = os.path.abspath(os.path.join(cache_dir, "object", abi))
		ensure_directory(object_dir)

		# pre-process and compile changes
		import filecmp
		object_files = []
		recompiled_count = 0
		for file in source_files:
			relative_file = relative_path(directory, file)
			sys.stdout.write("preprocessing " + relative_file + " " * 64 + "\r")

			object_file = os.path.join(object_dir, relative_file) + ".o"
			preprocessed_file = os.path.join(preprocessed_dir, relative_file)
			tmp_preprocessed_file = preprocessed_file + ".tmp"
			ensure_file_dir(preprocessed_file)
			ensure_file_dir(object_file)
			object_files.append(object_file)

			result = subprocess.call(gcc + ["-E", file, "-o", tmp_preprocessed_file] + includes)
			if result == CODE_OK:
				if not os.path.isfile(preprocessed_file) or not os.path.isfile(object_file) or \
						not filecmp.cmp(preprocessed_file, tmp_preprocessed_file):
					if os.path.isfile(preprocessed_file):
						os.remove(preprocessed_file)
					os.rename(tmp_preprocessed_file, preprocessed_file)
					if os.path.isfile(object_file):
						os.remove(object_file)

					sys.stdout.write("compiling " + relative_file + " " * 64 + "\n")
					result = max(result, subprocess.call(gcc + ["-c", preprocessed_file, "-shared", "-o", object_file]))
					if result != CODE_OK:
						if os.path.isfile(object_file):
							os.remove(object_file)
						overall_result = result
					else:
						recompiled_count += 1
			else:
				if os.path.isfile(object_file):
					os.remove(object_file)
				overall_result = result

		print(" " * 128)
		if overall_result != CODE_OK:
			print("failed to compile", overall_result)
			return overall_result
		else:
			print(f"recompiled {recompiled_count}/{len(object_files)} files with result {overall_result}")

		ensure_file_dir(targets[abi])

		command = []
		command += gcc
		command += object_files
		command.append("-shared")
		command.append("-Wl,-soname=" + soname)
		command.append("-o")
		command.append(targets[abi])
		command += includes
		command += dependencies
		print("linking object files...")
		result = subprocess.call(command)
		if result == CODE_OK:
			print("build successful")
		else:
			print("linker failed with result code", result)
			overall_result = result
			return overall_result
	return overall_result
示例#31
0
def import_build_config(make_file, source, destination):
    global root_files
    root_files.append("build.config")

    build_config = os.path.join(source, "build.config")
    with open(build_config, "r", encoding="utf-8") as config_file:
        config_obj = json.loads(config_file.read())
        config = BaseConfig(config_obj)
        make_file["global"]["api"] = config.get_value("defaultConfig.api",
                                                      "CoreEngine")

        src_dir = os.path.join(destination, "src")

        # clear assets folder
        assets_dir = os.path.join(src_dir, "assets")
        clear_directory(assets_dir)
        os.makedirs(assets_dir)

        # some pre-defined resource folders
        resources = [{
            "path": "src/assets/resource_packs/*",
            "type": "minecraft_resource_pack"
        }, {
            "path": "src/assets/behavior_packs/*",
            "type": "minecraft_behavior_pack"
        }]

        os.makedirs(os.path.join(assets_dir, "resource_packs"))
        os.makedirs(os.path.join(assets_dir, "behavior_packs"))

        # import assets
        for res_dir in config.get_filtered_list("resources", "resourceType",
                                                ("resource", "gui")):
            if res_dir["resourceType"] == "resource":
                res_dir["resourceType"] = "resource_directory"
            path_stripped = res_dir["path"].strip('/')
            path_parts = path_stripped.split('/')
            path = os.path.join(*path_parts)
            copy_directory(os.path.join(source, path),
                           os.path.join(assets_dir, path), True)
            resources.append({
                "path": "src/assets/" + path_stripped,
                "type": res_dir["resourceType"]
            })

            root_files.append(path_parts[0])

        make_file["resources"] = resources

        # clear libraries folder and copy libraries from the old project
        libs_dir = os.path.join(destination, "src", "lib")
        clear_directory(libs_dir)
        clear_directory(os.path.join(destination, "src", "dev"))
        os.makedirs(libs_dir)
        old_libs = config.get_value("defaultConfig.libraryDir",
                                    "lib").strip('/')
        old_libs_parts = old_libs.split('/')
        old_libs_dir = os.path.join(source, *old_libs_parts)
        if os.path.isdir(old_libs_dir):
            root_files.append(old_libs_parts[0])
            copy_directory(old_libs_dir, libs_dir)

        # some pre-defined source folders
        sources = [{
            "source": "src/lib/*",
            "type": "library",
            "language": "javascript"
        }, {
            "source": "src/preloader/*",
            "type": "preloader",
            "language": "javascript"
        }]

        ensure_directory(os.path.join(src_dir, "preloader"))

        # import sources
        for source_dir in config.get_filtered_list("compile", "sourceType",
                                                   ("mod", "launcher")):
            if source_dir["sourceType"] == "mod":
                source_dir["sourceType"] = "main"

            sourceObj = {
                "type": source_dir["sourceType"],
                "language": "javascript"
            }

            source_parts = source_dir["path"].split('/')
            root_files.append(source_parts[0])

            build_dirs = config.get_filtered_list("buildDirs", "targetSource",
                                                  (source_dir["path"]))
            if (len(build_dirs) > 0):
                old_build_path = build_dirs[0]["dir"].strip("/")
                old_path_parts = old_build_path.split('/')
                sourceObj["source"] = "src/" + old_build_path
                sourceObj["target"] = source_dir["path"]
                root_files.append(old_path_parts[0])

                copy_directory(os.path.join(source, *old_path_parts),
                               os.path.join(src_dir, *old_path_parts), True)

            else:
                sourceObj["source"] = "src/" + source_dir["path"]
                copy_file(os.path.join(source, *source_parts),
                          os.path.join(src_dir, *source_parts))

            sources.append(sourceObj)

        make_file["sources"] = sources
        return
    exit("unable to read build.config")
示例#32
0
def play_audio():
    GM.mumble.sound_output.clear_buffer()
    time.sleep(0.1)

    YoutubeHelper.current_song_info = YoutubeHelper.queue_instance.pop()
    if YoutubeHelper.current_song_info is None:
        stop_audio()
        return
    if YoutubeHelper.current_song_info['img_id'] is None:
        return
    YoutubeHelper.current_song = YoutubeHelper.current_song_info.get(
        'main_url')

    stripped_url = BeautifulSoup(YoutubeHelper.current_song,
                                 features='html.parser').get_text()
    uri = stripped_url

    command = utils.get_vlc_dir()

    thr = None
    if not YoutubeHelper.queue_instance.is_empty():
        thr = threading.Thread(target=download_next)
        thr.start()

    #if YoutubeHelper.music_thread:
    #    YoutubeHelper.music_thread.terminate()
    #    YoutubeHelper.music_thread.kill()
    #    YoutubeHelper.music_thread = None

    #if YoutubeHelper.music_thread is None:
    YoutubeHelper.music_thread = sp.Popen([command, uri] + [
        '-I', 'dummy', '--quiet', '--one-instance', '--no-repeat', '--sout',
        '#transcode{acodec=s16le, channels=2, '
        'samplerate=24000, ab=192, threads=8}:std{access=file, '
        'mux=wav, dst=-}', 'vlc://quit'
    ],
                                          stdout=sp.PIPE,
                                          bufsize=480)
    # YoutubeHelper.music_thread.wait()
    YoutubeHelper.is_playing = True
    utils.unmute()

    GM.gui.quick_gui_img(
        f"{utils.get_temporary_img_dir()}",
        f"{YoutubeHelper.current_song_info['img_id']}",
        caption=f"Now playing: {YoutubeHelper.current_song_info['main_title']}",
        format=True,
        img_size=32768)

    while not YoutubeHelper.exit_flag and GM.mumble.isAlive():
        while GM.mumble.sound_output.get_buffer_size(
        ) > 0.5 and not YoutubeHelper.exit_flag:
            time.sleep(0.01)
        if YoutubeHelper.music_thread:
            raw_music = YoutubeHelper.music_thread.stdout.read(480)
            if raw_music and YoutubeHelper.music_thread and YoutubeHelper.is_playing:
                GM.mumble.sound_output.add_sound(
                    audioop.mul(raw_music, 2, YoutubeHelper.volume))
            else:
                if not YoutubeHelper.autoplay:
                    YoutubeHelper.is_playing = False
                    if thr:
                        thr.join()
                    try:
                        utils.remove_file(
                            f"{YoutubeHelper.current_song_info['img_id']}.jpg",
                            utils.get_temporary_img_dir())
                        if YoutubeHelper.queue_instance.size() < 1:
                            utils.clear_directory(
                                utils.get_temporary_img_dir())
                    except (FileNotFoundError, TypeError):
                        pass
                    download_next()
                    return
                else:
                    YoutubeHelper.is_playing = False
                    if thr:
                        thr.join()
                    try:
                        utils.remove_file(
                            f"{YoutubeHelper.current_song_info['img_id']}.jpg",
                            utils.get_temporary_img_dir())
                        if YoutubeHelper.queue_instance.size() < 1:
                            utils.clear_directory(
                                utils.get_temporary_img_dir())
                    except (FileNotFoundError, TypeError):
                        pass
                    download_next()
                    play_audio()
                    return
        else:
            return
    return