re-common 10.0.37__py3-none-any.whl → 10.0.39__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- re_common/baselibrary/__init__.py +4 -4
- re_common/baselibrary/baseabs/__init__.py +6 -6
- re_common/baselibrary/baseabs/baseabs.py +26 -26
- re_common/baselibrary/database/mbuilder.py +132 -132
- re_common/baselibrary/database/moudle.py +93 -93
- re_common/baselibrary/database/msqlite3.py +194 -194
- re_common/baselibrary/database/mysql.py +169 -169
- re_common/baselibrary/database/sql_factory.py +26 -26
- re_common/baselibrary/mthread/MThreadingRun.py +486 -486
- re_common/baselibrary/mthread/MThreadingRunEvent.py +349 -349
- re_common/baselibrary/mthread/__init__.py +2 -2
- re_common/baselibrary/mthread/mythreading.py +695 -695
- re_common/baselibrary/pakge_other/socks.py +404 -404
- re_common/baselibrary/readconfig/config_factory.py +18 -18
- re_common/baselibrary/readconfig/ini_config.py +317 -317
- re_common/baselibrary/readconfig/toml_config.py +49 -49
- re_common/baselibrary/temporary/envdata.py +36 -36
- re_common/baselibrary/tools/all_requests/aiohttp_request.py +118 -118
- re_common/baselibrary/tools/all_requests/httpx_requet.py +102 -102
- re_common/baselibrary/tools/all_requests/mrequest.py +412 -412
- re_common/baselibrary/tools/all_requests/requests_request.py +81 -81
- re_common/baselibrary/tools/batch_compre/bijiao_batch.py +31 -31
- re_common/baselibrary/tools/contrast_db3.py +123 -123
- re_common/baselibrary/tools/copy_file.py +39 -39
- re_common/baselibrary/tools/db3_2_sizedb3.py +102 -102
- re_common/baselibrary/tools/foreachgz.py +39 -39
- re_common/baselibrary/tools/get_attr.py +10 -10
- re_common/baselibrary/tools/image_to_pdf.py +61 -61
- re_common/baselibrary/tools/java_code_deal.py +139 -139
- re_common/baselibrary/tools/javacode.py +79 -79
- re_common/baselibrary/tools/mdb_db3.py +48 -48
- re_common/baselibrary/tools/merge_file.py +171 -171
- re_common/baselibrary/tools/merge_gz_file.py +165 -165
- re_common/baselibrary/tools/mhdfstools/down_hdfs_files.py +42 -42
- re_common/baselibrary/tools/mhdfstools/hdfst.py +42 -42
- re_common/baselibrary/tools/mhdfstools/up_hdfs_files.py +38 -38
- re_common/baselibrary/tools/mongo_tools.py +50 -50
- re_common/baselibrary/tools/move_file.py +170 -170
- re_common/baselibrary/tools/move_mongo/mongo_table_to_file.py +63 -63
- re_common/baselibrary/tools/move_mongo/move_mongo_table.py +354 -354
- re_common/baselibrary/tools/move_mongo/use_mttf.py +18 -18
- re_common/baselibrary/tools/move_mongo/use_mv.py +93 -93
- re_common/baselibrary/tools/mpandas/mpandasreadexcel.py +125 -125
- re_common/baselibrary/tools/mpandas/pandas_visualization.py +7 -7
- re_common/baselibrary/tools/myparsel.py +104 -104
- re_common/baselibrary/tools/rename_dir_file.py +37 -37
- re_common/baselibrary/tools/sequoiadb_utils.py +398 -398
- re_common/baselibrary/tools/split_line_to_many.py +25 -25
- re_common/baselibrary/tools/stringtodicts.py +33 -33
- re_common/baselibrary/tools/workwechant_bot.py +84 -84
- re_common/baselibrary/utils/baseaiohttp.py +296 -296
- re_common/baselibrary/utils/baseaiomysql.py +87 -87
- re_common/baselibrary/utils/baseallstep.py +191 -191
- re_common/baselibrary/utils/baseavro.py +19 -19
- re_common/baselibrary/utils/baseboto3.py +291 -291
- re_common/baselibrary/utils/basecsv.py +32 -32
- re_common/baselibrary/utils/basedict.py +133 -133
- re_common/baselibrary/utils/basedir.py +241 -241
- re_common/baselibrary/utils/baseencode.py +351 -351
- re_common/baselibrary/utils/baseencoding.py +28 -28
- re_common/baselibrary/utils/baseesdsl.py +86 -86
- re_common/baselibrary/utils/baseexcel.py +264 -264
- re_common/baselibrary/utils/baseexcept.py +109 -109
- re_common/baselibrary/utils/basefile.py +654 -654
- re_common/baselibrary/utils/baseftp.py +214 -214
- re_common/baselibrary/utils/basegzip.py +60 -60
- re_common/baselibrary/utils/basehdfs.py +135 -135
- re_common/baselibrary/utils/basehttpx.py +268 -268
- re_common/baselibrary/utils/baseip.py +87 -87
- re_common/baselibrary/utils/basejson.py +2 -2
- re_common/baselibrary/utils/baselist.py +32 -32
- re_common/baselibrary/utils/basemotor.py +190 -190
- re_common/baselibrary/utils/basemssql.py +98 -98
- re_common/baselibrary/utils/baseodbc.py +113 -113
- re_common/baselibrary/utils/basepandas.py +302 -302
- re_common/baselibrary/utils/basepeewee.py +11 -11
- re_common/baselibrary/utils/basepika.py +180 -180
- re_common/baselibrary/utils/basepydash.py +143 -143
- re_common/baselibrary/utils/basepymongo.py +230 -230
- re_common/baselibrary/utils/basequeue.py +22 -22
- re_common/baselibrary/utils/baserar.py +57 -57
- re_common/baselibrary/utils/baserequest.py +279 -279
- re_common/baselibrary/utils/baseset.py +8 -8
- re_common/baselibrary/utils/basesmb.py +403 -403
- re_common/baselibrary/utils/basestring.py +382 -382
- re_common/baselibrary/utils/basetime.py +320 -320
- re_common/baselibrary/utils/baseurl.py +121 -121
- re_common/baselibrary/utils/basezip.py +57 -57
- re_common/baselibrary/utils/core/__init__.py +7 -7
- re_common/baselibrary/utils/core/bottomutils.py +18 -18
- re_common/baselibrary/utils/core/mdeprecated.py +327 -327
- re_common/baselibrary/utils/core/mlamada.py +16 -16
- re_common/baselibrary/utils/core/msginfo.py +25 -25
- re_common/baselibrary/utils/core/requests_core.py +103 -103
- re_common/baselibrary/utils/fateadm.py +429 -429
- re_common/baselibrary/utils/importfun.py +123 -123
- re_common/baselibrary/utils/mfaker.py +57 -57
- re_common/baselibrary/utils/my_abc/__init__.py +3 -3
- re_common/baselibrary/utils/my_abc/better_abc.py +32 -32
- re_common/baselibrary/utils/mylogger.py +414 -414
- re_common/baselibrary/utils/myredisclient.py +861 -861
- re_common/baselibrary/utils/pipupgrade.py +21 -21
- re_common/baselibrary/utils/ringlist.py +85 -85
- re_common/baselibrary/utils/version_compare.py +36 -36
- re_common/baselibrary/utils/ydmhttp.py +126 -126
- re_common/facade/lazy_import.py +11 -11
- re_common/facade/loggerfacade.py +25 -25
- re_common/facade/mysqlfacade.py +467 -467
- re_common/facade/now.py +31 -31
- re_common/facade/sqlite3facade.py +257 -257
- re_common/facade/use/mq_use_facade.py +83 -83
- re_common/facade/use/proxy_use_facade.py +19 -19
- re_common/libtest/base_dict_test.py +19 -19
- re_common/libtest/baseavro_test.py +13 -13
- re_common/libtest/basefile_test.py +14 -14
- re_common/libtest/basemssql_test.py +77 -77
- re_common/libtest/baseodbc_test.py +7 -7
- re_common/libtest/basepandas_test.py +38 -38
- re_common/libtest/get_attr_test/get_attr_test_settings.py +14 -14
- re_common/libtest/get_attr_test/settings.py +54 -54
- re_common/libtest/idencode_test.py +53 -53
- re_common/libtest/iniconfig_test.py +35 -35
- re_common/libtest/ip_test.py +34 -34
- re_common/libtest/merge_file_test.py +20 -20
- re_common/libtest/mfaker_test.py +8 -8
- re_common/libtest/mm3_test.py +31 -31
- re_common/libtest/mylogger_test.py +88 -88
- re_common/libtest/myparsel_test.py +27 -27
- re_common/libtest/mysql_test.py +151 -151
- re_common/libtest/pymongo_test.py +21 -21
- re_common/libtest/split_test.py +11 -11
- re_common/libtest/sqlite3_merge_test.py +5 -5
- re_common/libtest/sqlite3_test.py +34 -34
- re_common/libtest/tomlconfig_test.py +30 -30
- re_common/libtest/use_tools_test/__init__.py +2 -2
- re_common/libtest/user/__init__.py +4 -4
- re_common/studio/__init__.py +4 -4
- re_common/studio/assignment_expressions.py +36 -36
- re_common/studio/mydash/test1.py +18 -18
- re_common/studio/pydashstudio/first.py +9 -9
- re_common/studio/streamlitstudio/first_app.py +65 -65
- re_common/studio/streamlitstudio/uber_pickups.py +23 -23
- re_common/studio/test.py +18 -18
- re_common/v2/baselibrary/business_utils/BusinessStringUtil.py +219 -219
- re_common/v2/baselibrary/business_utils/baseencodeid.py +100 -100
- re_common/v2/baselibrary/business_utils/full_doi_path.py +116 -116
- re_common/v2/baselibrary/business_utils/rel_tools.py +6 -6
- re_common/v2/baselibrary/decorators/utils.py +59 -59
- re_common/v2/baselibrary/helpers/search_packge/NearestNeighbors_test.py +105 -105
- re_common/v2/baselibrary/helpers/search_packge/fit_text_match.py +253 -253
- re_common/v2/baselibrary/helpers/search_packge/scikit_learn_text_matcher.py +260 -260
- re_common/v2/baselibrary/helpers/search_packge/test.py +1 -1
- re_common/v2/baselibrary/s3object/baseboto3.py +230 -230
- re_common/v2/baselibrary/tools/WeChatRobot.py +95 -95
- re_common/v2/baselibrary/tools/ac_ahocorasick.py +75 -75
- re_common/v2/baselibrary/tools/concurrency.py +35 -35
- re_common/v2/baselibrary/tools/data_processer/base.py +53 -53
- re_common/v2/baselibrary/tools/data_processer/data_processer.py +508 -508
- re_common/v2/baselibrary/tools/data_processer/data_reader.py +187 -187
- re_common/v2/baselibrary/tools/data_processer/data_writer.py +38 -38
- re_common/v2/baselibrary/tools/dict_tools.py +44 -44
- re_common/v2/baselibrary/tools/dolphinscheduler.py +187 -187
- re_common/v2/baselibrary/tools/hdfs_base_processor.py +204 -204
- re_common/v2/baselibrary/tools/hdfs_bulk_processor.py +67 -67
- re_common/v2/baselibrary/tools/hdfs_data_processer.py +338 -338
- re_common/v2/baselibrary/tools/hdfs_line_processor.py +74 -74
- re_common/v2/baselibrary/tools/list_tools.py +69 -69
- re_common/v2/baselibrary/tools/resume_tracker.py +94 -94
- re_common/v2/baselibrary/tools/search_hash_tools.py +54 -54
- re_common/v2/baselibrary/tools/text_matcher.py +326 -326
- re_common/v2/baselibrary/tools/unionfind_tools.py +60 -60
- re_common/v2/baselibrary/utils/BusinessStringUtil.py +196 -196
- re_common/v2/baselibrary/utils/api_net_utils.py +270 -270
- re_common/v2/baselibrary/utils/author_smi.py +361 -361
- re_common/v2/baselibrary/utils/base_string_similarity.py +158 -158
- re_common/v2/baselibrary/utils/basedict.py +37 -37
- re_common/v2/baselibrary/utils/basehdfs.py +163 -163
- re_common/v2/baselibrary/utils/basepika.py +180 -180
- re_common/v2/baselibrary/utils/basetime.py +77 -77
- re_common/v2/baselibrary/utils/db.py +156 -156
- re_common/v2/baselibrary/utils/json_cls.py +16 -16
- re_common/v2/baselibrary/utils/mq.py +83 -83
- re_common/v2/baselibrary/utils/n_ary_expression_tree.py +243 -243
- re_common/v2/baselibrary/utils/string_bool.py +186 -186
- re_common/v2/baselibrary/utils/string_clear.py +246 -246
- re_common/v2/baselibrary/utils/string_smi.py +18 -18
- re_common/v2/baselibrary/utils/stringutils.py +271 -278
- re_common/vip/base_step_process.py +11 -11
- re_common/vip/baseencodeid.py +90 -90
- re_common/vip/changetaskname.py +28 -28
- re_common/vip/core_var.py +24 -24
- re_common/vip/mmh3Hash.py +89 -89
- re_common/vip/proxy/allproxys.py +127 -127
- re_common/vip/proxy/allproxys_thread.py +159 -159
- re_common/vip/proxy/cnki_proxy.py +153 -153
- re_common/vip/proxy/kuaidaili.py +87 -87
- re_common/vip/proxy/proxy_all.py +113 -113
- re_common/vip/proxy/update_kuaidaili_0.py +42 -42
- re_common/vip/proxy/wanfang_proxy.py +152 -152
- re_common/vip/proxy/wp_proxy_all.py +181 -181
- re_common/vip/read_rawid_to_txt.py +91 -91
- re_common/vip/title/__init__.py +5 -5
- re_common/vip/title/transform/TransformBookTitleToZt.py +125 -125
- re_common/vip/title/transform/TransformConferenceTitleToZt.py +139 -139
- re_common/vip/title/transform/TransformCstadTitleToZt.py +195 -195
- re_common/vip/title/transform/TransformJournalTitleToZt.py +203 -203
- re_common/vip/title/transform/TransformPatentTitleToZt.py +132 -132
- re_common/vip/title/transform/TransformRegulationTitleToZt.py +114 -114
- re_common/vip/title/transform/TransformStandardTitleToZt.py +135 -135
- re_common/vip/title/transform/TransformThesisTitleToZt.py +135 -135
- re_common/vip/title/transform/__init__.py +10 -10
- {re_common-10.0.37.dist-info → re_common-10.0.39.dist-info}/LICENSE +201 -201
- {re_common-10.0.37.dist-info → re_common-10.0.39.dist-info}/METADATA +16 -16
- re_common-10.0.39.dist-info/RECORD +248 -0
- {re_common-10.0.37.dist-info → re_common-10.0.39.dist-info}/WHEEL +1 -1
- re_common-10.0.37.dist-info/RECORD +0 -248
- {re_common-10.0.37.dist-info → re_common-10.0.39.dist-info}/top_level.txt +0 -0
|
@@ -1,214 +1,214 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import socket
|
|
3
|
-
import threading
|
|
4
|
-
import time
|
|
5
|
-
import traceback
|
|
6
|
-
from ftplib import FTP
|
|
7
|
-
|
|
8
|
-
import socks
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class BaseFtp(object):
|
|
12
|
-
def __init__(self, encoding='utf-8'):
|
|
13
|
-
self.ftp = FTP()
|
|
14
|
-
self.ftp.encoding = encoding
|
|
15
|
-
|
|
16
|
-
def set_proxy_socks(self, type, ip, port):
|
|
17
|
-
"""
|
|
18
|
-
type = socks.PROXY_TYPE_SOCKS5
|
|
19
|
-
:param type:
|
|
20
|
-
:param ip:
|
|
21
|
-
:param port:
|
|
22
|
-
:return:
|
|
23
|
-
"""
|
|
24
|
-
socks.set_default_proxy(type, ip, port)
|
|
25
|
-
socket.socket = socks.socksocket
|
|
26
|
-
return self
|
|
27
|
-
|
|
28
|
-
def conn_ftp(self, ftp_host, port=21):
|
|
29
|
-
self.ftp.connect(ftp_host, port)
|
|
30
|
-
return self
|
|
31
|
-
|
|
32
|
-
def login(self, username, passwd):
|
|
33
|
-
self.ftp.login(username, passwd)
|
|
34
|
-
return self
|
|
35
|
-
|
|
36
|
-
def set_conn_login_pare(self, ftp_host, port, username, passwd):
|
|
37
|
-
"""
|
|
38
|
-
设置参数
|
|
39
|
-
:return:
|
|
40
|
-
"""
|
|
41
|
-
self.ftp_host = ftp_host
|
|
42
|
-
self.port = port
|
|
43
|
-
self.username = username
|
|
44
|
-
self.passwd = passwd
|
|
45
|
-
return self
|
|
46
|
-
|
|
47
|
-
def conn_and_login(self):
|
|
48
|
-
self.conn_ftp(self.ftp_host, self.port)
|
|
49
|
-
self.login(self.username, self.passwd)
|
|
50
|
-
return self
|
|
51
|
-
|
|
52
|
-
def cwd(self, dir):
|
|
53
|
-
"""
|
|
54
|
-
更改到目录
|
|
55
|
-
:param dires:
|
|
56
|
-
:return:
|
|
57
|
-
"""
|
|
58
|
-
return self.ftp.cwd(dir) # change remote work dir
|
|
59
|
-
|
|
60
|
-
def pwd(self):
|
|
61
|
-
"""
|
|
62
|
-
返回当前FTP操作的路径
|
|
63
|
-
:return:
|
|
64
|
-
"""
|
|
65
|
-
return self.ftp.pwd()
|
|
66
|
-
|
|
67
|
-
def size(self, remotefile):
|
|
68
|
-
return self.ftp.size(remotefile)
|
|
69
|
-
|
|
70
|
-
def voidcmd(self, cmd):
|
|
71
|
-
"""
|
|
72
|
-
和FTP.sendcmd(command)功能相似,但返回代码不在200-299之间时抛出异常
|
|
73
|
-
FTP.sendcmd(command):向服务器发送一条简单的FTP命令,返回响应结果
|
|
74
|
-
'TYPE I'
|
|
75
|
-
f"MDTM {ftp_path}" 获取时间
|
|
76
|
-
:return:
|
|
77
|
-
"""
|
|
78
|
-
return self.ftp.voidcmd(cmd)
|
|
79
|
-
|
|
80
|
-
def retrlines(self, cmd, callback=None):
|
|
81
|
-
"""
|
|
82
|
-
返回list的数据格式为liunx权限的格式
|
|
83
|
-
dr-x------ 3 user group 0 Jan 26 11:10 CN-IC-DECO-RE 中国集成电路布图设计复审撤销案件数据
|
|
84
|
-
:param cmd: RETR、LIST或NLST命令
|
|
85
|
-
LIST以列表形式检索有关文件及其详细信息。NLST只是以列表展示文件名
|
|
86
|
-
RETR 下载
|
|
87
|
-
MLSD: 更好的信息展示
|
|
88
|
-
:param callback: 一个被调用的可选的单个参数,为每一行去掉后面的CRLF
|
|
89
|
-
比如放入列表 可以传入
|
|
90
|
-
filelist = []
|
|
91
|
-
filelist.append
|
|
92
|
-
:return:
|
|
93
|
-
"""
|
|
94
|
-
return self.ftp.retrlines(cmd, callback)
|
|
95
|
-
|
|
96
|
-
def set_pasv(self, val):
|
|
97
|
-
"""
|
|
98
|
-
val:为True时,启用被动模式;反之,禁用。默认情况下是被动模式
|
|
99
|
-
:param val:
|
|
100
|
-
:return:
|
|
101
|
-
"""
|
|
102
|
-
return self.ftp.set_pasv(val)
|
|
103
|
-
|
|
104
|
-
def get_file_info(self, file_str):
|
|
105
|
-
"""
|
|
106
|
-
将str 转换成字典
|
|
107
|
-
:param file_str:
|
|
108
|
-
:return:
|
|
109
|
-
"""
|
|
110
|
-
dicts = {}
|
|
111
|
-
dicts["time"] = []
|
|
112
|
-
dicts["filename"] = []
|
|
113
|
-
lists = file_str.split()
|
|
114
|
-
count = 0
|
|
115
|
-
for item in lists:
|
|
116
|
-
item = item.strip()
|
|
117
|
-
if item != "" and count <= 8:
|
|
118
|
-
count = count + 1
|
|
119
|
-
if count == 1:
|
|
120
|
-
# 文件属性字段
|
|
121
|
-
"""
|
|
122
|
-
文件属性字段总共有10个字母组成;第一个字符代表文件的类型。
|
|
123
|
-
字母“-”表示该文件是一个普通文件
|
|
124
|
-
字母“d”表示该文件是一个目录,字母"d",是dirtectory(目录)的缩写
|
|
125
|
-
注意:目录或者是特殊文件,这个特殊文件存放其他文件或目录的相关信息
|
|
126
|
-
字母“l”表示该文件是一个链接文件。字母"l"是link(链接)的缩写,类似于windows下的快捷方式
|
|
127
|
-
字母“b”的表示块设备文件(block),一般置于/dev目录下,设备文件是普通文件和程序访问硬件设备的入口,是很特殊的文件。没有文件大小,只有一个主设备号和一个辅设备号。一次传输数据为一整块的被称为块设备,如硬盘、光盘等。最小数据传输单位为一个数据块(通常一个数据块的大小为512字节)
|
|
128
|
-
字母为“c”表示该文件是一个字符设备文件(character),一般置于/dev目录下,一次传输一个字节的设备被称为字符设备,如键盘、字符终端等,传输数据的最小单位为一个字节。
|
|
129
|
-
字母为“p”表示该文件为命令管道文件。与shell编程有关的文件。
|
|
130
|
-
字母“s”表示该文件为sock文件。与shell编程有关的文件。
|
|
131
|
-
"""
|
|
132
|
-
dicts["file_info"] = item
|
|
133
|
-
if count == 2:
|
|
134
|
-
# 文件硬链接数 如果是一个目录,则第2字段表示该目录所含子目录的个数。
|
|
135
|
-
dicts["file_hardlink_num"] = item
|
|
136
|
-
if count == 3:
|
|
137
|
-
dicts["user"] = item
|
|
138
|
-
if count == 4:
|
|
139
|
-
dicts["group"] = item
|
|
140
|
-
|
|
141
|
-
if count == 5:
|
|
142
|
-
# 文件所占用的空间(以字节为单位)
|
|
143
|
-
dicts["size"] = item
|
|
144
|
-
|
|
145
|
-
if count in (6, 7, 8):
|
|
146
|
-
# 件(目录)最近访问(修改)时间
|
|
147
|
-
dicts["time"].append(item)
|
|
148
|
-
if count == 8:
|
|
149
|
-
count = count + 1
|
|
150
|
-
else:
|
|
151
|
-
dicts["filename"].append(item)
|
|
152
|
-
|
|
153
|
-
dicts["filename"] = " ".join(dicts["filename"])
|
|
154
|
-
dicts["time"] = " ".join(dicts["time"])
|
|
155
|
-
return dicts
|
|
156
|
-
|
|
157
|
-
def get_file_info_MLSD(self, file_str):
|
|
158
|
-
"""
|
|
159
|
-
MLSD 模式下转换为字典
|
|
160
|
-
:param file_str:
|
|
161
|
-
:return:
|
|
162
|
-
"""
|
|
163
|
-
dicts = {}
|
|
164
|
-
lists = file_str.split(";")
|
|
165
|
-
dicts["size"] = lists[0].replace("Size=", "")
|
|
166
|
-
dicts["time"] = lists[1].replace("Modify=", "")
|
|
167
|
-
dicts["type"] = lists[2].replace("Type=", "")
|
|
168
|
-
dicts["filename"] = lists[3][1:]
|
|
169
|
-
return dicts
|
|
170
|
-
|
|
171
|
-
def down_file(self, ftp_path, local_path, blocksize=1024):
|
|
172
|
-
"""
|
|
173
|
-
下载一个文件
|
|
174
|
-
:return:
|
|
175
|
-
"""
|
|
176
|
-
local_file_size = 0
|
|
177
|
-
if os.path.exists(local_path):
|
|
178
|
-
local_file_size = os.path.getsize(local_path)
|
|
179
|
-
try:
|
|
180
|
-
ftp_file_size = self.size(ftp_path)
|
|
181
|
-
# TYPE I表示以二进制模式传输
|
|
182
|
-
self.voidcmd('TYPE I')
|
|
183
|
-
# 下载ftp 目标文件 local_file_size 需要跳过的size
|
|
184
|
-
conn = self.ftp.transfercmd('RETR ' + ftp_path, local_file_size)
|
|
185
|
-
with open(local_path, 'ab+') as file:
|
|
186
|
-
if local_file_size == 0 or local_file_size > ftp_file_size:
|
|
187
|
-
file.truncate()
|
|
188
|
-
recv_num = 0
|
|
189
|
-
# 次数
|
|
190
|
-
times = 0
|
|
191
|
-
while True:
|
|
192
|
-
data = conn.recv(blocksize)
|
|
193
|
-
times = times + 1
|
|
194
|
-
recv_num = recv_num + len(data)
|
|
195
|
-
if times >= 1000:
|
|
196
|
-
print("P/T {}:{} Time {}".format(os.getpid(), threading.get_ident(),
|
|
197
|
-
time.strftime('%Y-%m-%d %H:%M:%S',
|
|
198
|
-
time.localtime(time.time()))), recv_num)
|
|
199
|
-
times = 0
|
|
200
|
-
recv_num = 0
|
|
201
|
-
if not data:
|
|
202
|
-
break
|
|
203
|
-
file.write(data)
|
|
204
|
-
# 此命令不产生什么实际动作,它仅使服务器返回OK。
|
|
205
|
-
result = self.voidcmd('NOOP')
|
|
206
|
-
print(result)
|
|
207
|
-
# 期待以“2”开头的回复
|
|
208
|
-
result = self.ftp.voidresp()
|
|
209
|
-
print(result)
|
|
210
|
-
return True
|
|
211
|
-
except:
|
|
212
|
-
self.ftp.quit()
|
|
213
|
-
traceback.print_exc()
|
|
214
|
-
return False
|
|
1
|
+
import os
|
|
2
|
+
import socket
|
|
3
|
+
import threading
|
|
4
|
+
import time
|
|
5
|
+
import traceback
|
|
6
|
+
from ftplib import FTP
|
|
7
|
+
|
|
8
|
+
import socks
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class BaseFtp(object):
|
|
12
|
+
def __init__(self, encoding='utf-8'):
|
|
13
|
+
self.ftp = FTP()
|
|
14
|
+
self.ftp.encoding = encoding
|
|
15
|
+
|
|
16
|
+
def set_proxy_socks(self, type, ip, port):
|
|
17
|
+
"""
|
|
18
|
+
type = socks.PROXY_TYPE_SOCKS5
|
|
19
|
+
:param type:
|
|
20
|
+
:param ip:
|
|
21
|
+
:param port:
|
|
22
|
+
:return:
|
|
23
|
+
"""
|
|
24
|
+
socks.set_default_proxy(type, ip, port)
|
|
25
|
+
socket.socket = socks.socksocket
|
|
26
|
+
return self
|
|
27
|
+
|
|
28
|
+
def conn_ftp(self, ftp_host, port=21):
|
|
29
|
+
self.ftp.connect(ftp_host, port)
|
|
30
|
+
return self
|
|
31
|
+
|
|
32
|
+
def login(self, username, passwd):
|
|
33
|
+
self.ftp.login(username, passwd)
|
|
34
|
+
return self
|
|
35
|
+
|
|
36
|
+
def set_conn_login_pare(self, ftp_host, port, username, passwd):
|
|
37
|
+
"""
|
|
38
|
+
设置参数
|
|
39
|
+
:return:
|
|
40
|
+
"""
|
|
41
|
+
self.ftp_host = ftp_host
|
|
42
|
+
self.port = port
|
|
43
|
+
self.username = username
|
|
44
|
+
self.passwd = passwd
|
|
45
|
+
return self
|
|
46
|
+
|
|
47
|
+
def conn_and_login(self):
|
|
48
|
+
self.conn_ftp(self.ftp_host, self.port)
|
|
49
|
+
self.login(self.username, self.passwd)
|
|
50
|
+
return self
|
|
51
|
+
|
|
52
|
+
def cwd(self, dir):
|
|
53
|
+
"""
|
|
54
|
+
更改到目录
|
|
55
|
+
:param dires:
|
|
56
|
+
:return:
|
|
57
|
+
"""
|
|
58
|
+
return self.ftp.cwd(dir) # change remote work dir
|
|
59
|
+
|
|
60
|
+
def pwd(self):
|
|
61
|
+
"""
|
|
62
|
+
返回当前FTP操作的路径
|
|
63
|
+
:return:
|
|
64
|
+
"""
|
|
65
|
+
return self.ftp.pwd()
|
|
66
|
+
|
|
67
|
+
def size(self, remotefile):
|
|
68
|
+
return self.ftp.size(remotefile)
|
|
69
|
+
|
|
70
|
+
def voidcmd(self, cmd):
|
|
71
|
+
"""
|
|
72
|
+
和FTP.sendcmd(command)功能相似,但返回代码不在200-299之间时抛出异常
|
|
73
|
+
FTP.sendcmd(command):向服务器发送一条简单的FTP命令,返回响应结果
|
|
74
|
+
'TYPE I'
|
|
75
|
+
f"MDTM {ftp_path}" 获取时间
|
|
76
|
+
:return:
|
|
77
|
+
"""
|
|
78
|
+
return self.ftp.voidcmd(cmd)
|
|
79
|
+
|
|
80
|
+
def retrlines(self, cmd, callback=None):
|
|
81
|
+
"""
|
|
82
|
+
返回list的数据格式为liunx权限的格式
|
|
83
|
+
dr-x------ 3 user group 0 Jan 26 11:10 CN-IC-DECO-RE 中国集成电路布图设计复审撤销案件数据
|
|
84
|
+
:param cmd: RETR、LIST或NLST命令
|
|
85
|
+
LIST以列表形式检索有关文件及其详细信息。NLST只是以列表展示文件名
|
|
86
|
+
RETR 下载
|
|
87
|
+
MLSD: 更好的信息展示
|
|
88
|
+
:param callback: 一个被调用的可选的单个参数,为每一行去掉后面的CRLF
|
|
89
|
+
比如放入列表 可以传入
|
|
90
|
+
filelist = []
|
|
91
|
+
filelist.append
|
|
92
|
+
:return:
|
|
93
|
+
"""
|
|
94
|
+
return self.ftp.retrlines(cmd, callback)
|
|
95
|
+
|
|
96
|
+
def set_pasv(self, val):
|
|
97
|
+
"""
|
|
98
|
+
val:为True时,启用被动模式;反之,禁用。默认情况下是被动模式
|
|
99
|
+
:param val:
|
|
100
|
+
:return:
|
|
101
|
+
"""
|
|
102
|
+
return self.ftp.set_pasv(val)
|
|
103
|
+
|
|
104
|
+
def get_file_info(self, file_str):
|
|
105
|
+
"""
|
|
106
|
+
将str 转换成字典
|
|
107
|
+
:param file_str:
|
|
108
|
+
:return:
|
|
109
|
+
"""
|
|
110
|
+
dicts = {}
|
|
111
|
+
dicts["time"] = []
|
|
112
|
+
dicts["filename"] = []
|
|
113
|
+
lists = file_str.split()
|
|
114
|
+
count = 0
|
|
115
|
+
for item in lists:
|
|
116
|
+
item = item.strip()
|
|
117
|
+
if item != "" and count <= 8:
|
|
118
|
+
count = count + 1
|
|
119
|
+
if count == 1:
|
|
120
|
+
# 文件属性字段
|
|
121
|
+
"""
|
|
122
|
+
文件属性字段总共有10个字母组成;第一个字符代表文件的类型。
|
|
123
|
+
字母“-”表示该文件是一个普通文件
|
|
124
|
+
字母“d”表示该文件是一个目录,字母"d",是dirtectory(目录)的缩写
|
|
125
|
+
注意:目录或者是特殊文件,这个特殊文件存放其他文件或目录的相关信息
|
|
126
|
+
字母“l”表示该文件是一个链接文件。字母"l"是link(链接)的缩写,类似于windows下的快捷方式
|
|
127
|
+
字母“b”的表示块设备文件(block),一般置于/dev目录下,设备文件是普通文件和程序访问硬件设备的入口,是很特殊的文件。没有文件大小,只有一个主设备号和一个辅设备号。一次传输数据为一整块的被称为块设备,如硬盘、光盘等。最小数据传输单位为一个数据块(通常一个数据块的大小为512字节)
|
|
128
|
+
字母为“c”表示该文件是一个字符设备文件(character),一般置于/dev目录下,一次传输一个字节的设备被称为字符设备,如键盘、字符终端等,传输数据的最小单位为一个字节。
|
|
129
|
+
字母为“p”表示该文件为命令管道文件。与shell编程有关的文件。
|
|
130
|
+
字母“s”表示该文件为sock文件。与shell编程有关的文件。
|
|
131
|
+
"""
|
|
132
|
+
dicts["file_info"] = item
|
|
133
|
+
if count == 2:
|
|
134
|
+
# 文件硬链接数 如果是一个目录,则第2字段表示该目录所含子目录的个数。
|
|
135
|
+
dicts["file_hardlink_num"] = item
|
|
136
|
+
if count == 3:
|
|
137
|
+
dicts["user"] = item
|
|
138
|
+
if count == 4:
|
|
139
|
+
dicts["group"] = item
|
|
140
|
+
|
|
141
|
+
if count == 5:
|
|
142
|
+
# 文件所占用的空间(以字节为单位)
|
|
143
|
+
dicts["size"] = item
|
|
144
|
+
|
|
145
|
+
if count in (6, 7, 8):
|
|
146
|
+
# 件(目录)最近访问(修改)时间
|
|
147
|
+
dicts["time"].append(item)
|
|
148
|
+
if count == 8:
|
|
149
|
+
count = count + 1
|
|
150
|
+
else:
|
|
151
|
+
dicts["filename"].append(item)
|
|
152
|
+
|
|
153
|
+
dicts["filename"] = " ".join(dicts["filename"])
|
|
154
|
+
dicts["time"] = " ".join(dicts["time"])
|
|
155
|
+
return dicts
|
|
156
|
+
|
|
157
|
+
def get_file_info_MLSD(self, file_str):
|
|
158
|
+
"""
|
|
159
|
+
MLSD 模式下转换为字典
|
|
160
|
+
:param file_str:
|
|
161
|
+
:return:
|
|
162
|
+
"""
|
|
163
|
+
dicts = {}
|
|
164
|
+
lists = file_str.split(";")
|
|
165
|
+
dicts["size"] = lists[0].replace("Size=", "")
|
|
166
|
+
dicts["time"] = lists[1].replace("Modify=", "")
|
|
167
|
+
dicts["type"] = lists[2].replace("Type=", "")
|
|
168
|
+
dicts["filename"] = lists[3][1:]
|
|
169
|
+
return dicts
|
|
170
|
+
|
|
171
|
+
def down_file(self, ftp_path, local_path, blocksize=1024):
|
|
172
|
+
"""
|
|
173
|
+
下载一个文件
|
|
174
|
+
:return:
|
|
175
|
+
"""
|
|
176
|
+
local_file_size = 0
|
|
177
|
+
if os.path.exists(local_path):
|
|
178
|
+
local_file_size = os.path.getsize(local_path)
|
|
179
|
+
try:
|
|
180
|
+
ftp_file_size = self.size(ftp_path)
|
|
181
|
+
# TYPE I表示以二进制模式传输
|
|
182
|
+
self.voidcmd('TYPE I')
|
|
183
|
+
# 下载ftp 目标文件 local_file_size 需要跳过的size
|
|
184
|
+
conn = self.ftp.transfercmd('RETR ' + ftp_path, local_file_size)
|
|
185
|
+
with open(local_path, 'ab+') as file:
|
|
186
|
+
if local_file_size == 0 or local_file_size > ftp_file_size:
|
|
187
|
+
file.truncate()
|
|
188
|
+
recv_num = 0
|
|
189
|
+
# 次数
|
|
190
|
+
times = 0
|
|
191
|
+
while True:
|
|
192
|
+
data = conn.recv(blocksize)
|
|
193
|
+
times = times + 1
|
|
194
|
+
recv_num = recv_num + len(data)
|
|
195
|
+
if times >= 1000:
|
|
196
|
+
print("P/T {}:{} Time {}".format(os.getpid(), threading.get_ident(),
|
|
197
|
+
time.strftime('%Y-%m-%d %H:%M:%S',
|
|
198
|
+
time.localtime(time.time()))), recv_num)
|
|
199
|
+
times = 0
|
|
200
|
+
recv_num = 0
|
|
201
|
+
if not data:
|
|
202
|
+
break
|
|
203
|
+
file.write(data)
|
|
204
|
+
# 此命令不产生什么实际动作,它仅使服务器返回OK。
|
|
205
|
+
result = self.voidcmd('NOOP')
|
|
206
|
+
print(result)
|
|
207
|
+
# 期待以“2”开头的回复
|
|
208
|
+
result = self.ftp.voidresp()
|
|
209
|
+
print(result)
|
|
210
|
+
return True
|
|
211
|
+
except:
|
|
212
|
+
self.ftp.quit()
|
|
213
|
+
traceback.print_exc()
|
|
214
|
+
return False
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import gzip
|
|
2
|
-
|
|
3
|
-
from re_common.baselibrary.utils.basefile import BaseFile
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class BaseGzip(object):
|
|
7
|
-
|
|
8
|
-
def __init__(self, bufsize, fin=None, fout=None):
|
|
9
|
-
self.bufsize = bufsize
|
|
10
|
-
self.fin = fin
|
|
11
|
-
self.fout = fout
|
|
12
|
-
|
|
13
|
-
def compress(self, src, dst):
|
|
14
|
-
"""
|
|
15
|
-
压缩文件
|
|
16
|
-
:param src:
|
|
17
|
-
:param dst:
|
|
18
|
-
:return:
|
|
19
|
-
"""
|
|
20
|
-
self.fin = open(src, 'rb')
|
|
21
|
-
self.fout = gzip.open(dst, 'wb')
|
|
22
|
-
|
|
23
|
-
self.__in2out()
|
|
24
|
-
|
|
25
|
-
def decompress(self, gzFile, dst):
|
|
26
|
-
"""
|
|
27
|
-
解压文件
|
|
28
|
-
:param gzFile:
|
|
29
|
-
:param dst:
|
|
30
|
-
:return:
|
|
31
|
-
"""
|
|
32
|
-
self.fin = gzip.open(gzFile, 'rb')
|
|
33
|
-
self.fout = open(dst, 'wb')
|
|
34
|
-
|
|
35
|
-
self.__in2out()
|
|
36
|
-
|
|
37
|
-
def __in2out(self):
|
|
38
|
-
while True:
|
|
39
|
-
buf = self.fin.read(self.bufsize)
|
|
40
|
-
if len(buf) < 1:
|
|
41
|
-
break
|
|
42
|
-
self.fout.write(buf)
|
|
43
|
-
|
|
44
|
-
self.fin.close()
|
|
45
|
-
self.fout.close()
|
|
46
|
-
|
|
47
|
-
def read_gz_file(self, file):
|
|
48
|
-
with gzip.open(file, 'r') as f:
|
|
49
|
-
for lineb in f:
|
|
50
|
-
line = lineb.decode()
|
|
51
|
-
yield line.strip()
|
|
52
|
-
|
|
53
|
-
@classmethod
|
|
54
|
-
def get_gz_line_num(self, file):
|
|
55
|
-
i = 0
|
|
56
|
-
if BaseFile.is_file_exists(file):
|
|
57
|
-
with gzip.open(file, 'rb') as f:
|
|
58
|
-
for i, l in enumerate(f):
|
|
59
|
-
pass
|
|
60
|
-
return i
|
|
1
|
+
import gzip
|
|
2
|
+
|
|
3
|
+
from re_common.baselibrary.utils.basefile import BaseFile
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class BaseGzip(object):
|
|
7
|
+
|
|
8
|
+
def __init__(self, bufsize, fin=None, fout=None):
|
|
9
|
+
self.bufsize = bufsize
|
|
10
|
+
self.fin = fin
|
|
11
|
+
self.fout = fout
|
|
12
|
+
|
|
13
|
+
def compress(self, src, dst):
|
|
14
|
+
"""
|
|
15
|
+
压缩文件
|
|
16
|
+
:param src:
|
|
17
|
+
:param dst:
|
|
18
|
+
:return:
|
|
19
|
+
"""
|
|
20
|
+
self.fin = open(src, 'rb')
|
|
21
|
+
self.fout = gzip.open(dst, 'wb')
|
|
22
|
+
|
|
23
|
+
self.__in2out()
|
|
24
|
+
|
|
25
|
+
def decompress(self, gzFile, dst):
|
|
26
|
+
"""
|
|
27
|
+
解压文件
|
|
28
|
+
:param gzFile:
|
|
29
|
+
:param dst:
|
|
30
|
+
:return:
|
|
31
|
+
"""
|
|
32
|
+
self.fin = gzip.open(gzFile, 'rb')
|
|
33
|
+
self.fout = open(dst, 'wb')
|
|
34
|
+
|
|
35
|
+
self.__in2out()
|
|
36
|
+
|
|
37
|
+
def __in2out(self):
|
|
38
|
+
while True:
|
|
39
|
+
buf = self.fin.read(self.bufsize)
|
|
40
|
+
if len(buf) < 1:
|
|
41
|
+
break
|
|
42
|
+
self.fout.write(buf)
|
|
43
|
+
|
|
44
|
+
self.fin.close()
|
|
45
|
+
self.fout.close()
|
|
46
|
+
|
|
47
|
+
def read_gz_file(self, file):
|
|
48
|
+
with gzip.open(file, 'r') as f:
|
|
49
|
+
for lineb in f:
|
|
50
|
+
line = lineb.decode()
|
|
51
|
+
yield line.strip()
|
|
52
|
+
|
|
53
|
+
@classmethod
|
|
54
|
+
def get_gz_line_num(self, file):
|
|
55
|
+
i = 0
|
|
56
|
+
if BaseFile.is_file_exists(file):
|
|
57
|
+
with gzip.open(file, 'rb') as f:
|
|
58
|
+
for i, l in enumerate(f):
|
|
59
|
+
pass
|
|
60
|
+
return i
|