def __init__(self, keepalive_interval=5, keepalive_count=5): self.keepalive_interval = keepalive_interval self.keepalive_count = keepalive_count # connection dict # maps hostnames to a list of connection objects for this hostname # atm it is possible to create more than one connection per hostname # with different logins or auth methods # connections are shared between all threads, see: # http://wiki.libvirt.org/page/FAQ#Is_libvirt_thread_safe.3F self._connections = dict() self._connections_lock = ReadWriteLock() # start event loop to handle keepalive requests and other events self._event_loop = wvmEventLoop() self._event_loop.start()
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_Dialog() # Ui_Dialog为.ui产生.py文件中窗体类名 self.ui.setupUi(self) self.ui.input.clicked.connect(self.input) self.ui.output.clicked.connect(self.output) self.ui.clear.clicked.connect(self.clear) self.ui.start.clicked.connect(self.start) self.ui.stop.clicked.connect(self.stop) self.queue = Queue.Queue() self.ip_lock = ReadWriteLock() self.dirty = False self.pid = None self.address = self.ui.address.text().__str__() self.username = self.ui.username.text().__str__() self.password = self.ui.password.text().__str__() threading.Thread(target=self.change_ip).start() for i in range(1): threading.Thread(target=self.login_thread).start()
class wvmConnectionManager(object): def __init__(self, keepalive_interval=5, keepalive_count=5): self.keepalive_interval = keepalive_interval self.keepalive_count = keepalive_count # connection dict # maps hostnames to a list of connection objects for this hostname # atm it is possible to create more than one connection per hostname # with different logins or auth methods # connections are shared between all threads, see: # http://wiki.libvirt.org/page/FAQ#Is_libvirt_thread_safe.3F self._connections = dict() self._connections_lock = ReadWriteLock() # start event loop to handle keepalive requests and other events self._event_loop = wvmEventLoop() self._event_loop.start() def _search_connection(self, host, login, passwd, conn): """ search the connection dict for a connection with the given credentials if it does not exist return None """ self._connections_lock.acquireRead() try: if (host in self._connections): connections = self._connections[host] for connection in connections: if (connection.login == login and connection.passwd == passwd and connection.type == conn): return connection finally: self._connections_lock.release() return None def get_connection(self, host, login, passwd, conn): """ returns a connection object (as returned by the libvirt.open* methods) for the given host and credentials raises libvirtError if (re)connecting fails """ # force all string values to unicode host = unicode(host) login = unicode(login) passwd = unicode(passwd) if passwd is not None else None connection = self._search_connection(host, login, passwd, conn) if (connection is None): self._connections_lock.acquireWrite() try: # we have to search for the connection again after aquireing the write lock # as the thread previously holding the write lock may have already added our connection connection = self._search_connection(host, login, passwd, conn) if (connection is None): # create a new connection if a matching connection does not already exist connection = wvmConnection(host, login, passwd, conn) # add new connection to connection dict if host in self._connections: self._connections[host].append(connection) else: self._connections[host] = [connection] finally: self._connections_lock.release() elif not connection.connected: # try to (re-)connect if connection is closed connection.connect() if connection.connected: # return libvirt connection object return connection.connection else: # raise libvirt error raise libvirtError(connection.last_error) def host_is_up(self, conn_type, hostname): """ returns True if the given host is up and we are able to establish a connection using the given credentials. """ try: socket_host = socket.socket(socket.AF_INET, socket.SOCK_STREAM) socket_host.settimeout(1) if conn_type == CONN_SSH: if ':' in hostname: LIBVIRT_HOST, PORT = (hostname).split(":") PORT = int(PORT) else: PORT = SSH_PORT LIBVIRT_HOST = hostname socket_host.connect((LIBVIRT_HOST, PORT)) if conn_type == CONN_TCP: socket_host.connect((hostname, TCP_PORT)) if conn_type == CONN_TLS: socket_host.connect((hostname, TLS_PORT)) socket_host.close() return True except Exception as err: return err
class wvmConnectionManager(object): def __init__(self, keepalive_interval=5, keepalive_count=5): self.keepalive_interval = keepalive_interval self.keepalive_count = keepalive_count # connection dict # maps hostnames to a list of connection objects for this hostname # atm it is possible to create more than one connection per hostname # with different logins or auth methods # connections are shared between all threads, see: # http://wiki.libvirt.org/page/FAQ#Is_libvirt_thread_safe.3F self._connections = dict() self._connections_lock = ReadWriteLock() # start event loop to handle keepalive requests and other events self._event_loop = wvmEventLoop() self._event_loop.start() def _search_connection(self, host, login, passwd, conn, hypervisor): """ search the connection dict for a connection with the given credentials if it does not exist return None """ self._connections_lock.acquireRead() try: if (host in self._connections): connections = self._connections[host] for connection in connections: if (connection.login == login and connection.passwd == passwd and connection.type == conn and connection.hypervisor == hypervisor): return connection finally: self._connections_lock.release() return None def get_connection(self, host, login, passwd, conn, hypervisor): """ returns a connection object (as returned by the libvirt.open* methods) for the given host and credentials raises libvirtError if (re)connecting fails """ # force all string values to unicode host = unicode(host) login = unicode(login) passwd = unicode(passwd) if passwd is not None else None connection = self._search_connection(host, login, passwd, conn, hypervisor) if (connection is None): self._connections_lock.acquireWrite() try: # we have to search for the connection again after aquireing the write lock # as the thread previously holding the write lock may have already added our connection connection = self._search_connection(host, login, passwd, conn, hypervisor) if (connection is None): # create a new connection if a matching connection does not already exist connection = wvmConnection(host, login, passwd, conn, hypervisor) # add new connection to connection dict if host in self._connections: self._connections[host].append(connection) else: self._connections[host] = [connection] finally: self._connections_lock.release() elif not connection.connected: # try to (re-)connect if connection is closed connection.connect() if connection.connected: # return libvirt connection object return connection.connection else: # raise libvirt error raise libvirtError(connection.last_error) def host_is_up(self, conn_type, hostname): """ returns True if the given host is up and we are able to establish a connection using the given credentials. """ try: socket_host = socket.socket(socket.AF_INET, socket.SOCK_STREAM) socket_host.settimeout(1) if conn_type == CONN_SSH: if ':' in hostname: LIBVIRT_HOST, PORT = (hostname).split(":") PORT = int(PORT) else: PORT = SSH_PORT LIBVIRT_HOST = hostname socket_host.connect((LIBVIRT_HOST, PORT)) if conn_type == CONN_TCP: socket_host.connect((hostname, TCP_PORT)) if conn_type == CONN_TLS: socket_host.connect((hostname, TLS_PORT)) socket_host.close() return True except Exception as err: return err
import uprclindex from uprclhttp import runbottle import minimconfig from upmplgutils import uplog from uprclutils import findmyip from conftree import stringToStrings # Once initialization (not on imports) try: _s = g_httphp except: # The recoll documents g_pathprefix = "" g_httphp = "" g_dblock = ReadWriteLock() g_rclconfdir = "" g_friendlyname = "UpMpd-mediaserver" g_trees = {} g_trees_order = ['folders', 'playlists', 'tags', 'untagged'] g_minimconfig = None def _reset_index(): _update_index(True) # Create or update Recoll index, then read and process the data. This # runs in the separate uprcl_init_worker thread, and signals # startup/completion by setting/unsetting the g_initrunning flag def _update_index(rebuild=False):
class MainWindow(QtGui.QDialog): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_Dialog() # Ui_Dialog为.ui产生.py文件中窗体类名 self.ui.setupUi(self) self.ui.input.clicked.connect(self.input) self.ui.output.clicked.connect(self.output) self.ui.clear.clicked.connect(self.clear) self.ui.start.clicked.connect(self.start) self.ui.stop.clicked.connect(self.stop) self.queue = Queue.Queue() self.ip_lock = ReadWriteLock() self.dirty = False self.pid = None self.address = self.ui.address.text().__str__() self.username = self.ui.username.text().__str__() self.password = self.ui.password.text().__str__() threading.Thread(target=self.change_ip).start() for i in range(1): threading.Thread(target=self.login_thread).start() # self.encrpy=vvv8.Enerypt_58() @QtCore.pyqtSlot() def start(self): self.dirty = True while self.dirty is True: time.sleep(1) threading.Thread(target=self.start1).start() def start1(self): # pool=threadpool.ThreadPool(10) # if self.ui.checkBox.checkState() == 2: # order=self.ui.order.text().__str__() # self.apiUrl = "http://api.ip.data5u.com/dynamic/get.html?order=" + order # else: # self.apiUrl=None self.new_pwd = self.ui.lineEdit_6.text().__str__() for i in range(self.ui.tableWidget.rowCount()): self.queue.put(i) # for i in range(self.ui.tableWidget.rowCount()): # threading.Thread(target=self.get_ip).start() # reqs = threadpool.makeRequests(self.logining, range(self.ui.tableWidget.rowCount())) # [pool.putRequest(req) for req in reqs] # pool.wait() # def get_ip(self): # while self.apiUrl: # # res = urllib.urlopen(self.apiUrl).read().strip("\n") # # 按照\n分割获取到的IP # ips = res.split("\n") # # 随机选择一个IP # proxy = ips[0] # if check_proxy.proxy_check(proxy) is True: # self.queue.put(proxy) def change_ip(self): while True: if self.dirty is True: self.ip_lock.acquire_write() if self.pid is not None: win32ras.HangUp(self.pid) time.sleep(3) self.pid, ret = win32ras.Dial( None, None, ('vpn', self.address, "", self.username, self.password, ""), None) print self.pid, ret # if ret==0: # QtGui.QMessageBox.information(self, u"连接", u'连接vpn') # else # QtGui.QMessageBox.information(self, u"连接", u'连接vpn错误') self.dirty = False self.ip_lock.release_write() time.sleep(1) def login_thread(self): while True: i = self.queue.get() self.logining(i) def logining(self, i): while self.dirty is True: time.sleep(1) self.ip_lock.acquire_read() try: # i=self.queue.get() account = self.ui.tableWidget.item(i, 0).text().__str__() password = self.ui.tableWidget.item(i, 1).text().__str__() print account, password # time.sleep(5) try: a = Login_58(account, password) login_re = a.login() # if login_re['code']in (0,1,3): # self.queue.put(proxy) except: # self.logining(i) # return login_re = {'code': 2, "msg": "u连接错误"} if login_re['code'] is 0: self.ui.tableWidget.setItem(i, 2, QtGui.QTableWidgetItem(u"登录成功")) auth = a.get_auth() if auth: if auth[3] is True: self.ui.tableWidget.setItem( i, 6, QtGui.QTableWidgetItem(u"已认证")) else: self.ui.tableWidget.setItem( i, 6, QtGui.QTableWidgetItem(u"未认证")) if auth[0] is True: self.ui.tableWidget.setItem( i, 3, QtGui.QTableWidgetItem(u"已认证")) else: self.ui.tableWidget.setItem( i, 3, QtGui.QTableWidgetItem(u"未认证")) if auth[2] is True: self.ui.tableWidget.setItem( i, 4, QtGui.QTableWidgetItem(u"已认证")) else: self.ui.tableWidget.setItem( i, 4, QtGui.QTableWidgetItem(u"未认证")) if (auth[100] and auth[500] and auth[501]) is True: self.ui.tableWidget.setItem( i, 5, QtGui.QTableWidgetItem(u"已认证")) else: self.ui.tableWidget.setItem( i, 5, QtGui.QTableWidgetItem(u"未认证")) print auth money = a.get_money() if money: self.ui.tableWidget.setItem( i, 7, QtGui.QTableWidgetItem(str(money))) if self.new_pwd: pwd_modify = a.modify_password(self.new_pwd) if pwd_modify is True: self.ui.tableWidget.setItem( i, 8, QtGui.QTableWidgetItem(u"修改密码成功")) else: self.ui.tableWidget.setItem( i, 8, QtGui.QTableWidgetItem(pwd_modify)) else: if login_re["code"] == 2: self.dirty = True self.ip_lock.release_read() # self.ui.tableWidget.setItem(i, 2, QtGui.QTableWidgetItem(login_re["msg"])) self.queue.put(i) return self.ui.tableWidget.setItem( i, 2, QtGui.QTableWidgetItem(login_re["msg"])) finally: self.ip_lock.release_read() @QtCore.pyqtSlot() def stop(self): pass @QtCore.pyqtSlot() def input(self): dialog = QtGui.QDialog() ui = select_dialog.Ui_Dialog() ui.setupUi(dialog) ui.accept.clicked.connect(dialog.accept) ui.cancle.clicked.connect(dialog.reject) path = QtGui.QFileDialog().getOpenFileName() data = [] for line in open(path.__str__()).readlines(): line = line.decode('utf-8') data.append(line.strip().split('----')) col_num = len(data[0]) ui.treeWidget.setColumnCount(col_num) ui.treeWidget.setColumnWidth(0, 200) for item in data: it = QtGui.QTreeWidgetItem(item) ui.treeWidget.addTopLevelItem(it) if dialog.exec_(): # print ui.account_col account_col = int(ui.account_col.text().__str__()) pwd_col = int(ui.password_col.text().__str__()) print account_col, pwd_col for item in data: row = self.ui.tableWidget.rowCount() self.ui.tableWidget.insertRow(row) self.ui.tableWidget.setItem( row, 0, QtGui.QTableWidgetItem(item[account_col])) self.ui.tableWidget.setItem( row, 1, QtGui.QTableWidgetItem(item[pwd_col])) dialog.destroy() @QtCore.pyqtSlot() def output(self): if self.ui.tableWidget.rowCount() == 0: QtGui.QMessageBox.information(self, u"导出", u'没有数据') return path = QtGui.QFileDialog().getSaveFileName() try: with open(path, 'wb') as ff: for i in range(self.ui.tableWidget.rowCount()): for j in range(self.ui.tableWidget.columnCount()): item = self.ui.tableWidget.item(i, j) if item: ff.write(item.text().__str__()) else: ff.write('') ff.write('----') ff.write('\n') except: QtGui.QMessageBox.information(self, u"导出", u'导出失败') return QtGui.QMessageBox.information(self, u"导出", u'导出成功') @QtCore.pyqtSlot() def clear(self): while self.ui.tableWidget.rowCount() > 0: self.ui.tableWidget.removeRow(0)