aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorSix <unknown>2010-04-10 17:05:55 -0400
committerSix <unknown>2010-04-10 17:05:55 -0400
commit418bb176021361f539fe5de13c6af0b316d8e4be (patch)
treebf2eb2bda93c523f739b7592d4d6bfd138e6641f /examples
downloaddodai-macsupport-418bb176021361f539fe5de13c6af0b316d8e4be.tar.bz2
dodai-macsupport-418bb176021361f539fe5de13c6af0b316d8e4be.tar.xz
dodai-macsupport-418bb176021361f539fe5de13c6af0b316d8e4be.zip
Initial import of source.
Diffstat (limited to 'examples')
-rw-r--r--examples/config/config.cfg29
-rw-r--r--examples/config/connect29
-rw-r--r--examples/example_01.py69
-rw-r--r--examples/example_02.py57
-rw-r--r--examples/example_03.py54
5 files changed, 238 insertions, 0 deletions
diff --git a/examples/config/config.cfg b/examples/config/config.cfg
new file mode 100644
index 0000000..36b0414
--- /dev/null
+++ b/examples/config/config.cfg
@@ -0,0 +1,29 @@
1# Copyright (C) 2010 Leonard Thomas
2#
3# This file is part of Dodai.
4#
5# Dodai is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# Dodai is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with Dodai. If not, see <http://www.gnu.org/licenses/>.
17
18
19[title]
20foo=bar
21
22
23[test_db]
24protocol=postgresql
25hostname=127.0.0.1
26username=test
27password=test
28port=12345
29database=testing
diff --git a/examples/config/connect b/examples/config/connect
new file mode 100644
index 0000000..36b0414
--- /dev/null
+++ b/examples/config/connect
@@ -0,0 +1,29 @@
1# Copyright (C) 2010 Leonard Thomas
2#
3# This file is part of Dodai.
4#
5# Dodai is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# Dodai is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with Dodai. If not, see <http://www.gnu.org/licenses/>.
17
18
19[title]
20foo=bar
21
22
23[test_db]
24protocol=postgresql
25hostname=127.0.0.1
26username=test
27password=test
28port=12345
29database=testing
diff --git a/examples/example_01.py b/examples/example_01.py
new file mode 100644
index 0000000..7915e5f
--- /dev/null
+++ b/examples/example_01.py
@@ -0,0 +1,69 @@
1#!/usr/bin/env python
2# Copyright (C) 2010 Leonard Thomas
3#
4# This file is part of Dodai.
5#
6# Dodai is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# Dodai is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with Dodai. If not, see <http://www.gnu.org/licenses/>.
18
19
20##############################################################################
21# The following is for setting up the correct python path. Ignore this
22# section for your project
23import sys
24import os.path as p
25path = p.dirname(p.dirname(p.abspath(__file__)))
26sys.path.append(path)
27##############################################################################
28
29from dodai.config import Config
30
31def main(config):
32
33 config.log.debug('testing one two three')
34 config.log.critical('testing of critical')
35 print config.__dict__
36
37
38
39if __name__ == "__main__":
40
41 config = Config()
42 config.options().add_quiet()
43 config.options().add_log_level()
44 config.options().parser.add_option('-c', '--crazy', dest='crazy',
45 default=False, help="Crazy mode")
46 config.set('crazy', config.options().get_options().crazy)
47 config.set('verbose', config.options().get_options().verbose)
48
49
50 path = p.join(p.dirname(p.abspath(__file__)), 'logs')
51 config.logs().set_directory(path)
52 config.logs().set_log_level(config.options().get_options().log_level)
53 log = config.logs().load(__file__)
54 config.logs().attach_file_handler(log, 'example.log')
55 config.logs().attach_screen_handler(log, 'critical')
56 config.set('log', log)
57
58
59 path = p.join(p.dirname(p.abspath(__file__)), 'config')
60 config.files().set_directory(path)
61 config.files().load('config.cfg')
62 foo = config.files().parser().get('title', 'foo')
63 config.set('foo', foo)
64
65
66
67
68
69 main(config())
diff --git a/examples/example_02.py b/examples/example_02.py
new file mode 100644
index 0000000..2844121
--- /dev/null
+++ b/examples/example_02.py
@@ -0,0 +1,57 @@
1#!/usr/bin/env python
2# Copyright (C) 2010 Leonard Thomas
3#
4# This file is part of dodai.
5#
6# dodai is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# Foobar is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with dodai. If not, see <http://www.gnu.org/licenses/>.
18
19
20##############################################################################
21# The following is for setting up the correct python path. Ignore this
22# section for your project
23import sys
24import os.path as p
25path = p.dirname(p.dirname(p.abspath(__file__)))
26sys.path.append(path)
27##############################################################################
28
29"""
30This example requires that you have sqlalchemy installed as well as the
31psycopg2 package.
32
33On ubuntu you can do:
34 apt-get install libpq-dev
35 easy_install psycopg2
36 easy_install sqlalchemy
37
38"""
39
40
41from dodai.config import Config
42
43
44def main(config):
45 print config.db.__dict__
46
47
48if __name__ == "__main__":
49
50 config = Config()
51 path = p.join(p.dirname(p.abspath(__file__)), 'config')
52 config.files().set_directory(path)
53 config.files().load('config.cfg')
54 config.dbs().add_config(config_parser=config.files().parser())
55 db = config.dbs().load('test_db')
56 config.set('db', db)
57 main(config())
diff --git a/examples/example_03.py b/examples/example_03.py
new file mode 100644
index 0000000..b94c39e
--- /dev/null
+++ b/examples/example_03.py
@@ -0,0 +1,54 @@
1#!/usr/bin/env python
2# Copyright (C) 2010 Leonard Thomas
3#
4# This file is part of dodai.
5#
6# dodai is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# Foobar is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with dodai. If not, see <http://www.gnu.org/licenses/>.
18
19
20##############################################################################
21# The following is for setting up the correct python path. Ignore this
22# section for your project
23import sys
24import os.path as p
25path = p.dirname(p.dirname(p.abspath(__file__)))
26sys.path.append(path)
27##############################################################################
28
29"""
30This example requires that you have sqlalchemy installed as well as the
31psycopg2 package.
32
33On ubuntu you can do:
34 apt-get install libpq-dev
35 easy_install psycopg2
36 easy_install sqlalchemy
37
38"""
39
40from dodai import Configure
41
42
43def main(config):
44 print config.db.engine
45 print config.db.session
46 print config.home_directory
47
48if __name__ == "__main__":
49
50 config = Configure('test')
51 db = config.dbs().load('test_db')
52 config.set('db', db)
53 config.set('home_directory', config.home_directory)
54 main(config())