def main(): config = toml.loads(file.read_all_text('config.toml')) path_in = Path('in') / config['in']['path'] raw = file.read_all_text(path_in / 'raw.txt') cfg = json.loads(file.read_all_text(path_in / 'cfg.json')) template = template_make(raw, cfg) path_out = Path('out') file.write_all_text(path_out / 'template.txt', template)
def gen_api(): template = file.read_all_text(path_to_abs_str(path_project/'script'/'crud_gen'/'template'/'api.txt')) dir_cfg = path_project/'script'/'crud_gen'/'cfg' for file_cfg in dir_cfg.glob('*.json'): cfg = json.loads(file.read_all_text(file_cfg)) file_code = path_project / 'app' / 'api' / (cfg['小写'] + '.go') if file_code.exists(): print(f'{file_code} has already exists, skipped.') else: content = fill_template(template,cfg) file.write_all_text(file_code,content) print(f'{file_code} gen successful :)')
def main(): config = file.read_all_text('config.toml') config = toml.loads(config) path_in = Path('in') / config['in']['path'] template = file.read_all_text(path_in / 'template.txt') path_out = Path('out') for p in path_in.glob('*.json'): in_value = json.loads(file.read_all_text(p)) result = make_template(template, in_value) # print(result) file.write_all_text( path_out / ('.'.join(p.name.split('.')[:-1]) + '.txt'), result)
def gen_router(): template = file.read_all_text(path_project/'script'/'crud_gen'/'template'/'route.txt') dir_cfg = path_project/'script'/'crud_gen'/'cfg' route = file.read_all_text(path_project/'router'/'router.go') for file_cfg in dir_cfg.glob('*.json'): cfg = json.loads(file.read_all_text(file_cfg)) name = cfg['小写'] if name in route: print(f'{name} has already exists, skipped.') else: content = fill_template(template,cfg) route = route.replace('// crud_gen will insert here',content) print(f'{name} gen successful :)') file.write_all_text(path_project/'router'/'router.go',route)
def gen_dto(): path_in = path_project / 'app' / 'model' / 'internal' for p in path_in.glob('*.go'): print(p) s = file.read_all_text(p) lines = s.split('\n') structStart = -1 for i, line in enumerate(lines): if ' struct {' in line: structStart = i break lines = lines[structStart:] lines = [line for line in lines if (not 'CreatedAt' in line and not 'UpdatedAt' in line and not 'DeletedAt' in line)] response = '\n'.join(lines) response = response.replace(' struct', 'ApiResponse struct') lines = [line for line in lines if 'Id' not in line] request = '\n'.join(lines) request = request.replace(' struct', 'ApiRequest struct') text = file.read_all_text(path_project/'app'/'model'/ p.name) if 'ApiRequest' in text: print('ApiRequest has already exists, skipped.') else: text += request print('ApiRequest gen successful :)') if 'ApiResponse' in text: print('ApiResponse has already exists, skipped.') else: text += response print('ApiResponse gen successful :)') file.write_all_text(path_project/'app'/'model'/ p.name,text)
import pathlib from htutil import file path_in = pathlib.Path('../../app/model/internal') for p in path_in.glob('*.go'): print(p) # s = '''type Members struct { # Id int `orm:"id,primary" json:"id"` // # Name string `orm:"name" json:"name"` // # UrlAvatar string `orm:"url_avatar" json:"urlAvatar"` // # SchoolYear int `orm:"school_year" json:"schoolYear"` // # Describe string `orm:"describe" json:"describe"` // # MemberType int `orm:"member_type" json:"memberType"` // # TeacherInfo string `orm:"teacher_info" json:"teacherInfo"` // # }''' s = file.read_all_text(p) lines = s.split('\n') structStart = -1 for i, line in enumerate(lines): if ' struct {' in line: structStart = i break lines = lines[structStart:] s = '\n'.join(lines) s = s.replace(' struct', 'ApiRep struct') for i in range(97, 123): small = chr(i) big = chr(i-32) s = s.replace(f'json:"{small}', f'json:"{big}')
# coding: utf-8 import subprocess from pathlib import Path import pysftp import yaml from htutil import file import paramiko project_path = str(Path('.').absolute()) project_name = Path('.').absolute().name image_name = f'{project_name}_dev' container_name = f'{project_name}_dev' config_path = Path(__file__).parent / 'config.yaml' config = yaml.load(file.read_all_text(config_path), Loader=yaml.FullLoader) def run_shell_script(script: str): lines = script.split('\n') for line in lines: print(line) subprocess.call(args=line, shell=True) def build_image(): #run_shell_script('docker pull golang:1.16.0-alpine3.13\ndocker pull alpine:3.13') # run_shell_script(f'docker rm -f {container_name}') run_shell_script(f'docker build -t {image_name} -f Dockerfile_dev .')
'webdav_hostname': hostname, 'webdav_login': config['webdav']['username'], 'webdav_password': config['webdav']['password'], 'disable_check': True, # 有的网盘不支持check功能 } client = Client(option) av_min_size = 500 * 1024 * 1024 # size of av should > 500 MB paths = list_all_paths(client, '/') av_paths = [] for path in paths: info = client.info(path) if info['size'] is not None: size = int(info['size']) if size > av_min_size: url = f'{hostname}/{path}' url = url.replace('///', '/') av_paths.append(url) print(path) file.write_all_lines('paths.txt', av_paths) if __name__ == '__main__': config = yaml.load(file.read_all_text('config.yaml'), Loader=yaml.SafeLoader) upload()
# print(ex) pass except Exception as ex: pass def single(): for url in tqdm(urls, leave=False): download_file(url) def multi(): task_pool = ThreadPoolExecutor(max_workers=4) tqdm(task_pool.map(download_file, urls), total=len(urls), leave=False) def main(): log.register_p_callback( lambda string: file.append_all_text('download.log', string + '\n')) single() # all_task = [task_pool.submit(download_file, (url)) for url in urls] # wait(all_task, return_when=ALL_COMPLETED) if __name__ == '__main__': config = yaml.safe_load(file.read_all_text('config.yaml')) urls = file.read_all_lines('paths.txt') file.create_dir_if_not_exist('file') main()