mdbq 3.7.0__py3-none-any.whl → 3.7.1__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.
mdbq/bdup/bdup.py CHANGED
@@ -2,6 +2,7 @@
2
2
  import os
3
3
  import platform
4
4
  import subprocess
5
+ from concurrent.futures import ThreadPoolExecutor
5
6
  from bypy import ByPy
6
7
 
7
8
 
@@ -12,13 +13,15 @@ class BaiDu:
12
13
  def __init__(self):
13
14
  self.local_path = None
14
15
  self.remote_path = None
15
- self.skip = ['.DS_Store', '.localized', 'desktop.ini', '$RECYCLE.BIN', 'Icon']
16
- self.delete_remote_files = ['.DS_Store', '.localized', 'desktop.ini', '$RECYCLE.BIN', 'Icon']
16
+ self.skip:list = []
17
+ self.delete_remote_files:list = []
17
18
  self.bp = ByPy()
19
+ self.count = 0
20
+ self.total = 0
18
21
 
19
22
  def upload_dir(self, local_path, remote_path):
20
23
  """
21
- 上传整个文件夹,执行完后删除指定文件
24
+ 上传整个文件夹,执行完后删除指定文件, 指定 self.delete_remote_files
22
25
  如果通过调用命令行终端运行, 《云端路径!!》必须使用linux格式,不要使用反斜杆,否则在windows系统里面会上传失败
23
26
  """
24
27
  self.local_path = local_path
@@ -37,38 +40,59 @@ class BaiDu:
37
40
  print(e)
38
41
  self.delete_files() # 最好是在内部执行删除, 避免路径异常
39
42
 
40
- def upload_file(self, local_path, remote_path):
43
+ def upload_file(self, local_path, remote_path, processes=False):
41
44
  """
42
- 上传文件夹,按单个文件上传,可以跳过指定文件
45
+ 上传文件夹,按单个文件上传,可以跳过指定文件/文件夹, 指定 self.skip
43
46
  《云端路径!!》必须使用linux格式
44
47
  """
48
+ if not isinstance(self.skip, list):
49
+ raise TypeError('skip must be a list')
50
+ self.skip += ['.DS_Store', '.localized', 'desktop.ini', '$RECYCLE.BIN', 'Icon']
45
51
  self.local_path = local_path
46
52
  self.remote_path = remote_path.replace('\\', '/')
47
53
  if not os.path.exists(self.local_path):
48
54
  print(f'{self.local_path}: 本地目录不存在,没有什么可传的')
49
55
  return
50
56
 
51
- files = os.listdir(self.local_path)
52
- for file in files:
53
- if os.path.isfile(os.path.join(self.local_path, file)):
54
- if file in self.skip:
55
- continue
56
- lc_path = os.path.join(self.local_path, file)
57
+ local_files = os.listdir(self.local_path)
58
+
59
+ local_file_list = []
60
+ for file in local_files:
61
+ if file in self.skip: # 跳过指定文件/文件夹
62
+ continue
63
+ local_p = os.path.join(self.local_path, file)
64
+ if os.path.isfile(local_p):
57
65
  rt_path = os.path.join(self.remote_path, file).replace('\\', '/')
58
- print(f'上传: {file}')
59
- self.bp.upload(localpath=lc_path, remotepath=rt_path) # 上传文件到百度云
60
- elif os.path.isdir(os.path.join(self.local_path, file)):
61
- for root, dirs, files in os.walk(os.path.join(self.local_path, file), topdown=False):
66
+ self.total += 1
67
+ local_file_list.append({local_p: rt_path})
68
+ elif os.path.isdir(local_p):
69
+ for root, dirs, files in os.walk(local_p, topdown=False):
62
70
  for name in files:
63
- if name in self.skip:
71
+ if name in self.skip: # 从子文件夹内跳过指定文件
64
72
  continue
65
73
  lc_path = os.path.join(root, name)
66
74
  rt_path = lc_path.replace(self.local_path, self.remote_path).replace('\\', '/')
67
- print(f'上传: {name}')
68
- self.bp.upload(localpath=lc_path, remotepath=rt_path) # 上传文件到百度云
75
+ self.total += 1
76
+ local_file_list.append({lc_path: rt_path})
77
+ if processes:
78
+ # 不指定 max_workers 参数,默认值是 os.cpu_count() * 5
79
+ with ThreadPoolExecutor() as executor:
80
+ executor.map(self.up_one_file, local_file_list)
81
+ else:
82
+ for item in local_file_list:
83
+ self.up_one_file(file_dict=item)
84
+
85
+ def up_one_file(self, file_dict:dict):
86
+ if not isinstance(file_dict, dict):
87
+ raise TypeError('file_dict must be a dict')
88
+ for k, v in file_dict.items():
89
+ self.count += 1
90
+ print(f'上传: {self.count}/{self.total} {k}')
91
+ self.bp.upload(localpath=k, remotepath=v) # 上传文件到百度云
69
92
 
70
93
  def delete_files(self):
71
94
  """ 移除云端文件,位于 self.remote_path 文件夹下的子文件 """
95
+ self.delete_remote_files += ['.DS_Store', '.localized', 'desktop.ini', '$RECYCLE.BIN', 'Icon']
72
96
  for delete_file in self.delete_remote_files:
73
97
  self.bp.remove(remotepath=f'{self.remote_path.replace('\\', '/')}/{delete_file}') # 移除文件
74
98
 
@@ -83,9 +107,5 @@ class BaiDu:
83
107
 
84
108
 
85
109
  if __name__ == '__main__':
86
- pass
87
- import datetime
88
- upload_path = f'windows/{str(datetime.date.today().strftime("%Y-%m"))}/{str(datetime.date.today())}'
89
- b = BaiDu()
90
- # b.upload_dir(local_path='/Users/xigua/Downloads', remote_path=upload_path)
91
- b.download_dir(local_path='/Users/xigua/Downloads', remote_path=upload_path)
110
+ bp = ByPy()
111
+ bp.list()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mdbq
3
- Version: 3.7.0
3
+ Version: 3.7.1
4
4
  Home-page: https://pypi.org/project/mdbq
5
5
  Author: xigua,
6
6
  Author-email: 2587125111@qq.com
@@ -6,7 +6,7 @@ mdbq/aggregation/datashow_bak.py,sha256=1AYSIDkdUx-4as1Ax2rPj0cExM9d-qFMrFYLAaPH
6
6
  mdbq/aggregation/optimize_data.py,sha256=foZGLDGJRhM2qOr2mTvB3InDFId7r4KBXrJfB3-xq1k,2639
7
7
  mdbq/aggregation/query_data.py,sha256=AiG0W9Rum_hKCTPNB-nuA5ehpnVW12byLA7uwzOmO6Q,168639
8
8
  mdbq/bdup/__init__.py,sha256=AkhsGk81SkG1c8FqDH5tRq-8MZmFobVbN60DTyukYTY,28
9
- mdbq/bdup/bdup.py,sha256=LAV0TgnQpc-LB-YuJthxb0U42_VkPidzQzAagan46lU,4234
9
+ mdbq/bdup/bdup.py,sha256=hJs815hGFwm_X5bP2i9XugG2w2ZY_F0n3-Q0hVpIPPw,4892
10
10
  mdbq/config/__init__.py,sha256=jso1oHcy6cJEfa7udS_9uO5X6kZLoPBF8l3wCYmr5dM,18
11
11
  mdbq/config/default.py,sha256=3IGc4aVuoL6sZh7xkM0GUXwHJD3-HCfYTnb1Q5ZL1UM,4976
12
12
  mdbq/config/myconfig.py,sha256=Akt-7KqSUBdoHQa4_Mw6YC4pA75219d-21iDO30iaD8,894
@@ -36,7 +36,7 @@ mdbq/redis/__init__.py,sha256=YtgBlVSMDphtpwYX248wGge1x-Ex_mMufz4-8W0XRmA,12
36
36
  mdbq/redis/getredis.py,sha256=oyFwE-8c6uErSGYNIO0z2ng93mH0zstRLD86MWqF6M8,25636
37
37
  mdbq/spider/__init__.py,sha256=RBMFXGy_jd1HXZhngB2T2XTvJqki8P_Fr-pBcwijnew,18
38
38
  mdbq/spider/aikucun.py,sha256=1gAEwCUmhCSpOSRPD2EEcbH3bFGn4sUQnQUAsJb5-qM,19391
39
- mdbq-3.7.0.dist-info/METADATA,sha256=0uGaC5cgZEGGQq_U5XmvMzgUtGMK0o8_3CyLq4lKgpU,243
40
- mdbq-3.7.0.dist-info/WHEEL,sha256=cpQTJ5IWu9CdaPViMhC9YzF8gZuS5-vlfoFihTBC86A,91
41
- mdbq-3.7.0.dist-info/top_level.txt,sha256=2FQ-uLnCSB-OwFiWntzmwosW3X2Xqsg0ewh1axsaylA,5
42
- mdbq-3.7.0.dist-info/RECORD,,
39
+ mdbq-3.7.1.dist-info/METADATA,sha256=uHL1bLpTvZHQVsfp6WHV5Ceog2VTGOfZhcbj0-WW16I,243
40
+ mdbq-3.7.1.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
41
+ mdbq-3.7.1.dist-info/top_level.txt,sha256=2FQ-uLnCSB-OwFiWntzmwosW3X2Xqsg0ewh1axsaylA,5
42
+ mdbq-3.7.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (70.1.0)
2
+ Generator: bdist_wheel (0.44.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5