def main(args):
    project = utils.find_projectjson()

    # This path is relative to the current working directory and to the
    # directory with project.json (since they're the same dir)
    bmml_path = project['bmml_path']

    # Add a "urls" component to the project if not exists
    if "urls" not in project:
        project['urls'] = {}

    # Build a list of all bmml files
    print("Scanning %s for .bmml files" % bmml_path)
    all_bmmls = []
    for dirpath, dirnames, filenames in os.walk(bmml_path):
        for filename in filenames:
            if filename.endswith(".bmml"):
                # Find the path to the bmml relative to the bmml_path. We can
                # do this by stripping off bmml_path from the front of dirpath,
                # but make sure there is no leading slash left on dirpath
                if not dirpath.startswith(bmml_path):
                    raise Exception("Sanity check failed: found a dirpath that did not start with %s. This shouldn't happen, what's going on?" % bmml_path)
                bmml_file = dirpath[len(bmml_path):]
                bmml_file = bmml_file.lstrip("/\\")
                bmml_file = os.path.join(bmml_file, filename)


                # See if there's an existing entry in project['urls'] or if we
                # need to create a new one
                if bmml_file in project['urls']:
                    json_entry = project['urls'][bmml_file]
                else:
                    json_entry = {}
                    project['urls'][bmml_file] = json_entry

                bmml_obj = BMML(
                                bmml_file,
                                json_entry,
                            )
                print("\tProcessing %s %s" % (bmml_file,"(NEW!)" if bmml_obj.is_new() else ""))

                all_bmmls.append(
                            bmml_obj
                        )

    print("Found %s bmml files! How do you want to proceed?" % len(all_bmmls))
    main_menu(all_bmmls)

    print()
    print("Saving project.json...")
    utils.save_projectjson(project)
Example #2
0
def main():
    project = utils.find_projectjson()

    bmml_path = project['bmml_path']

    # Add a "forms" component to the project if not exists
    if "forms" not in project:
        project['forms'] = []

    # Build a list of all bmml files
    print("Scanning %s for .bmml files" % bmml_path)
    all_bmmls = []
    for dirpath, dirnames, filenames in os.walk(bmml_path):
        for filename in filenames:
            if filename.endswith(".bmml"):
                all_bmmls.append(
                        BMML(
                            os.path.join(dirpath, filename)
                            )
                        )

    # Find and build Form objects for all forms found in in bmml files
    bmml_forms = []
    for bmml_file in all_bmmls:
        forms = bmml_file.forms
        if len(forms) != 0:
            bmml_forms.extend(forms)

    choice = 0
    while(choice != 3 and choice != 4):
        print("\nFound %s possible forms within %s bmml files! How do you want to proceed?" % (len(bmml_forms), len(all_bmmls)))
        choice = utils.prompt_choices([
            "Show me the currently configured forms.",
            "Delete a currently configured forms.",
            "Show me auto-detected forms, and ask me what to do with them.",
            "Save + Quit.  We're done here.",
            "Quit.  Throwing away changes.",
            ])
        print()
    
        if choice == 0:
            display_forms(project)
        elif choice == 1:
            delete_a_form(project)
        elif choice == 2:
            ask_autodetected_forms(project, bmml_forms)
        elif choice == 3:
            utils.save_projectjson(project)