diff options
author | Six <unknown> | 2010-05-20 20:37:56 -0400 |
---|---|---|
committer | Six <unknown> | 2010-05-20 20:37:56 -0400 |
commit | 099133ba43547600768b401699cb5b2f4c1f229b (patch) | |
tree | 3da613fc747468ac7f698da9ec4570a22b265adf /examples | |
parent | f005d4af39cb2c870b009b8b564748a348b80b40 (diff) | |
download | dodai-macsupport-099133ba43547600768b401699cb5b2f4c1f229b.tar.bz2 dodai-macsupport-099133ba43547600768b401699cb5b2f4c1f229b.tar.xz dodai-macsupport-099133ba43547600768b401699cb5b2f4c1f229b.zip |
changed examples for next release
Diffstat (limited to 'examples')
-rw-r--r-- | examples/config/config.cfg | 4 | ||||
-rw-r--r-- | examples/example_01.py | 36 | ||||
-rw-r--r-- | examples/example_02.py | 15 | ||||
-rw-r--r-- | examples/example_03.py | 13 |
4 files changed, 37 insertions, 31 deletions
diff --git a/examples/config/config.cfg b/examples/config/config.cfg index 36b0414..a99c4bd 100644 --- a/examples/config/config.cfg +++ b/examples/config/config.cfg | |||
@@ -27,3 +27,7 @@ username=test | |||
27 | password=test | 27 | password=test |
28 | port=12345 | 28 | port=12345 |
29 | database=testing | 29 | database=testing |
30 | |||
31 | [test_file_db] | ||
32 | protocol=sqlite | ||
33 | filename=test_file_db.sqlite | ||
diff --git a/examples/example_01.py b/examples/example_01.py index 7915e5f..d77c163 100644 --- a/examples/example_01.py +++ b/examples/example_01.py | |||
@@ -35,35 +35,29 @@ def main(config): | |||
35 | print config.__dict__ | 35 | print config.__dict__ |
36 | 36 | ||
37 | 37 | ||
38 | |||
39 | if __name__ == "__main__": | 38 | if __name__ == "__main__": |
40 | 39 | ||
41 | config = Config() | 40 | config = Config() |
42 | config.options().add_quiet() | 41 | config.options.add_quiet() |
43 | config.options().add_log_level() | 42 | config.options.add_log_level() |
44 | config.options().parser.add_option('-c', '--crazy', dest='crazy', | 43 | config.options.parser.add_option('-c', '--crazy', dest='crazy', |
45 | default=False, help="Crazy mode") | 44 | default=False, help="Crazy mode") |
46 | config.set('crazy', config.options().get_options().crazy) | 45 | config.set('crazy', config.options.get_options().crazy) |
47 | config.set('verbose', config.options().get_options().verbose) | 46 | config.set('verbose', config.options.get_options().verbose) |
48 | 47 | ||
49 | 48 | ||
50 | path = p.join(p.dirname(p.abspath(__file__)), 'logs') | 49 | log_directory = p.join(p.dirname(p.abspath(__file__)), 'config') |
51 | config.logs().set_directory(path) | 50 | config.logs.set_directory(log_directory) |
52 | config.logs().set_log_level(config.options().get_options().log_level) | 51 | config.logs.set_log_level(config.options.get_options().log_level) |
53 | log = config.logs().load(__file__) | 52 | log = config.logs.load('test_log') |
54 | config.logs().attach_file_handler(log, 'example.log') | 53 | config.logs.attach_file_handler(log, 'example.log') |
55 | config.logs().attach_screen_handler(log, 'critical') | 54 | config.logs.attach_screen_handler(log, 'critical') |
56 | config.set('log', log) | 55 | config.set('log', log) |
57 | 56 | ||
58 | 57 | ||
59 | path = p.join(p.dirname(p.abspath(__file__)), 'config') | 58 | path = p.join(p.dirname(p.abspath(__file__)), 'config') |
60 | config.files().set_directory(path) | 59 | filename = p.join(path, 'config.cfg') |
61 | config.files().load('config.cfg') | 60 | config.files.add(filename) |
62 | foo = config.files().parser().get('title', 'foo') | 61 | sections = config.files.load() |
63 | config.set('foo', foo) | 62 | config.set('foo', sections['title']['foo']) |
64 | |||
65 | |||
66 | |||
67 | |||
68 | |||
69 | main(config()) | 63 | main(config()) |
diff --git a/examples/example_02.py b/examples/example_02.py index 2844121..28ee179 100644 --- a/examples/example_02.py +++ b/examples/example_02.py | |||
@@ -43,15 +43,18 @@ from dodai.config import Config | |||
43 | 43 | ||
44 | def main(config): | 44 | def main(config): |
45 | print config.db.__dict__ | 45 | print config.db.__dict__ |
46 | print config.file_db.__dict__ | ||
46 | 47 | ||
47 | 48 | ||
48 | if __name__ == "__main__": | 49 | if __name__ == "__main__": |
49 | 50 | ||
50 | config = Config() | 51 | # path to config file |
51 | path = p.join(p.dirname(p.abspath(__file__)), 'config') | 52 | path = p.join(p.dirname(p.abspath(__file__)), 'config') |
52 | config.files().set_directory(path) | 53 | filename = p.join(path, 'config.cfg') |
53 | config.files().load('config.cfg') | 54 | |
54 | config.dbs().add_config(config_parser=config.files().parser()) | 55 | config = Config() |
55 | db = config.dbs().load('test_db') | 56 | config.files.add(filename) |
56 | config.set('db', db) | 57 | config.databases.add(config.files.load()) |
58 | config.set('db', config.databases.load('test_db')) | ||
59 | config.set('file_db', config.databases.load('test_file_db')) | ||
57 | main(config()) | 60 | main(config()) |
diff --git a/examples/example_03.py b/examples/example_03.py index b94c39e..da84eb8 100644 --- a/examples/example_03.py +++ b/examples/example_03.py | |||
@@ -38,7 +38,7 @@ On ubuntu you can do: | |||
38 | """ | 38 | """ |
39 | 39 | ||
40 | from dodai import Configure | 40 | from dodai import Configure |
41 | 41 | from dodai.tools import home_directory | |
42 | 42 | ||
43 | def main(config): | 43 | def main(config): |
44 | print config.db.engine | 44 | print config.db.engine |
@@ -47,8 +47,13 @@ def main(config): | |||
47 | 47 | ||
48 | if __name__ == "__main__": | 48 | if __name__ == "__main__": |
49 | 49 | ||
50 | config = Configure('test') | 50 | |
51 | db = config.dbs().load('test_db') | 51 | # path to config file |
52 | path = p.join(p.dirname(p.abspath(__file__)), 'config') | ||
53 | filename = p.join(path, 'config.cfg') | ||
54 | |||
55 | config = Configure('test', filename) | ||
56 | db = config.databases.load('test_db') | ||
52 | config.set('db', db) | 57 | config.set('db', db) |
53 | config.set('home_directory', config.home_directory) | 58 | config.set('home_directory', home_directory()) |
54 | main(config()) | 59 | main(config()) |