~ubuntu-branches/ubuntu/trusty/openerp-client/trusty

« back to all changes in this revision

Viewing changes to bin/environment_info.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-08-24 20:13:33 UTC
  • mfrom: (1.2.1 upstream) (10.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090824201333-7wxq9q81a7qke0w2
Tags: 5.0.3-0-1
* Updating package to standards version 3.8.3.
* Adding maintainer homepage field to control.
* Marking maintainer homepage field to be also included in binary
  packages and changelog.
* Merging upstream version 5.0.3-0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
import sys
 
3
import platform
 
4
import locale
 
5
import optparse
 
6
import xmlrpclib
 
7
import release
 
8
import tools
 
9
class environment(object):
 
10
    def __init__(self, login, password, dbname, host='localhost', port=8069):
 
11
        self.login = login
 
12
        self.passwd = password
 
13
        self.db = dbname
 
14
        self.host = host
 
15
        self.port = port
 
16
 
 
17
    def get_with_server_info(self):
 
18
        try:
 
19
            login_socket = xmlrpclib.ServerProxy('http://%s:%s/xmlrpc/common' % (self.host, self.port))
 
20
            self.uid = login_socket.login(self.db, self.login, self.passwd)
 
21
            if self.uid:
 
22
                print login_socket.get_server_environment() + self.get_client_info()
 
23
                login_socket.logout(self.db, self.login, self.passwd)
 
24
            else:
 
25
                print "bad login or password from "+self.login+" using database "+self.db
 
26
        except Exception,e:
 
27
                print e
 
28
        return True
 
29
 
 
30
    def get_client_info(self):
 
31
        try:
 
32
            rev_id = os.popen('bzr revision-info').read()
 
33
            if not rev_id:
 
34
                rev_id = 'Bazaar Package not Found !'
 
35
        except Exception,e:
 
36
            rev_id = 'Exception: %s\n' % (tools.ustr(e))
 
37
        environment = 'OpenERP-Client Version : %s\n'\
 
38
                      'Last revision No. & ID :%s'\
 
39
                      %(release.version,rev_id)
 
40
        return environment
 
41
 
 
42
if __name__=="__main__":
 
43
    uses ="""%prog [options]
 
44
 
 
45
Note:
 
46
    This script will provide you the full environment information of OpenERP-Client
 
47
    If login,password and database are given then it will also give OpenERP-Server Information
 
48
 
 
49
Examples:
 
50
[1] python environment_info.py
 
51
[2] python environment_info.py -l admin -p admin -d test
 
52
"""
 
53
 
 
54
    parser = optparse.OptionParser(uses)
 
55
 
 
56
    parser.add_option("-l", "--login", dest="login", help="Login of the user in Open ERP")
 
57
    parser.add_option("-p", "--password", dest="password", help="Password of the user in Open ERP")
 
58
    parser.add_option("-d", "--database", dest="dbname", help="Database name")
 
59
    parser.add_option("-P", "--port", dest="port", help="Port",default=8069)
 
60
    parser.add_option("-H", "--host", dest="host", help="Host",default='localhost')
 
61
 
 
62
    (options, args) = parser.parse_args()
 
63
    parser = environment(options.login, options.password, dbname = options.dbname, host = options.host, port = options.port)
 
64
    if not(options.login and options.password and options.dbname):
 
65
        client_info = parser.get_client_info()
 
66
 
 
67
        os_lang = '.'.join( [x for x in locale.getdefaultlocale() if x] )
 
68
        if not os_lang:
 
69
            os_lang = 'NOT SET'
 
70
 
 
71
        environment = '\nEnvironment Information : \n' \
 
72
                     'System : %s\n' \
 
73
                     'OS Name : %s\n' \
 
74
                     %(platform.platform(), platform.os.name)
 
75
        if os.name == 'posix':
 
76
          if platform.system() == 'Linux':
 
77
             lsbinfo = os.popen('lsb_release -a').read()
 
78
             environment += '%s'%(lsbinfo)
 
79
          else:
 
80
             environment += 'Your System is not lsb compliant\n'
 
81
        environment += 'Operating System Release : %s\n' \
 
82
                    'Operating System Version : %s\n' \
 
83
                    'Operating System Architecture : %s\n' \
 
84
                    'Operating System Locale : %s\n'\
 
85
                    'Python Version : %s\n'\
 
86
                    %(platform.release(), platform.version(), platform.architecture()[0],
 
87
                      os_lang, platform.python_version())
 
88
 
 
89
        print environment + client_info
 
90
        print '\nFor server Information you need to pass database(-d), login(-l),password(-p)'
 
91
        sys.exit(1)
 
92
 
 
93
    else:
 
94
        parser.get_with_server_info()