Ejemplo n.º 1
0
def main():
    '''
    usage: python3 generate_sample_solutions.py {platform} {path_to_samples} {output_root}
    '''
    # Take the path to the samples root (ending in src)
    print(sys.argv)
    platform = sys.argv[1]
    sample_root = sys.argv[2]  # TODO
    output_root = sys.argv[3]

    if not platform in ["UWP", "WPF", "Android", "iOS", "XFU", "XFA", "XFI"]:
        print("Platform must be UWP, WPF, Android, iOS, XFA, XFI, or XFU")
    if not sample_root.endswith("src"):
        print("sample dir should end in src")

    # make a list of samples, so that build_all_csproj.bat can be produced
    list_of_sample_dirs = []
    list_of_samples = {}
    skipped_categories = False
    sample_root = get_platform_samples_root(platform, sample_root)
    for r, d, f in os.walk(sample_root):
        if not skipped_categories:
            skipped_categories = True
            continue
        for sample_dir in d:
            # skip category directories
            sample = sample_metadata()
            path_to_json = os.path.join(r, sample_dir, "readme.metadata.json")
            if not os.path.exists(path_to_json):
                print(f"skipping path; does not exist: {path_to_json}")
                continue
            sample.populate_from_json(path_to_json)
            if platform == "Forms":
                for sub_plat in ["XFA", "XFI", "XFU"]:
                    sample.emit_standalone_solution(
                        sub_plat, os.path.join(r, sample_dir), output_root)
            else:
                sample.emit_standalone_solution(platform,
                                                os.path.join(r, sample_dir),
                                                output_root)
            list_of_sample_dirs.append(sample_dir)
            # track samples in each category to enable TOC generation
            if sample.category in list_of_samples.keys():
                list_of_samples[sample.category].append(sample)
            else:
                list_of_samples[sample.category] = [sample]
    # write out build_all_csproj.bat
    if platform == "Forms":
        for sub_plat in ["XFA", "XFI", "XFU"]:
            write_build_script(list_of_sample_dirs, sub_plat,
                               os.path.join(output_root, sub_plat))
    else:
        write_build_script(list_of_sample_dirs, platform,
                           os.path.join(output_root, platform))
def main():
    '''
    Usage: python process_metadata.py {operation} {path_to_samples (ends in src)} {path_to_secondary}
    Operations: toc; secondary path is empty
                improve; secondary path is common readme
                attributes; keep attributes in code in sync with readme
                sync; keep metadata in sync with readme
    '''

    if len(sys.argv) < 3:
        print("Usage: python process_metadata.py {operation} {path_to_samples (ends in src)} {path_to_secondary}")
        print("Operations are toc, improve, attributes, and sync; secondary path is path to common readme source for the improve operation.")
        return

    operation = sys.argv[1]        
    sample_root = sys.argv[2]
    common_dir_path = ""
    if operation == "improve":
        if len(sys.argv) < 4:
            print("Usage: python process_metadata.py improve {path_to_samples (ends in src)} {path_to_readme_source}")
            return
        common_dir_path = sys.argv[3]

    for platform in ["UWP", "WPF", "Android", "Forms", "iOS", "FormsAR"]:
        # make a list of samples, so that build_all_csproj.bat can be produced
        list_of_sample_dirs = []
        list_of_samples = {}
        skipped_categories = False
        for r, d, f in os.walk(get_platform_samples_root(platform, sample_root)):
            if not skipped_categories:
                skipped_categories = True
                continue
            for sample_dir in d:
                # skip category directories
                sample = sample_metadata()
                path_to_readme = os.path.join(r, sample_dir, "readme.md")
                if not os.path.exists(path_to_readme):
                    print(f"skipping path; does not exist: {path_to_readme}")
                    continue
                sample.populate_from_readme(platform, path_to_readme)
                if platform == "FormsAR":
                    sample.category = "Augmented reality"
                sample.populate_snippets_from_folder(platform, path_to_readme)
                if operation == "improve":
                    sample.try_replace_with_common_readme(platform, common_dir_path, path_to_readme)
                if operation in ["improve", "sync"]:
                    # read existing packages from metadata
                    path_to_json = os.path.join(r, sample_dir, "readme.metadata.json")
                    if os.path.exists(path_to_json):
                        metadata_based_sample = sample_metadata()
                        metadata_based_sample.populate_from_json(path_to_json)
                        sample.nuget_packages = metadata_based_sample.nuget_packages
                    sample.resync_nuget_packages(platform)
                    sample.flush_to_json(path_to_json)
                if operation == "attributes":
                    update_attribute(sample, os.path.join(r, sample_dir))
                list_of_sample_dirs.append(sample_dir)
                # track samples in each category to enable TOC generation
                if sample.category in list_of_samples.keys():
                    list_of_samples[sample.category].append(sample)
                else:
                    list_of_samples[sample.category] = [sample]
        # write out samples TOC
        if operation in ["toc", "improve", "sync"] and platform != "FormsAR":
            write_samples_toc(get_platform_samples_root(platform, sample_root), get_relative_path_to_samples_from_platform_root(platform), list_of_samples)
    return