Quote:
Originally Posted by eschwartz
There was no way that would ever work on anything other than Windows. It is highly os-specific.
For that matter, it is highly environment-specific -- it would also break hard on a PortableApps.com install, for example.
|
This is certainly a valid point, but since
CalibUser doesn't have a Mac or a Linux machine, I appreciate it that he at least made an effort to make his plugin OSX/Linux compatible, even though he doesn't have a way of testing it.
@CalibUser: Python has a boatload of built-in functions for cross-platform file handling that make it really easy to implement cross-platform file support.
Since the Sigil plugin root directory and the user_dictionary directory are sibling directories it's relatively easy to get the user_dictionary directory location.
For example, you could use the following code to get the dictionary folder:
Code:
import os, inspect
def run(bk):
# get plugin directory path
plugin_path = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
print(plugin_path)
# get rid of the last two directories
tmp_path = plugin_path.split(os.path.sep)[:7]
print(tmp_path)
# add the dictionary path
tmp_path.extend(['user_dictionaries', 'WordDictionary.txt'])
# convert list back to file path
dictionary_path = os.path.sep.join(tmp_path)
print(dictionary_path)
The above code will produce the following output:
Windows:
Code:
C:\Users\Doitsu\AppData\Local\sigil-ebook\sigil\plugins\test
['C:', 'Users', 'Doitsu', 'AppData', 'Local', 'sigil-ebook', 'sigil']
C:\Users\Doitsu\AppData\Local\sigil-ebook\sigil\user_dictionaries\WordDictionary.txt
Linux (DiapDealer's build):
Code:
/home/doitsu/.local/share/sigil-ebook/sigil/plugins/test
['', 'home', 'doitsu', '.local', 'share', 'sigil-ebook', 'sigil']
/home/doitsu/.local/share/sigil-ebook/sigil/user_dictionaries/WordDictionary.txt
I've attached a test plugin that you can play with.