mdserver-web/plugins/solr/script/full.py

58 lines
1.6 KiB
Python
Raw Permalink Normal View History

2019-08-06 07:05:27 -04:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import MySQLdb as mdb
import random
import sys
import subprocess
import time
sys.path.append("/usr/local/lib/python2.7/site-packages")
2019-08-06 08:08:52 -04:00
conn = mdb.connect(host='0.0.0.0',
port=3306,
user='xxx',
passwd='xxx',
db='xxx',
charset='utf8')
2019-08-06 07:05:27 -04:00
conn.autocommit(True)
cursor = conn.cursor()
2019-08-06 08:08:52 -04:00
sql = 'select id from xxx order by id desc limit 1'
2019-08-06 07:05:27 -04:00
r = cursor.execute(sql)
count = 0
2019-08-06 08:08:52 -04:00
for info in cursor.fetchall():
2019-08-06 07:05:27 -04:00
count = info[0]
conn.close()
def execShell(cmdstring, cwd=None, timeout=None, shell=True):
if shell:
cmdstring_list = cmdstring
else:
cmdstring_list = shlex.split(cmdstring)
if timeout:
end_time = datetime.datetime.now() + datetime.timedelta(seconds=timeout)
sub = subprocess.Popen(cmdstring_list, cwd=cwd, stdin=subprocess.PIPE,
shell=shell, bufsize=4096, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while sub.poll() is None:
time.sleep(0.1)
if timeout:
if end_time <= datetime.datetime.now():
raise Exception("Timeout%s" % cmdstring)
return sub.communicate()
2019-08-06 10:24:15 -04:00
length = 100
2019-08-06 10:49:49 -04:00
for x in xrange(0, count / length + 1):
2019-08-06 10:24:15 -04:00
y = x * length
2019-08-06 10:49:37 -04:00
cmd = 'curl --basic -u admin:admin "http://127.0.0.1:8983/solr/sodht/dataimport?command=full-import&wt=json&clean=false&commit=true&length=' + \
str(length) + '&offset=' + str(y) + '"'
2019-08-06 08:08:52 -04:00
print execShell(cmd)
2019-08-06 11:35:39 -04:00
time.sleep(0.3)