def login(userName, password): logger = log_configer.getLogger('login_jalor') logger.setLevel(level=logging.INFO) # url = 'http://login-beta.huawei.com/login/login.do?actionFlag=loginAuthenticate&lang=en&loginMethod=login&loginPageType=mix&uid='+userName+'&password='******'http://login-beta.huawei.com/login/login.do?actionFlag=loginAuthenticate&uid=cwx921932&password=Rcedwcx1@' res = requests.post(url=url,data=None) cookies = res.cookies return cookies
def __init__(self, *args, package:str, all:bool = False, level:int = logging.INFO): self.package = package self.all = all self.repositories = args self.log = log_configer.getLogger('checkPackage4Python') self.log.setLevel(level)
class GenerateExcel(): logger = log_configer.getLogger('GenerateExcel') logger.setLevel(level=logging.DEBUG) # 需要生成excel的绝对路径名称 absolute_name = '' # Color = {'red':'ffc7ce', 'yellow': 'ffeb9c', 'green': 'c6efce'} # fill = PatternFill('solid', bgColor=colors.Color()) def __init__(self, absolute_name): self.absolute_name = absolute_name def new_wb(self): # wb 代表一个工作簿, 即一个Excel文件 return openpyxl.Workbook() def built_ws(self, wb, title, datas=[], headers=[]): # ws 代表一个工作表 ws = wb.create_sheet(title) # ws.column_dimensions[1].width = # ws.title = title self.logger.debug('制作工作表%s, 一共包含%d行数据', title, len(datas)) for col in range(len(headers)): c = col + 1 ws.cell(row=1, column=c).value = headers[col] # ws.cell(row=1, column=c).fill = self.fill for cur_row in range(len(datas)): curRow = datas[cur_row] for cur_col in range(len(curRow)): c = cur_col + 1 ws.cell(row=cur_row + 2, column=c).value = curRow[cur_col] return wb def done(self, wb): wb.save(self.absolute_name) self.logger.info('DONE! 保存文件%s', self.absolute_name)
import requests import json import base64 from functools import wraps from bllools.common import log_configer log = log_configer.getLogger('mainEntry') ''' 功能主要入口 包含获取 soa 动态 token逻辑 请求隐私中心,将明文加密为密文的主要逻辑 ''' class mainEntry(): # http://kwe-beta.huawei.com/sgovernance/servicestore/services/saasApplicationModuleGetAppToken def __init__(self, *args, appid='com.huawei.tbsd', token=r'wR<Q4B()mGn6Uo2Yriy(W8I4+VXWMge8f)QqDibYUqRvklGGXpj1524625157846', url=r"http://kwe-beta.huawei.com/ApiCommonQuery/appToken/getRestAppDynamicToken", **kwargs ): self.appid = appid self.token = token self.url = url # 目前不需要主方法提供具体的返回, 通过继承了返回 def __call__(self, func): @wraps(func) def wrapped_function(*args, **kwargs): log.warning('未定义方法,什么都不会做')
# _*_ coding: utf-8 _*_ import re from bllools.common import log_configer from logging import DEBUG from logging import INFO logger = log_configer.getLogger('Filter.py') class Filter(): total, analy = 0, 0 encoding = 'utf-8' def __init__(self, encoding='utf-8'): self.encoding = encoding def each_line_contain(self, cur_file, pattern): logger.debug('当前编码%s 文件 %s', self.encoding, cur_file) try: theFile = open(cur_file, mode='r', encoding=self.encoding) total_content = theFile.read() file_name = theFile.name theFile.close() except UnicodeDecodeError: logger.error('文件%s非%s格式, 解析失败', cur_file, self.encoding) return fined = re.findall(pattern, total_content) if fined:
from bllools.common import log_configer logger = log_configer.getLogger('builder') # log_configer.debugEnable(logger) import sys import os def home_path(): try: return os.path.expanduser('~') except Exception: try: return os.environ['HOME'] except Exception: path = os.path.expandvars('$HOME') if path == '$HOME': logger.warn("无法获取 HOME 路径!") return '.' + os.sep # 将内容写入指定文件中 # 如果文件不存在,则新建一个 # 完成后返回文件所在目录 def single_file(path, name, content): if path != '' and (not path.endswith('/')) and (not path.endswith('\\')): path = path + os.sep else: logger.debug("使用默认路径") path = home_path() + os.sep + 'export' + os.sep if not os.path.exists(path):
import cx_Oracle import psycopg2 import sys from bllools.common import log_configer logger = log_configer.getLogger('dbConnector') # log_configer.debugEnable(logger) log_configer.infoEnable(logger) class connect(object): def __init__(self, url, user, password): self.url = url self.user = user self.password = password def call(self): print("开始连接服务器: ", self.url) # 连接ORACLE举例 # client = r"D:\etc\Drivers\instantclient_11_2_64"; # oracle = oracle_conn("tbsdgis", "ccps123456", "dggtsp427-or/tbsdgis", client) # ora_conn = oracle_conn.call(oracle) class oracle_conn(connect): def __init__(self, url, user, password, client:str): super(oracle_conn, self).__init__(url, user, password) self.client = client def call(self): try: cx_Oracle.init_oracle_client(lib_dir=client) except Exception as err:
import re from bllools.common import log_configer logger = log_configer.getLogger('urlHandler') log_configer.debugEnable(logger) def getUserFromUrl(url): if url is None: logger.error('url不能为空!') return if url.startswith('postgresql+psycopg2'): logger.debug("适用于 sqlalchemy 的url") pattern = r'://([^:]+)' matcher = re.search(pattern, url) return matcher.group(1)
import json from bllools.common import log_configer import logging from bllools.func import login_ja import requests from bllools.excelsupport import establish logger = log_configer.getLogger('myYaml.py') logger.setLevel(level=logging.DEBUG) # rights_handler & show_all_rights 一起使用, 用于将权限信息展示到工作台 def show_all_rights(jsonBody, name): logger.info('%s 权限点一共有:%d', name, len(jsonBody)) tbsd_rights = '' for cur in jsonBody: desc = cur.get('desc') rpChildren = cur.get('rpChildren') for curChildren in rpChildren: if curChildren.get('checked'): childrenDesc = curChildren.get('desc') tbsd_rights = tbsd_rights + desc + '\t' + childrenDesc + '\t' operationUrl = curChildren.get('operationUrl') if operationUrl: for url in operationUrl: tbsd_rights = tbsd_rights + url + '\t' else: logger.warning('权限点[%s]没有具体调用地址!', desc + '\W' + childrenDesc) tbsd_rights = tbsd_rights + '\r\n' logger.info('权限点分布:')
from bllools.files import get import os from bllools.common import log_configer log = log_configer.getLogger('coalesce') log_configer.infoEnable(log) # 针对分散的多个 sql 文件, def coalesce(dir, newFileName='_total.sql', suffix=['.sql']): getFiles = get.GetFile(dir, suffix=suffix) files = getFiles.all_files() if files is None or len(files) == 0: filesSuffix = '' for cur in suffix: filesSuffix = filesSuffix + '[' + cur + '] ' log.warning("当前目录下不存在 %s文件, 任务结束", filesSuffix) return else: log.debug('一共识别存在 %d 个文件等待聚合', len(files)) if not dir.endswith('/') and not dir.endswith('\\'): dir = dir + os.sep # a+ 打开一个文件用于读写。如果该文件已存在,文件指针将会放在文件的结尾。文件打开时会是追加模式。如果该文件不存在,创建新文件用于读写。 total_file = open(dir + newFileName, mode='a+', encoding='utf-8') for cur_file in files: theFile = open(cur_file, mode='r', encoding='utf-8') total_file.write(theFile.read()) total_file.write('\r\n') theFile.close()