From: Oleg Broytman Date: Sun, 29 Jun 2014 15:50:19 +0000 (+0400) Subject: Allow parameters in BKMK_* environment variables X-Git-Tag: v4.6.0~25 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=18c4a4f08c96c72f3f06c06ba3e7eb8d87eaa614;p=bookmarks_db.git Allow parameters in BKMK_* environment variables For example, BKMK_ROBOT=forking:subproc=urllib or BKMK_STORAGE=json:filename=bookmarks_db.json. --- diff --git a/bkmk_objects.py b/bkmk_objects.py index a8c75f2..dce9811 100644 --- a/bkmk_objects.py +++ b/bkmk_objects.py @@ -10,7 +10,7 @@ __license__ = "GNU GPL" __all__ = ['Folder', 'Bookmark', 'Ruler', 'Walker', 'Writer', 'Robot', 'InverseLinker', 'Linear', 'make_linear', 'make_tree', 'break_tree', - 'quote_title', 'unquote_title', + 'quote_title', 'unquote_title', 'parse_params', 'set_params', ] @@ -218,3 +218,19 @@ def unquote_title(title): title = HTMLParser().unescape(title.replace("&", '&').decode('utf-8')) title = title.encode('utf-8').replace("'", "'") return title + + +def parse_params(param_str): + params = param_str.split(':') + main_param = params.pop(0) + param_list = {} + for param in params: + key, value = param.split('=', 1) + param_list[key] = value + return main_param, param_list + +def set_params(obj, params): + if hasattr(params, "items"): + params = params.items() + for key, value in params: + setattr(obj, key, value) diff --git a/doc/ANNOUNCE b/doc/ANNOUNCE index 92cb624..8e06cdd 100644 --- a/doc/ANNOUNCE +++ b/doc/ANNOUNCE @@ -17,12 +17,20 @@ WHAT'S NEW in version 4.6.0 (2014-06-??) Adapt JSON storage to recent Mozilla export format. + Add ChangeLog. + + Allow parameters in BKMK_* environment variables; for example, + BKMK_ROBOT=forking:subproc=urllib or + BKMK_STORAGE=json:filename=bookmarks_db.json. + WHERE TO GET Home page: http://phdru.name/Software/Python/#bookmarks_db git clone http://git.phdru.name/bookmarks_db.git git clone git://git.phdru.name/bookmarks_db.git + Requires: Python 2.5+, m_lib 2.0+. + AUTHOR Oleg Broytman diff --git a/doc/ChangeLog b/doc/ChangeLog index f83c649..8919e53 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -11,6 +11,10 @@ WHAT'S NEW in version 4.6.0 (2014-06-??) Add ChangeLog. + Allow parameters in BKMK_* environment variables; for example, + BKMK_ROBOT=forking:subproc=urllib or + BKMK_STORAGE=json:filename=bookmarks_db.json. + WHAT'S NEW in version 4.5.6 (2014-01-14) diff --git a/doc/TODO b/doc/TODO index 943919e..234dc2b 100644 --- a/doc/TODO +++ b/doc/TODO @@ -1,5 +1,3 @@ -Allow parameters in BKMK_ROBOT; for example, 'forking:urllib'. - A new robot based on urllib2. A new robot based on PycURL. diff --git a/robots.py b/robots.py index 3a0238d..3efb8f0 100644 --- a/robots.py +++ b/robots.py @@ -1,17 +1,20 @@ """Thin wrapper for module Robots. Provides "default" robot This file is a part of Bookmarks database and Internet robot. + """ __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 1997-2012 PhiloSoft Design" +__copyright__ = "Copyright (C) 1997-2014 PhiloSoft Design" __license__ = "GNU GPL" __all__ = ['import_robot', 'robot'] from os import environ -robot_name = environ.get("BKMK_ROBOT", "forking") +from bkmk_objects import parse_params, set_params + +robot_name, robot_params = parse_params(environ.get("BKMK_ROBOT", "forking")) def import_robot(robot_name): exec "from Robots import bkmk_r%s" % robot_name @@ -19,3 +22,4 @@ def import_robot(robot_name): return robot robot = import_robot(robot_name) +set_params(robot, robot_params) diff --git a/storage.py b/storage.py index 704fc7f..9c806e4 100644 --- a/storage.py +++ b/storage.py @@ -1,17 +1,20 @@ """Thin wrapper for module Storage. Provides "default" storage This file is a part of Bookmarks database and Internet robot. + """ __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 1997-2012 PhiloSoft Design" +__copyright__ = "Copyright (C) 1997-2014 PhiloSoft Design" __license__ = "GNU GPL" __all__ = ['import_storage', 'storage'] from os import environ -storage_name = environ.get("BKMK_STORAGE", "pickle") +from bkmk_objects import parse_params, set_params + +storage_name, storage_params = parse_params(environ.get("BKMK_STORAGE", "pickle")) def import_storage(storage_name): exec "from Storage import bkmk_st%s" % storage_name @@ -19,3 +22,4 @@ def import_storage(storage_name): return storage storage = import_storage(storage_name) +set_params(storage, storage_params) diff --git a/writers.py b/writers.py index 4240202..57d963c 100644 --- a/writers.py +++ b/writers.py @@ -1,17 +1,20 @@ """Thin wrapper for module Writers. Provides "default" writer This file is a part of Bookmarks database and Internet robot. + """ __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 1997-2012 PhiloSoft Design" +__copyright__ = "Copyright (C) 1997-2014 PhiloSoft Design" __license__ = "GNU GPL" __all__ = ['import_writer', 'writer'] from os import environ -writer_name = environ.get("BKMK_WRITER", "html") +from bkmk_objects import parse_params, set_params + +writer_name, writer_params = parse_params(environ.get("BKMK_WRITER", "html")) def import_writer(writer_name): exec "from Writers import bkmk_w%s" % writer_name @@ -19,3 +22,4 @@ def import_writer(writer_name): return writer writer = import_writer(writer_name) +set_params(writer, writer_params)