コード例 #1
0
    def parse(self, html):
        root = etree.HTML(html)
        all_urls = root.xpath('//*[@id="shop-all-list"]/ul/li/div[1]/a["href"]/text()')

        for url in all_urls:
            log.info(url)
            self.queue.put((url, False))
コード例 #2
0
 def update_stock_list_to_file(self, filename=''):
     df = self.get_all_stock_list_form_network()
     if filename == '':
         filename = data_path + 'bs_stock_list.csv'
     if df.empty is False:
         log.info('save to' + filename)
         df.to_csv(filename, encoding="gbk", index=False)
コード例 #3
0
	def client_send(self):
		#hello = 10
		hello = int(self.response)
		#print "respone.....",type(self.response)
		print "hello.....",type(hello)
		#print hello
		data = str(transnit_data(self.filename).data_collect())
		data_do = transnit_data(self.filename).data_collect()
		try:
			print data
			print "host is :",self.host
			print "port is :",self.port
			logging.info("Miontor agent started Successfully!")
			while True:
				self.do_working(data_do)
				try:
					host = self.host
					port = self.port
					s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
					s.connect((host,int(port)))
					logging.info(("Miontor agent has been successfully connected to the server!!"))
					s.sendall(data)
					logging.debug(data)
					buf = s.recv(8092)
					if not len(data): break
					s.close()
				except:
					logging.error('socket.error: [Errno 111] Connection refused')
					continue
				finally:
					time.sleep(hello)
		except:
			logging.error('The socket connect to the server failed!!!')
コード例 #4
0
    def get_real_data_by_skobj(self, skobjs):
        codes = []
        codes_future = []
        for sk in skobjs:
            if sk.code[:2] == 'sh' or sk.code[:2] == 'sz':
                codes.append(sk.code)
            else:
                codes_future.append(sk.code)
        df = srt.get_real_time_data(codes)
        df_future = srt.get_future_real_time_data(codes_future)

        if df is None and df_future is None:
            log.info('df is None')
            return False
        if df is not None:
            for code in df['code']:
                data = df[df['code'] == code]
                data = data.reset_index().T.to_dict()[0]
                sk = self.get_stock_obj(code)
                if sk is not None:
                    sk.set_data(data)
        if df_future is not None:
            for code in df_future['code']:
                data = df_future[df_future['code'] == code]
                data = data.reset_index().T.to_dict()[0]
                sk = self.get_stock_obj(code)
                if sk is not None:
                    sk.set_data(data)
        return True
コード例 #5
0
ファイル: common_data.py プロジェクト: yhy121949/yhy121
 def func(*args, **kwargs):
     com_data = CommonData()
     send_request = args[0]
     if len(args
            ) == 1 and "post_process" in kwargs and "pre_process" in kwargs:
         com_data.pre_process = kwargs["pre_process"]
         com_data.post_process = kwargs["post_process"]
     elif len(args) == 2 and "post_process" in kwargs:
         com_data.pre_process = args[1]
         com_data.post_process = kwargs["post_process"]
     elif len(args) == 3:
         com_data.pre_process = args[1]
         com_data.post_process = args[2]
     else:
         assert False, "send_request方法缺少必要参数"
     pre_process = json.loads(
         com_data.get_json_pre_or_post(send_request, "pre_process"))
     post_process = json.loads(
         com_data.get_json_pre_or_post(send_request, "post_process"))
     post_process.extend(com_data.post_process if isinstance(
         com_data.post_process, list) else [])
     pre_process.extend(com_data.pre_process if isinstance(
         com_data.pre_process, list) else [])
     com_data.post_process = post_process
     com_data.pre_process = pre_process
     log.info("------------------执行前置步骤------------------")
     com_data.update_request(send_request)
     res = function(*args, **kwargs)
     log.info("-----------------执行后置操作-------------------")
     com_data.excute_post(send_request)
     log.debug("全部变量:{}".format(send_request.local_var))
     return res
コード例 #6
0
def test():
    # 实例化,修改日志文件名称,加载新配置
    xxx = log.Log()
    xxx.log_filename = 'test_log.log'
    xxx.log_config()
    # 测试
    log.debug('This is debug message')
    log.info('This is info message')
    log.warning('This is warning message')
コード例 #7
0
ファイル: pipeline.py プロジェクト: pighui/dianping_zz
 def save(self, **item):
     with open(self.csv_filename, 'a', encoding='utf-8') as f:
         writer = csv.DictWriter(f, fieldnames=item.keys())
         if not self.existed_header:
             writer.writeheader()
             self.existed_header = True
         writer.writerow(item)
     log.info('保存OK', item)
     return item
コード例 #8
0
ファイル: action_kvm.py プロジェクト: wangyouyan/OpenStack
def closeConnection(conn):
	try:
		conn.close()
	except:
		print('Failed to close the connection.')
		logging.error('Failed to close the connection.')
		return 1
	
	print('Connection is closed...')
	logging.info('Connection is closed...')
コード例 #9
0
ファイル: action_kvm.py プロジェクト: wangyouyan/OpenStack
def closeConnection(conn):
    try:
        conn.close()
    except:
        print('Failed to close the connection.')
        logging.error('Failed to close the connection.')
        return 1

    print('Connection is closed...')
    logging.info('Connection is closed...')
コード例 #10
0
 def run(self):
     while True:
         try:
             url, flag = self.queue.get(timeout=60)
             log.info('downloading %s' % url)
             self.download(url, flag)
             time.sleep(1)
         except Exception as e:
             log.error(e)
             break
コード例 #11
0
ファイル: action_kvm.py プロジェクト: wangyouyan/OpenStack
def createConnection():
	conn = libvirt.open('qemu:///system')
	if conn == None:
		print('Failed to open connection to qemu:///system',file=sys.stderr)
		logging.error('Failed to open connection to qemu:///system',file=sys.stderr)
		exit(1)

	else:
		print('--Connection is created successfully--')
		logging.info('--Connection is created successfully--')
	return conn
コード例 #12
0
ファイル: action_kvm.py プロジェクト: wangyouyan/OpenStack
def createConnection():
    conn = libvirt.open('qemu:///system')
    if conn == None:
        print('Failed to open connection to qemu:///system', file=sys.stderr)
        logging.error('Failed to open connection to qemu:///system',
                      file=sys.stderr)
        exit(1)

    else:
        print('--Connection is created successfully--')
        logging.info('--Connection is created successfully--')
    return conn
コード例 #13
0
ファイル: action_kvm.py プロジェクト: wangyouyan/OpenStack
def resetDom(conn, ID):
    print('---Reset Domin status-----')
    logging.info('---Reset Domin status-----')
    dom = conn.lookupByID(ID)
    try:
        dom.reset()
        print('Dom %s State %s' % (dom.name(), dom.info()[0]))
        logging.info('Dom %s State %s' % (dom.name(), dom.info()[0]))
        return 0
    except:
        print('Dom %s reset failed...' % dom.name())
        logging.error('Dom %s reset failed...' % dom.name())
        return 1
コード例 #14
0
ファイル: action_kvm.py プロジェクト: wangyouyan/OpenStack
def resetDom(conn,ID):
	print('---Reset Domin status-----')
	logging.info('---Reset Domin status-----')
        dom = conn.lookupByID(ID)
        try:
                dom.reset()
                print('Dom %s State %s' %(dom.name(),dom.info()[0]))
                logging.info('Dom %s State %s' %(dom.name(),dom.info()[0]))
                return 0
        except:
                print('Dom %s reset failed...' % dom.name())
                logging.error('Dom %s reset failed...' % dom.name())
                return 1
コード例 #15
0
ファイル: action_kvm.py プロジェクト: wangyouyan/OpenStack
def shutdownDomaction(conn, ID):
    print('----Shutdown domain info by ID -----')
    logging.debug('----Shutdown domain info by ID -----')
    dom = conn.lookupByID(ID)
    try:
        dom.destroy()
        print('Dom %s State %s' % (dom.name(), dom.info()[0]))
        logging.info('Dom %s State %s' % (dom.name(), dom.info()[0]))
        return 0
    except:
        print('Dom %s shutdown failed...' % dom.name())
        logging.error('Dom %s shutdown failed...' % dom.name())
        return 1
コード例 #16
0
ファイル: action_kvm.py プロジェクト: wangyouyan/OpenStack
def startDomaction(conn, name):
    print('----Start domain info by Name -----')
    logging.debug('----Start domain info by Name -----')
    dom = conn.lookupByName(name)
    try:
        dom.create()
        print('Dome %s boot sucessfully' % dom.name())
        logging.info('Dome %s boot sucessfully' % dom.name())
        return 0
    except:
        print('Dome %s boot failed' % dom.name())
        logging.error('Dome %s boot failed' % dom.name())
        return 1
コード例 #17
0
ファイル: action_kvm.py プロジェクト: wangyouyan/OpenStack
def startDomaction(conn,name):
        print('----Start domain info by Name -----')
        logging.debug('----Start domain info by Name -----')
        dom = conn.lookupByName(name)
        try:
		dom.create()
		print('Dome %s boot sucessfully' %dom.name())
		logging.info('Dome %s boot sucessfully'%dom.name())
		return 0
	except:
		print('Dome %s boot failed' %dom.name())
		logging.error('Dome %s boot failed' %dom.name())
		return 1
コード例 #18
0
ファイル: action_kvm.py プロジェクト: wangyouyan/OpenStack
def shutdownDomaction(conn,ID):
	print('----Shutdown domain info by ID -----')
	logging.debug('----Shutdown domain info by ID -----')
	dom = conn.lookupByID(ID)
	try:
		dom.destroy()
		print('Dom %s State %s' %(dom.name(),dom.info()[0]))
		logging.info('Dom %s State %s' %(dom.name(),dom.info()[0]))
		return 0
	except:
		print('Dom %s shutdown failed...' % dom.name())
		logging.error('Dom %s shutdown failed...' % dom.name())
		return 1	
コード例 #19
0
    def write_json_file(component_dict, json_filename):
        close_file = False
        json_env_string = None
        json_component_string = None

        # Attempt to remove any previous files, if none exists just eat the error
        try:
            os.remove(json_filename)
        except OSError:
            pass
        log.debug("evaluating components to generate %s" % json_filename)
        for component in component_dict.keys():
            for key, version in component_dict[component].iteritems():
                if key == "component_env_version":
                    if "component" in json_filename:
                        json_env_string = '"env_version":{"current":"%s","new":"%s"}}' % (
                            version[1], version[0])
                    else:
                        json_env_string = '"env_version":{"current":"%s","new":"%s"}}' % (
                            version[0], version[0])
                if key == "component_version":
                    if "component" in json_filename:
                        json_component_string = '"%s":{"version":{"current":"%s","new":"%s"}' % (
                            component, version[1], version[0])
                    else:
                        json_component_string = '"%s":{"version":{"current":"%s","new":"%s"}' % (
                            component, version[0], version[0])
            # This section sets the type to ACS if the component is found in the static mapping
            if component in acs.component.CMPS:
                if json_env_string is not None and json_component_string is not None:
                    json_string = '{%s,"type":"acs",%s}' % (
                        json_component_string, json_env_string)
                else:
                    json_string = '{%s,"type":"acs"}' % json_component_string
            # If the component isn't apart of the ACS and doesn't have an env_version just output the component version
            else:
                if json_env_string is None:
                    json_string = '{%s}' % json_component_string
                    # Check if the file has already been created. If it does append to the file, if not do a write
                    # operation
                    # The file should only exist at this point if it has had current json data written to it
            if os.path.isfile(json_filename):
                write_file = open(json_filename, "a")
            else:
                write_file = open(json_filename, "w")
            write_file.write(json_string)
            write_file.write("\n")
            close_file = True
        if close_file:
            write_file.close()
            log.info("%s has been closed." % json_filename)
コード例 #20
0
def stock_monitor_run(sk_list):
    log.info('start to run stock nonitor')
    # 启动列表监控
    #stock_manager.run()
    '''
    for obj in stock_manager.get_stock_list():
        data = get_stock_data(obj.code)
        if data is None:
            time.sleep(5)
            continue
        sk_obj = stock_manager.get_stock_obj(obj.code) 
        sk_obj.set_data(data)
    '''
    while True:
        if stock_manager.get_real_data_by_skobj(sk_list) is False:
            log.info('get data fail, sleep 5')
            time.sleep(5)
            continue

        if len(sk_list) > 0:
            for sk in sk_list:
                data = sk.get_data()
                log.info(data['name'] + ':' + str(data['cur_price']) + '  ' +
                         str(data['p_change']) + '  ' +
                         str(data['monitor_price']))
            time.sleep(3)
    log.info('%s run end' % stock_monitor_run.__name__)
コード例 #21
0
def runReplacing(args):
    inputDirectoryOrFilePath = args.i
    outputDirectoryPath = args.o

    vocabulariesFilesPath = args.c  # list

    strictPattern = args.nostrictpattern
    # valid directory
    validInputFileOrDir = isValidDirOrFile(inputDirectoryOrFilePath)
    validOutputDirectory = isValidDir(outputDirectoryPath)

    if (not validInputFileOrDir):
        logger.err(inputDirectoryOrFilePath +
                   " is not a valid directory or file")
    if (not validOutputDirectory):
        try:
            logger.info("Creating output directory :" + outputDirectoryPath)
            os.makedirs(outputDirectoryPath, exist_ok=True)
            validOutputDirectory = True
            logger.info("Directory created successfully :" +
                        outputDirectoryPath)
        except OSError as exc:  # Guard against race condition
            logger.err(outputDirectoryPath + " is not a valid directory")

    for vocabularyFilePath in vocabulariesFilesPath:
        validVocabularyFile = isValidFile(vocabularyFilePath)
        if (not validVocabularyFile):
            logger.err(vocabularyFilePath + " is not a valid file path")
            sys.exit()

    if (not validInputFileOrDir or not validOutputDirectory
            or not validVocabularyFile):
        sys.exit()

    absOutputDirectoryPath = os.path.abspath(outputDirectoryPath)

    if (isValidDir(inputDirectoryOrFilePath)):
        absInputDirectoryPath = os.path.abspath(inputDirectoryOrFilePath)
        # if it is a directory
        filenameList = os.listdir(os.path.abspath(absInputDirectoryPath))
    if (isValidFile(inputDirectoryOrFilePath)):
        # if it is a file
        absInputDirectoryPath = os.path.dirname(inputDirectoryOrFilePath)
        filenameList = [os.path.basename(inputDirectoryOrFilePath)]

    for filename in filenameList:
        if not filename.startswith('.'):
            logger.info("Replace terms in file " + filename)
            inputFilename = os.path.join(absInputDirectoryPath, filename)
            outputFile = os.path.join(absOutputDirectoryPath, filename)
            with open(inputFilename, "r", encoding="utf8") as fileIn, open(
                    outputFile, "w", encoding="utf8") as fileOut:
                data = fileIn.read()
                for vocabularyFilePath in vocabulariesFilesPath:
                    vocabulary = loadVocabularyFile(vocabularyFilePath)
                    data = multipleReplace(data, vocabulary, strictPattern)
                fileOut.write(data)
    # if it is a file
    #
    logger.info("Replacements done")
コード例 #22
0
def stock_list_setup():
    log.info('start to setup stock list')
    # 检查本地股票列表信息
    stock_list = stock_data.get_stock_list()
    if stock_list is not None:
        # 根据列表信息,创建股票对象
        for data in stock_list:
            stock_manager.add_code(data[0])
            sk_data = stock_manager.get_stock_obj(data[0])
            if len(data) > 1:
                sk_data.set_monitor_price(float(data[1]))

    # 返回股票对象列表信息
    return stock_manager.stock_list
コード例 #23
0
 def download(self, url, flag):
     resp = requests.get(url, headers={
         'User-Agent': ua.get_ua(),
         'Cookie': auth.auth()}, proxies=proxy.get_proxies()[0]
                         )
     if resp.status_code == 200:
         log.info('GET %s 200 OK' % url)
         html = to_html(resp.content)
         if flag:
             self.parse(html)
         else:
             self.parse_detail(html)
             self.filter_urls.append(url)
     else:
         log.error('Error %s %s ' % (url, resp.status_code))
コード例 #24
0
    def write_json_file(component_dict, json_filename):
        close_file = False
        json_env_string = None
        json_component_string = None

        # Attempt to remove any previous files, if none exists just eat the error
        try:
            os.remove(json_filename)
        except OSError:
            pass
        log.debug("evaluating components to generate %s" % json_filename)
        for component in component_dict.keys():
            for key, version in component_dict[component].iteritems():
                if key == "component_env_version":
                    if "component" in json_filename:
                        json_env_string = '"env_version":{"current":"%s","new":"%s"}}' % (version[1], version[0])
                    else:
                        json_env_string = '"env_version":{"current":"%s","new":"%s"}}' % (version[0], version[0])
                if key == "component_version":
                    if "component" in json_filename:
                        json_component_string = '"%s":{"version":{"current":"%s","new":"%s"}' % (
                        component, version[1], version[0])
                    else:
                        json_component_string = '"%s":{"version":{"current":"%s","new":"%s"}' % (component, version[0],
                                                                                                 version[0])
            # This section sets the type to ACS if the component is found in the static mapping
            if component in acs.component.CMPS:
                if json_env_string is not None and json_component_string is not None:
                    json_string = '{%s,"type":"acs",%s}' % (json_component_string, json_env_string)
                else:
                    json_string = '{%s,"type":"acs"}' % json_component_string
            # If the component isn't apart of the ACS and doesn't have an env_version just output the component version
            else:
                if json_env_string is None:
                    json_string = '{%s}' % json_component_string
                    # Check if the file has already been created. If it does append to the file, if not do a write
                    # operation
                    # The file should only exist at this point if it has had current json data written to it
            if os.path.isfile(json_filename):
                write_file = open(json_filename, "a")
            else:
                write_file = open(json_filename, "w")
            write_file.write(json_string)
            write_file.write("\n")
            close_file = True
        if close_file:
            write_file.close()
            log.info("%s has been closed." % json_filename)
コード例 #25
0
def getFileNameRecursively(walk_dir):
    """ Description
    :type walk_dir:
    :param walk_dir:

    :raises:

    :rtype:
    """
    filePaths = []
    for root, directory_names, file_names in os.walk(walk_dir):
        for filename in file_names:
            filePath = os.path.join(root, filename)
            if (os.path.isfile(filePath)):
                filePaths.append(filePath)
    log.info(str(len(filePaths)) + " files found")
    return filePaths
コード例 #26
0
	def list_all(data):
		conn = libvirt.open('qemu:///system')
		if isinstance(data,dict):
        		for x in range(len(data)):
            			temp_key = data.keys()[x]
            			a = data[temp_key]
            			#print  a.get('state')
            			if (a.get('state') == 'NULL') or (a.get('state') == 'fluent'):
                			b = a.get('id')
					name = a.get('hostname')
                			print "The virtual machine [%s] state for id [%s] do not need to do anying..." %(name,b)
					logging.info("The virtual machine [%s] state for id [%s] do not need to do anying..." %(name,b))
				elif (a.get('state') == 'inactive'):
					c = a.get('id')
					name2 = a.get('hostname')
					start = action.startDomaction(conn,name2)
					if not start:
						print "The virtual machine [%s] state for id [%s] started successfully..." %(name2,c)
						logging.info("The virtual machine [%s] state for id [%s] stared successfully..." %(name2,c))
						cmd = 'sh /root/script/monitoring_kvm/tools/send_mail.sh  Successfully %s' % name2
						shell.shell_cmd(cmd)
					else:
						print "The virtual machine [%s] state for id [%s] started faild..." %(name2,c)
						logging.info("The virtual machine [%s] state for id [%s] stared faild..." %(name2,c))
						cmd = 'sh /root/script/monitoring_kvm/tools/send_mail.sh Faild %s' % name2
						shell.shell_cmd(cmd)
				elif (a.get('state') == 'active'):
					d = a.get('id')
					name3 = a.get('hostname')
					reset = action.resetDom(conn,int(d))
					if not reset:
						print "The virtual machine [%s] state for id [%s] reset successfully..." %(name3,d)
						logging.info("The virtual machine [%s] state for id [%s] reset successfully..." %(name3,d))
						cmd = 'sh /root/script/monitoring_kvm/tools/send_mail.sh  Successfully %s' % name3
						shell.shell_cmd(cmd)
					else:
						print "The virtual machine [%s] state for id [%s] reset faild..." %(name3,d)
						logging.info("The virtual machine [%s] state for id [%s] reset faild..." %(name3,d))
						cmd = 'sh /root/script/monitoring_kvm/tools/send_mail.sh Faild %s' % name3
						shell.shell_cmd(cmd)
							
		conn.close()
コード例 #27
0
ファイル: quick.py プロジェクト: qbuat/WsInputInspector
def make_plot(meas, categories, sample='Ztt', key_filter=None, no_plotting=False):
    
    for cat in categories:
        if cat.is_cr:
            continue

        samp = meas.get_sample(sample)
        systs = samp.syst_dict(cat.cats, meas.rfile)
        if key_filter is None:
            keys = sorted(systs.keys())
        else:
            keys = filter(lambda s: key_filter in s, systs.keys())
            keys = sorted(keys)

        log.info('Make plot for NPs:')
        for k in keys:
#             log.info('\t {}'.format(k))
            if no_plotting:
                continue
            c = raw_np_plot(meas.rfile, k, cat, samp)
            c.SaveAs('plots/{}_{}_{}_{}.eps'.format(meas.channel, cat.name.replace(' ', '_'), sample, k))
            c.SaveAs('plots/{}_{}_{}_{}.pdf'.format(meas.channel, cat.name.replace(' ', '_'), sample, k))
コード例 #28
0
ファイル: action_kvm.py プロジェクト: wangyouyan/OpenStack
def checkDom(conn,name,ip):
	print('---check Domin status-----')
	logging.info('---check Domin status-----')
	def check_ip(ip):
		cmd = 'fping %s' %ip
		ping_result = shell.shell_cmd(cmd)[0]
		if 'alive' in ping_result:
			return 'active'
		else:
			return 'inactive'
	dom = conn.lookupByName(name)
	try:
		if (dom.state() == [1,1]) and (check_ip(ip) == 'active'):
			return 'fluent'
		elif (dom.state() == [1,1]) or (check_ip(ip) == 'inactive'):
			return 'active'
		else:
			return 'inactive'
			
	except:
		print('Dom %s check failed...' %dom.name())
		logging.error('Dom %s check failed...' %dom.name())
コード例 #29
0
ファイル: action_kvm.py プロジェクト: wangyouyan/OpenStack
def checkDom(conn, name, ip):
    print('---check Domin status-----')
    logging.info('---check Domin status-----')

    def check_ip(ip):
        cmd = 'fping %s' % ip
        ping_result = shell.shell_cmd(cmd)[0]
        if 'alive' in ping_result:
            return 'active'
        else:
            return 'inactive'

    dom = conn.lookupByName(name)
    try:
        if (dom.state() == [1, 1]) and (check_ip(ip) == 'active'):
            return 'fluent'
        elif (dom.state() == [1, 1]) or (check_ip(ip) == 'inactive'):
            return 'active'
        else:
            return 'inactive'

    except:
        print('Dom %s check failed...' % dom.name())
        logging.error('Dom %s check failed...' % dom.name())
コード例 #30
0
 def send_request(self, pre_process, post_process):
     """
     主方法,发送请求
     :param pre_process: 请求前的操作
     :param post_process: 收到响应后的操作
     :return:
     """
     self.clear()
     self.request = BaseRequest(self.data)
     log.info("--------------获取请求数据-------------------")
     requst_data = self.__get_request_data()
     log.info("--------------发送请求----------------------")
     if "data" in requst_data:
         requst_data["data"] = requst_data["data"].encode("utf-8") if requst_data["data"] else None
     response = self.__send_request(requst_data)
     log.debug("响应状态码为:{}".format(response.status_code))
     self.response = BaseResponse(response)
     log.info("--------------获取响应数据----------------------")
     self.__get_response_data()
     return self
コード例 #31
0
	def server_receive(self):
		ip = self.host
		port = self.port
		s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
		s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
		s.bind((ip,int(port)))
		s.listen(9)
		check_file = '/root/script/monitoring_kvm/tools/check_client_conn'
		try:
			while True:
				####################################
				# Process the connection
				try:
					clientconn,clientaddr=s.accept()
				except (KeyboardInterrupt, SystemExit):
					raise
					logging.error("you have CTRL+C,Now quit")
				except:
					traceback.print_exc()
					logging.error(traceback.print_exc())
				try:
					print "Got connection from %s",clientconn.getpeername() 
					logging.info("Got connection from %s", clientconn.getpeername())
					with open(check_file,'w') as f:
						f.writelines('1')
					while True:
						remote_data=clientconn.recv(8094)
						if not len(remote_data):
                            				clientconn.send('welcome',remote_data)
							logging.info(("The client data has been received and connection will be disconected!"))
                            				break
						clientconn.sendall(remote_data)
						recv_data = eval(remote_data)
						remote_data += remote_data
						print "Data is :",remote_data
						logging.debug(remote_data)#####
						self.do_working(recv_data)
				except (KeyboardInterrupt, SystemExit):
					raise
					logging.error("you have CTRL+C,Now quit")
				except:
					traceback.print_exc()
					logging.error(traceback.print_exc())
				# Close the connection
                		try:
					clientconn.close()
				except KeyboardInterrupt:
					raise
					logging.error("you have CTRL+C,Now quit")
                		except:
                    			traceback.print_exc()
					logging.error(traceback.print_exc())
		except (KeyboardInterrupt, SystemExit):
            		print "you have CTRL+C,Now quit"
			raise
			logging.error(traceback.print_exc())
        	except:
            		traceback.print_exc()
			logging.error(traceback.print_exc())
        	finally:
            		s.close()
コード例 #32
0
        dump_files_here = options.output_directory
    else:
        dump_files_here = "./"
    if options.blue_print is not None:
        if "_env" not in options.blue_print[0]:
            log.error(
                "Unexpected input for blueprint. Expected blueprint with _env")
            parser.print_help()
            sys.exit(1)
        list_of_components = options.component_name + options.blue_print
    else:
        list_of_components = options.component_name

    backup_location = "%s.backup" % options.config_file
    shutil.copyfile(options.config_file, backup_location)
    log.info("physical file backed up to: %s" % backup_location)

    env_file_section_to_find_env_name = 'environment'
    variable_name_of_environment_name = 'ENV_NAME'
    config = ConfigParser.RawConfigParser()
    config.optionxform = str  # make keys case sensitive
    config.read(options.config_file)
    try:
        environment_name = config.get(env_file_section_to_find_env_name,
                                      variable_name_of_environment_name)
    except ConfigParser.NoSectionError:
        log.error("%s was not found in %s. Cannot continue..." %
                  (env_file_section_to_find_env_name, options.config_file))
        sys.exit(1)
    except ConfigParser.NoOptionError:
        log.error("%s was not found in section %s in the config file: %s\n"
コード例 #33
0
def inspect_load_state(component_to_inspect, gateway_session, pod_status_dict, deployment_version_dict,
                       container_status_dict ):

    deployment_config_label = "internal.acs.amadeus.com/component=%s" % component_to_inspect
    get_dc_command = "sudo oc get dc -l %s -o json" % deployment_config_label
    close_file = False
    deployer_and_component = None
    # This is the file which will have the deployer name in it if there is a failure
    filename = "/tmp/deployer_cleanup"
    # Attempt to remove the file from a previous run to ensure the file is always empty
    try:
        os.remove(filename)
    except OSError:
        pass

    # Need to check the component against acs.component.CMPS[cmp_name]['cluster']
    # All of the component types are statically set in component.py
    try:
        acs.component.CMPS[component_to_inspect]
    except KeyError:
        print("Component is not part of the ACS category. Aborting the validation process")
        sys.exit(0)

    os_master_session = openshift.cluster.get_master_session(gateway_session, component_to_inspect)

    component_attributes = process_deployment_config_json(get_dc_command, os_master_session)

    for first_key in component_attributes.keys():
        for pod_label in component_attributes[first_key].keys():
            get_pod_command = "sudo oc get pod -l %s -o json" % pod_label
            process_pod_json(get_pod_command, pod_status_dict, deployment_version_dict, pod_label, os_master_session,
                             container_status_dict)
    exit_with_error = False

    # compare the dc latest version to component latest version
    for first_key in deployment_version_dict.keys():
        for second_key, value in deployment_version_dict[first_key].iteritems():
            if component_attributes[first_key][second_key] != deployment_version_dict[first_key][second_key]:
                # If there is a problem, store the data with the component name, in the same way that it is stored
                # if there are no pods running. i.e. name=component. This allows consistent error handling
                # Swap the first_key and second_key to normalize the data in the dict
                pod_status_dict.pop(first_key)
                pod_status_dict[second_key] = {first_key: False}
                # At this point the dict looks like:
                # pod_status_dict['name=ahp-report-audit-dmn'] = {'report-audit-dmn-deployment': False}

    for key in pod_status_dict.keys():
        log.info("Validating component: %s" % key)
        for second_key, value in pod_status_dict[key].iteritems():
            if not value:
                if "name" in key:
                    log.warning("%sThis component did not deploy at all:      \t%s\n" % (textColours.FAIL, key))
                    # name=component will be in the key if there was a problem
                    # The second key will be empty if the problem was that the pod did not exist. Usually when a pod
                    # no longer exists, there is no longer a deployer pod kicking around.
                    # This will get the name of the deployer pod and write it to a file for cleanup before
                    # failing back to the previous build
                    deployer_name = second_key + "-" + str(component_attributes[second_key][key]) + "-deploy"

                else:
                    print("%sThis component has container(s) not ready: \t%s\n" % (textColours.FAIL, key)),
                    print("\nContainer infomration from failure:\n"),
                    for container in container_status_dict.keys():
                        print("\tDocker image name: %s\n" % (container_status_dict[container])),
                        print("\tContainer name: %s\n" % container)
                if second_key is not None:
                    try:
                        try:
                            int(second_key.split("-")[-1])
                        except ValueError:
                            second_key = "-".join(second_key.split("-")[:-1])
                        command = "sudo oc get pod -l openshift.io/deployer-pod-for.name=%s -o json" % \
                                  (second_key)
                        log.info("Running command: %s" % command)
                        cmd_output = os_master_session.get_cmd_output(command)
                        deployer_json_data = json.loads(cmd_output)
                        deployer_name = deployer_json_data['items'][0]['metadata']['name']
                        log.warning("Deployer pod found in pod json for %s, writing %s" % (deployer_name, filename))
                    except IndexError:
                        log.warning("%sNo deployer pods found to clean up for: %s" % (textColours.FAIL, second_key))
                    except KeyError:
                        print("key error")
                        pass
                deployer_and_component = component_to_inspect + " : " + deployer_name
                if deployer_and_component is not None:
                    write_file = open(filename, "a")
                    write_file.write(deployer_and_component)
                    write_file.write("\n")
                    close_file = True
                    exit_with_error = True
    if close_file:
        log.debug("%s has been written" % filename)
        write_file.close()
    return(exit_with_error)
コード例 #34
0
    if options.output_directory is not None:
        dump_files_here = options.output_directory
    else:
        dump_files_here = "./"
    if options.blue_print is not None:
        if "_env" not in options.blue_print[0]:
            log.error("Unexpected input for blueprint. Expected blueprint with _env")
            parser.print_help()
            sys.exit(1)
        list_of_components = options.component_name + options.blue_print
    else:
        list_of_components = options.component_name

    backup_location = "%s.backup" % options.config_file
    shutil.copyfile(options.config_file, backup_location)
    log.info("physical file backed up to: %s" % backup_location)

    env_file_section_to_find_env_name = 'environment'
    variable_name_of_environment_name = 'ENV_NAME'
    config = ConfigParser.RawConfigParser()
    config.optionxform = str  # make keys case sensitive
    config.read(options.config_file)
    try:
        environment_name = config.get(env_file_section_to_find_env_name, variable_name_of_environment_name)
    except ConfigParser.NoSectionError:
        log.error("%s was not found in %s. Cannot continue..." % (env_file_section_to_find_env_name,
                                                                  options.config_file))
        sys.exit(1)
    except ConfigParser.NoOptionError:
        log.error("%s was not found in section %s in the config file: %s\n"
                  "Cannot continue..." % (variable_name_of_environment_name, env_file_section_to_find_env_name,
コード例 #35
0
                    while i < len(row):
                        element = row[i]
                        element = utils.clean(element, replacedChars,
                                              dateColumn[i])
                        tmpRow.append(element)
                        i += 1

                    rows.append(tmpRow)
                firstline = False
    except:
        pass
        # with open(filePath, 'r', encoding="ISO-8859-1") as csvfile:
        #     spamreader = csv.reader(csvfile, delimiter=',')
        #     for row in spamreader:
        #         tmpRow = []
        #         for element in row:
        #             element = utils.clean(element, replacedChars)
        #             tmpRow.append(element)
        #         rows.append(tmpRow)

    log.info("Writing")
    with open(OUTPUT_DIRECTORY_PATH + "/" +
              utils.getFileNameFromFilePath(filePath),
              'w',
              newline='') as f:
        writer = csv.writer(f)
        writer.writerows(rows)
    log.success(OUTPUT_DIRECTORY_PATH +
                utils.getFileNameFromFilePath(filePath))
    name = +1
コード例 #36
0
    # 返回股票对象列表信息
    return stock_manager.stock_list


def create_thread(func, args=None):
    if args is None:
        t = Thread(target=func)
    else:
        t = Thread(target=func, args=args)
    t.start()
    return t


if __name__ == '__main__':
    log.info('run main')
    thread_lst = []
    #get_all_stock_list_from_network()
    sk_list = stock_list_setup()
    #lst = ['sh000001', 'sh601068']
    #print(rt.get_real_time_data(lst))
    #print(sm.get_minutes_data('sh000001', 60))
    #print(sd.get_day_data('sh000001', 'month', 10))
    #sup.update_all_data()
    #exit()
    # if len(sk_list) > 0:
    # while True:
    # stock_monitor_run()
    # for sk in sk_list:
    # data = sk.get_data()
    # log.info(data['name']+':'+data['cur_price']+'  ' + str(data['p_change']))