|
@@ -8,9 +8,11 @@ from __future__ import print_function |
|
|
import os |
|
|
import os |
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
import configparser |
|
|
|
|
|
|
|
|
from configparser import ConfigParser, NoSectionError |
|
|
|
|
|
py3k = True |
|
|
except ImportError: # Python 2 |
|
|
except ImportError: # Python 2 |
|
|
import ConfigParser as configparser |
|
|
|
|
|
|
|
|
from ConfigParser import SafeConfigParser as ConfigParser, NoSectionError |
|
|
|
|
|
py3k = False |
|
|
|
|
|
|
|
|
from colorama import Fore, Style |
|
|
from colorama import Fore, Style |
|
|
|
|
|
|
|
@@ -37,9 +39,12 @@ def _migrate_old_config_path(): |
|
|
os.rename(old_path, new_path) |
|
|
os.rename(old_path, new_path) |
|
|
|
|
|
|
|
|
def _load_config_file(config_path=None): |
|
|
def _load_config_file(config_path=None): |
|
|
"""Read the config file and return a SafeConfigParser() object.""" |
|
|
|
|
|
|
|
|
"""Read the config file and return a config parser object.""" |
|
|
_migrate_old_config_path() |
|
|
_migrate_old_config_path() |
|
|
config = configparser.SafeConfigParser(delimiters='=') |
|
|
|
|
|
|
|
|
if py3k: |
|
|
|
|
|
config = ConfigParser(delimiters='=') |
|
|
|
|
|
else: |
|
|
|
|
|
config = ConfigParser() |
|
|
# Don't lowercase option names, because we are storing paths there: |
|
|
# Don't lowercase option names, because we are storing paths there: |
|
|
config.optionxform = lambda opt: opt |
|
|
config.optionxform = lambda opt: opt |
|
|
config.read(config_path or get_default_config_path()) |
|
|
config.read(config_path or get_default_config_path()) |
|
@@ -63,7 +68,7 @@ def get_bookmarks(config_path=None): |
|
|
config = _load_config_file(config_path) |
|
|
config = _load_config_file(config_path) |
|
|
try: |
|
|
try: |
|
|
return [path for path, _ in config.items("bookmarks")] |
|
|
return [path for path, _ in config.items("bookmarks")] |
|
|
except configparser.NoSectionError: |
|
|
|
|
|
|
|
|
except NoSectionError: |
|
|
return [] |
|
|
return [] |
|
|
|
|
|
|
|
|
def add_bookmarks(paths, config_path=None): |
|
|
def add_bookmarks(paths, config_path=None): |
|
|