author | Radek Brich <radek.brich@devl.cz> |
Tue, 16 Aug 2011 23:53:54 +0200 | |
changeset 10 | f3a1b9792cc9 |
child 11 | bc69eca59041 |
permissions | -rw-r--r-- |
10
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
1 |
from lxml import etree |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
2 |
from lxml import objectify |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
3 |
|
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
4 |
class Config: |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
5 |
def __init__(self): |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
6 |
self.tree = None |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
7 |
self.fname = None |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
8 |
|
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
9 |
|
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
10 |
def new(self, fname=None): |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
11 |
E = objectify.E |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
12 |
self.root = E.psqlconsole( |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
13 |
E.servers, |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
14 |
E.editor( |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
15 |
E.nodes( |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
16 |
E.node('-- Type your query here', name='Untitled', type='text'), |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
17 |
selected='Untitled' |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
18 |
) |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
19 |
), |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
20 |
E.window( |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
21 |
E.size( |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
22 |
E.width(800), |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
23 |
E.height(600) |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
24 |
), |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
25 |
E.dividers( |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
26 |
E.verticaldivider(300), |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
27 |
E.horizontaldivider(500), |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
28 |
E.editordivider(-1) |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
29 |
) |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
30 |
) |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
31 |
) |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
32 |
self.tree = etree.ElementTree(self.root) |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
33 |
self.servers = self.root.servers |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
34 |
self.fname = fname |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
35 |
|
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
36 |
|
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
37 |
def load(self, fname=None): |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
38 |
if fname: |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
39 |
self.fname = fname |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
40 |
self.tree = objectify.parse(self.fname) |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
41 |
self.root = self.tree.getroot() |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
42 |
self.servers = self.root.servers |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
43 |
|
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
44 |
|
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
45 |
def save(self, fname=None): |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
46 |
if fname: |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
47 |
self.fname = fname |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
48 |
self.tree.write( |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
49 |
self.fname, |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
50 |
encoding='utf-8', |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
51 |
xml_declaration=True, |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
52 |
pretty_print=True, |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
53 |
compression=6) |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
54 |
|
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
55 |
|
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
56 |
def add_server(self, name, host, port, user, password): |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
57 |
e = etree.SubElement(self.servers, 'server') |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
58 |
e.name = name |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
59 |
e.host = host |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
60 |
e.port = port |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
61 |
e.user = user |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
62 |
e.password = password |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
63 |
return e |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
64 |
|
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
65 |
|
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
66 |
cfg = Config() |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
67 |
|
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
68 |
|
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
69 |
if __name__ == '__main__': |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
70 |
cfg.load('../psqlconsole.xml.gz') |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
71 |
print cfg.root.servers.server[0].host.text |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
72 |
cfg.save() |
f3a1b9792cc9
Added pgconsole. It is my older project, a GUI query console. It uses GTK+ and asynchronous queries.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
73 |