예제 #1
0
    def _update_from_directory(self):
        self.name = op.splitext(op.basename(self.directory))[0]
        self._ui_title = self.name
        self.unique_name = GenericUIComponent.make_unique_name(self.directory)

        full_file_path = op.join(self.directory, exts.DEFAULT_ICON_FILE)
        self.icon_file = full_file_path if op.exists(full_file_path) else None
        mlogger.debug('Icon file is: %s:%s', self.name, self.icon_file)

        self.media_file = \
            self.find_bundle_file([exts.DEFAULT_MEDIA_FILENAME], finder='name')
        mlogger.debug('Media file is: %s:%s', self.name, self.media_file)

        self._help_url = \
            self.find_bundle_file([exts.HELP_FILE_PATTERN], finder='regex')

        # each component can store custom libraries under
        # lib/ inside the component folder
        lib_path = op.join(self.directory, exts.COMP_LIBRARY_DIR_NAME)
        self.library_path = lib_path if op.exists(lib_path) else None

        # setting up search paths. These paths will be added to
        # all sub-components of this component.
        if self.library_path:
            self.module_paths.append(self.library_path)

        # each component can store custom binaries under
        # bin/ inside the component folder
        bin_path = op.join(self.directory, exts.COMP_BIN_DIR_NAME)
        self.binary_path = bin_path if op.exists(bin_path) else None

        # setting up search paths. These paths will be added to
        # all sub-components of this component.
        if self.binary_path:
            self.module_paths.append(self.binary_path)

        # find meta file
        self.meta_file = self.find_bundle_file([exts.BUNDLEMATA_POSTFIX])
        if self.meta_file:
            # sets up self.meta
            try:
                self.meta = yaml.load_as_dict(self.meta_file)
                if self.meta:
                    self._read_bundle_metadata()
            except Exception as err:
                mlogger.error("Error reading meta file @ %s | %s",
                              self.meta_file, err)
예제 #2
0
파일: script.py 프로젝트: rheesk22/pyrevit
def update_bundle_property(bdata, bcomp, prop_name):
    # bdata is bundle locale data
    # bcomp is bundle component
    locale_data = bdata.get(bcomp.name, [])
    if locale_data:
        # ensure there is bundle metadata file
        meta_file = bcomp.meta_file
        if not meta_file:
            print('creating bundle file for \"%s\"' % bcomp)
            meta_file = op.join(bcomp.directory, DEFAULT_BUNDLE_FILENAME)
            yaml.dump_dict(
                {
                    prop_name: {
                        DEFAULT_LOCAL_KEY: get_prop_from_comp(
                            prop_name, bcomp)
                    }
                }, meta_file)

        meta = yaml.load_as_dict(meta_file)
        meta = localize_property(meta, prop_name, DEFAULT_LOCAL_KEY)
        print('updating bundle locale data for \"%s\"' % bcomp)
        for locale_code, locale_str in locale_data.items():
            if locale_str:
                if locale_code in meta[prop_name]:
                    print('updating existing locale \"%s\" -> \"%s\"' %
                          (meta[prop_name][locale_code], locale_str))
                else:
                    print('adding locale \"%s\" -> \"%s\"' %
                          (locale_code, locale_str))
                meta[prop_name][locale_code] = locale_str

        yaml.dump_dict(meta, meta_file)

    if bcomp.is_container:
        for child_comp in bcomp:
            update_bundle_property(bdata, child_comp, prop_name)
예제 #3
0
def load_configs(parma_file):
    # Load contents of yaml file into an ordered dict
    return yaml.load_as_dict(parma_file)