solax-py-library 1.0.0.21__py3-none-any.whl → 1.0.0.22__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.
@@ -34,8 +34,7 @@ class FTPUploadService(BaseUploadService):
34
34
  try:
35
35
  return FTPServiceConfig(**kwargs)
36
36
  except Exception as e:
37
- print(e)
38
- raise ConfigurationError
37
+ raise ConfigurationError(message=str(e))
39
38
 
40
39
  def connect(self):
41
40
  if self._client is not None:
@@ -47,17 +46,16 @@ class FTPUploadService(BaseUploadService):
47
46
  def _connect(self):
48
47
  try:
49
48
  self._client = ftplib.FTP()
49
+ self._client.encoding = "utf8" # 默认需要配置为utf8
50
50
  self._client.connect(self.host, self.port, timeout=self.timeout)
51
51
  except Exception as e:
52
- print(e)
53
- raise ConnectError
52
+ raise ConnectError(message=str(e))
54
53
 
55
54
  def _login(self):
56
55
  try:
57
56
  self._client.login(self.user, self.password)
58
57
  except Exception as e:
59
- print(e)
60
- raise LoginError
58
+ raise LoginError(message=str(e))
61
59
 
62
60
  def close(self):
63
61
  if self._client:
@@ -81,17 +79,24 @@ class FTPUploadService(BaseUploadService):
81
79
  try:
82
80
  if not self._is_connect:
83
81
  raise ConnectError(message="not connect yet")
82
+ self._cwd_folder()
84
83
  with open(data.file_path, "rb") as f:
85
- self._client.storbinary(
86
- f"STOR {self._build_remote_file(data.file_name)}", f
87
- )
84
+ self._client.storbinary(f"STOR {data.file_name}", f)
88
85
  print(f"Successfully uploaded to {data.file_name}")
89
86
  except Exception as e:
90
- print(e)
91
- raise SendDataError
87
+ raise SendDataError(message=str(e))
92
88
  finally:
93
89
  if os.path.exists(data.file_path):
94
90
  os.remove(data.file_path)
95
91
 
92
+ def _cwd_folder(self):
93
+ try:
94
+ self._client.cwd(self.remote_path)
95
+ except Exception as e:
96
+ print(f"CWD error: {e}")
97
+ self._client.mkd(self.remote_path)
98
+ self._client.cwd(self.remote_path)
99
+ print(f"mkdir {self.remote_path}, remove successfully")
100
+
96
101
  def _build_remote_file(self, file_name):
97
102
  return os.path.join(self.remote_path, file_name)
@@ -48,13 +48,45 @@ class FTPTest(unittest.TestCase):
48
48
  except LoginError:
49
49
  ...
50
50
 
51
- def test_ftp_upload(self):
51
+ def test_ftp_upload_to_windows(self):
52
52
  ftp_config = {
53
53
  "host": "10.1.31.181", # 测试host
54
54
  "port": 21,
55
55
  "user": "solax",
56
56
  "password": "123456",
57
- "remote_path": "/xixi",
57
+ "remote_path": "嘻嘻",
58
+ }
59
+ asyncio.run(
60
+ upload(
61
+ upload_type=UploadType.FTP,
62
+ configuration=ftp_config,
63
+ upload_data=UploadData(
64
+ upload_type=UploadType.FTP,
65
+ data=dict(
66
+ file_type=FTPFileType.CSV,
67
+ file_name="中文",
68
+ data=[
69
+ {
70
+ "EMS1000序列号": "XMG11A011L",
71
+ "EMS1000本地时间": "2025-02-11 15:39:10",
72
+ "EMS1000版本号": "V007.11.1",
73
+ "电站所在国家和地区": None,
74
+ "电站所在当前时区": None,
75
+ "电站系统类型": None,
76
+ }
77
+ ],
78
+ ),
79
+ ),
80
+ )
81
+ )
82
+
83
+ def test_ftp_upload_to_linux(self):
84
+ ftp_config = {
85
+ "host": "10.1.6.153", # 测试host
86
+ "port": 21,
87
+ "user": "ftpuser",
88
+ "password": "123456",
89
+ "remote_path": "你好呀",
58
90
  }
59
91
  asyncio.run(
60
92
  upload(
@@ -64,7 +96,7 @@ class FTPTest(unittest.TestCase):
64
96
  upload_type=UploadType.FTP,
65
97
  data=dict(
66
98
  file_type=FTPFileType.CSV,
67
- file_name="new_file",
99
+ file_name="中文",
68
100
  data=[
69
101
  {
70
102
  "EMS1000序列号": "XMG11A011L",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: solax-py-library
3
- Version: 1.0.0.21
3
+ Version: 1.0.0.22
4
4
  Summary: some common tool
5
5
  Author: shenlvyu
6
6
  Author-email: 13296718439@163.com
@@ -30,17 +30,17 @@ solax_py_library/upload/core/data_adapter/base.py,sha256=Va-SEe0eL3gobhNOnzHGkYB
30
30
  solax_py_library/upload/core/data_adapter/csv.py,sha256=8nlnV_43mMAR3re50MQJymzT5HYpZOo7eSeMsEfnEVE,861
31
31
  solax_py_library/upload/core/upload_service/__init__.py,sha256=uA-UeH31rDNxByeZwvPhNFHPV_-J8JyCev8geuc---k,269
32
32
  solax_py_library/upload/core/upload_service/base.py,sha256=dxCBVtPxDhN7oRTjnwnjtc2XAF4hyIz9HsYCJePlggg,912
33
- solax_py_library/upload/core/upload_service/ftp.py,sha256=3_H7m4o1yLil7FyFA4eA0XXvRXhvGo3sm9567Bno5n4,2896
33
+ solax_py_library/upload/core/upload_service/ftp.py,sha256=QGgL1wJwRFwIUaAWNqH4oupeu0W0bAN6CLffCil0GHc,3234
34
34
  solax_py_library/upload/exceptions/__init__.py,sha256=iSPPPHBP_aG9-9OCR_tCrGihL-uEIpSwvi9JZxSYbUk,194
35
35
  solax_py_library/upload/exceptions/upload_error.py,sha256=sqJvooTZxM9eKqFUV5-sI101xw24ubEdyUZq4mG8sbM,446
36
36
  solax_py_library/upload/test/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
37
- solax_py_library/upload/test/test_ftp.py,sha256=m4MSl3BDOXHYplpjuDNvFLnb5uIsRV-zoxdoIx_Kgs4,2609
37
+ solax_py_library/upload/test/test_ftp.py,sha256=Rq3ooQGwpqqinRU1V-vNBaDkSedR-bJgyWkIwe7dcfw,3799
38
38
  solax_py_library/upload/types/__init__.py,sha256=og9KBpYbcs36_S1izURj3vyHeuNOLJQrD9GpxK_JJaw,244
39
39
  solax_py_library/upload/types/client.py,sha256=fG674_QEpOw3ibO171lcxJ0cz27yGR_sd3zgiyr4yuI,492
40
40
  solax_py_library/upload/types/ftp.py,sha256=9kCeLB0g5Je19v4ifz8YYEsGOhJL1lKBO2C6V2VBndc,679
41
41
  solax_py_library/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
42
42
  solax_py_library/utils/common.py,sha256=bfnZcX9uM-PjJrYAFv1UMmZgt6bGR7MaOd7jRPNHGxw,1238
43
43
  solax_py_library/utils/struct_util.py,sha256=ER0F6W_QCGM98NItGbQLmdZtbPn1UAZ-qh2tnqHi004,943
44
- solax_py_library-1.0.0.21.dist-info/METADATA,sha256=odty7CefHj06sC_GrqU-4uwcUZzVOCKLYQW2R0iUK4E,1790
45
- solax_py_library-1.0.0.21.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
46
- solax_py_library-1.0.0.21.dist-info/RECORD,,
44
+ solax_py_library-1.0.0.22.dist-info/METADATA,sha256=UrLkxnXXmQNXQQCoBayTp45vcGFMjP4XQ5U5M4H0H7o,1790
45
+ solax_py_library-1.0.0.22.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
46
+ solax_py_library-1.0.0.22.dist-info/RECORD,,