Skip to content

Commit

Permalink
Save db_index in session file
Browse files Browse the repository at this point in the history
  • Loading branch information
katyukha committed Apr 8, 2016
1 parent fab82dd commit e27a9f2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
17 changes: 13 additions & 4 deletions openerp_proxy/ext/repr/__init__.py
Expand Up @@ -29,13 +29,22 @@
from .generic import (FieldNotFoundException,
HField,
toHField,
# PrettyTable,
# BaseTable,
PrettyTable,
BaseTable,
HTMLTable)

# import submodules
import orm
import reports
from .orm import *
from .reports import *

__all__ = (
'FieldNotFoundException',
'HField',
'toHField',
'PrettyTable',
'BaseTable',
'HTMLTable',
)


class ClientRegistedObjects(list):
Expand Down
3 changes: 2 additions & 1 deletion openerp_proxy/main.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf8 -*-

import operator

HELP_HEADER = """
Usage:
Expand Down Expand Up @@ -41,7 +42,7 @@ def generate_header_databases(session):
""" Prepare to display history of database connections
"""
header_databases = "\n"
for index, url in session.index.items():
for index, url in sorted(session.index.items(), key=operator.itemgetter(0)):
header_databases += " - [%3s] %s\n" % (index, url)
return header_databases

Expand Down
13 changes: 11 additions & 2 deletions openerp_proxy/session.py
Expand Up @@ -17,7 +17,8 @@


class SessionClientExt(Client):
""" Simple Client extension to add attribute '_no_save' used in session
""" Simple Client extension to add attribute '_no_save'
used in session
"""
def __init__(self, *args, **kwargs):
super(SessionClientExt, self).__init__(*args, **kwargs)
Expand Down Expand Up @@ -56,7 +57,7 @@ def __init__(self, data_file='~/.openerp_proxy.json'):

self._db_index = {} # key: index; value: url
self._db_index_rev = {} # key: url; value: index
self._db_index_counter = 0
self._db_index_counter = 0 # max index used

if os.path.exists(self.data_file):
data = json_read(self.data_file)
Expand All @@ -65,6 +66,13 @@ def __init__(self, data_file='~/.openerp_proxy.json'):
self._db_aliases = data.get('aliases', {})
self._options = data.get('options', {})

if 'index' in data:
for url, index in data['index'].items():
if url in self._databases:
self._db_index[index] = url
self._db_index_rev[url] = index
self._db_index_counter = max(self._db_index_counter, index)

for path in self.extra_paths:
self.add_path(path)

Expand Down Expand Up @@ -352,6 +360,7 @@ def save(self):
'databases': databases,
'aliases': self._db_aliases,
'options': self._options,
'index': self._db_index_rev,
}

json_write(self.data_file, data, indent=4)
Expand Down

0 comments on commit e27a9f2

Please sign in to comment.