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

Subscribers

People subscribed via source and target branches