bantya / Keypirinha-Zealous

Keypirinha plugin for exploring Zeal docs.
MIT License
18 stars 1 forks source link

plistlib fail on some files and zealous breaks #2

Closed vhanla closed 4 years ago

vhanla commented 4 years ago

If you add docset feeds from third party maintainers, like from example https://github.com/hashhar/dash-contrib-docset-feeds/blob/master/Clang.xml It has Info.plist file in single line, no multiline, I guess that makes plistlib to fail loading it, I really don't know. imagen

However, Zeal will import it correctly, but plistlib in Zealous fails to load Info.plist, and reading the next docsets in the for loop breaks, so it won't work with this plugin.

So one way to avoid that is using an exception catcher, as in the correction I did in order to make it work.


def on_start(self):
        self._load_settings()
        self._gather_docs()
        self._gather_types()

        self.package_path = self.get_package_cache_path(True)
        self.docsets_json = os.path.join(self.package_path, 'docsets.json')

        default_docset_path = kp.package_cache_dir().split('Keypirinha\\Packages')[0] + 'Zeal\\Zeal\\docsets'
        self.docsets_path = self.settings.get_stripped('docset_path', self.SECTION_MAIN, default_docset_path)

        json_data = self._read_json()

        for key in self.docs:
            docset = self.settings.get_stripped(key, self.SECTION_DOCS)
            if docset not in json_data.keys():
                for folder_name in os.listdir(self.docsets_path):
                    plist_path = os.path.join(self.docsets_path, folder_name, self.PLIST_FILE)
                    if os.path.isfile(plist_path):
                        with open(plist_path, 'rb') as fp:
                            try:
                                pl = plistlib.load(fp)
                                if docset == pl["DocSetPlatformFamily"]:
                                    self.icon_path = os.path.join(self.docsets_path, folder_name)

                                    self._save_docsets(docset, folder_name.split('.docset')[0])
                                    self._copy_icon(docset)
                            except Exception :
                                self.info('Error reading plist file')

I hope you can fix it, as this https://github.com/hashhar/dash-contrib-docset-feeds is awesome.

bantya commented 4 years ago

I'll take a good look into it. Thanks!

🙏🏼

bantya commented 4 years ago

@vhanla

First of all, extremely sorry for the ultra late reply! (I really have to learn some lessons about punctuality. 😑)

I've checked what you claimed and found out that your suspicion is not to blame. Many standard docsets like Laravel, Java and many others have their Info.plist file content specified in a single line. The code will take care of that.

The problem lies with these user-contributed docsets! The repo you provided is a good one but contains some old entries. I've tried Clang, Emacs any some other docs. The docs are OK, those can be used manually by navigating to the doc, but the problem is those cannot be accessed with pneumonic i.e. docset_name:search_term. (Some in the list can be, some not!) That is why it may seem like the plugin is having hard time working with such docsets, but surprisingly it works! The results get populated upon searching but as the docset in question cannot be accessed through docset_name:search_term, it may not work as expectd. So, can't help! 🙂

Thanks for the solution though. 👍🏽

Take care. Stay safe..

🙏🏼

bantya commented 4 years ago

I'll mark it as Closed! Please feel free to reach me if you want to.

🙏🏼