Merge lp:~mallorymarcot/unifield-toolbox/shuf_xmlrpc into lp:unifield-toolbox

Proposed by Mallory MARCOT
Status: Needs review
Proposed branch: lp:~mallorymarcot/unifield-toolbox/shuf_xmlrpc
Merge into: lp:unifield-toolbox
Diff against target: 84 lines (+80/-0)
1 file modified
shuf.py (+80/-0)
To merge this branch: bzr merge lp:~mallorymarcot/unifield-toolbox/shuf_xmlrpc
Reviewer Review Type Date Requested Status
UniField Dev Team Pending
Review via email: mp+336032@code.launchpad.net
To post a comment you must log in.

Unmerged revisions

262. By Mallory MARCOT

adding shuf.py XMLRPC shell

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'shuf.py'
--- shuf.py 1970-01-01 00:00:00 +0000
+++ shuf.py 2018-01-12 10:48:36 +0000
@@ -0,0 +1,80 @@
1#-*- coding:utf-8 -*-
2import oerplib
3import argparse
4import re
5import subprocess
6
7
8DEFAULT_XMLRPC_PORT = 8069
9DEFAULT_SERVER = "localhost"
10RUNBOT_URL = "rb.unifield.org"
11
12
13parser = argparse.ArgumentParser()
14parser.add_argument("-s", "--server", default=DEFAULT_SERVER, help="Server URL (default: %s)" % DEFAULT_SERVER)
15parser.add_argument("-p", "--port", type=int, default=DEFAULT_XMLRPC_PORT, help="XMLRPC port to use (default: %s)" % DEFAULT_XMLRPC_PORT)
16parser.add_argument("-u", "--user", default="admin", help="Unifield user to connect to the database (default: admin)")
17parser.add_argument("-w", "--password", default="admin", help="Unifield password to connect to the database (default: admin)")
18parser.add_argument("-d", "--database", help="Target database")
19args = parser.parse_args()
20
21args.server = args.server.strip('/ ')
22
23if args.server.startswith('http://'):
24 args.server = args.server[7:]
25
26if args.server not in ('localhost', '127.0.0.1'):
27 # if only the user name of the RB is given, complete URL:
28 if args.server.find('.unifield.org') == -1:
29 server_url = args.server + '.' + RUNBOT_URL
30 url_choice = raw_input("Server URL = %s, use this value ? (y or n) " % server_url)
31 if url_choice.lower() in ('y', 'yes'):
32 args.server = server_url
33
34 # try to get the XMLRPC port from runbot:
35 port_found = False
36 try:
37 rb_name = args.server.split('.')[0]
38 cmd = "scp -q root@%s:/home/%s/RB_info.txt /tmp/%s_info.txt" % ('.'.join(args.server.split('.')[1:]), rb_name, rb_name)
39 subprocess.call(cmd.split(" "))
40 fich = open("/tmp/%s_info.txt" % rb_name)
41 content = fich.read()
42 line = re.search(r'XML-RPC port.*', content).group()
43 port_found = int(line.split(' ')[-1])
44 fich.close()
45 except:
46 pass
47 if port_found and port_found != args.port:
48 port_choice = raw_input("Auto XMLRPC port = %s, use this value ? (y or n) " % port_found)
49 if port_choice.lower() in ('y', 'yes'):
50 args.port = port_found
51
52
53print "Connecting to %s on port %s ..." % (args.server, args.port),
54oerp = oerplib.OERP(server=args.server, protocol='xmlrpc', port=args.port, timeout=3600, version='6.0')
55print "done"
56
57# if target database not given, list all dbs and ask user to choose:
58if not args.database:
59 if not oerp.db.list():
60 print "No database found."
61 exit(1)
62 print "Target database:"
63 i = 1
64 for db in oerp.db.list():
65 print "\t%s) %s" % (i, db)
66 i += 1
67 input_ok = False
68 while not input_ok:
69 db_choice = raw_input("Your choice ? ")
70 try:
71 db_choice = int(db_choice)
72 except:
73 continue
74 if db_choice > 0 and db_choice <= len(oerp.db.list()):
75 input_ok = True
76 args.database = oerp.db.list()[db_choice-1]
77
78print "Logging as %s on %s ..." % (args.user, args.database),
79user = oerp.login(args.user, args.password, args.database)
80print "done"

Subscribers

People subscribed via source and target branches