ddi-fw 0.0.27__py3-none-any.whl → 0.0.28__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.
ddi_fw/utils/__init__.py CHANGED
@@ -1,3 +1,4 @@
1
1
  from .utils import create_folder_if_not_exists, utc_time_as_string,utc_time_as_string_simple_format, compress_and_save_data
2
2
  from .zip_helper import ZipHelper
3
+ from .py7zr_helper import Py7ZipHelper
3
4
  from .enums import UMLSCodeTypes, DrugBankTextDataTypes
@@ -0,0 +1,100 @@
1
+ from collections import defaultdict
2
+ import math
3
+ import py7zr
4
+ import os
5
+ from os.path import basename
6
+
7
+
8
+ class Py7ZipHelper:
9
+ def __init__(self):
10
+ pass
11
+
12
+ def create_archive_from_file(self, archive_name, file_path, output_path):
13
+ with py7zr.SevenZipFile(output_path+'/'+archive_name, 'w') as archive:
14
+ # for file in files_to_archive:
15
+ archive.write(file_path)
16
+
17
+ def create_archive_from_folder(self, archive_name, folder_path, output_path):
18
+ with py7zr.SevenZipFile(output_path+'/'+archive_name, 'w') as archive:
19
+ for root, dirs, files in os.walk(folder_path):
20
+ for file in files:
21
+ archive.write(os.path.join(root, file),
22
+ os.path.relpath(os.path.join(root, file),
23
+ os.path.join(folder_path, '..')))
24
+ # archive.write(root+"/"+file)
25
+
26
+ def create_archive_multiparts(self, zip_name, file_path, output_path, chunk_size):
27
+ parent_folder = os.path.dirname(file_path)
28
+
29
+ # parts_path = f"{parent_folder}/parts"
30
+ # create_folder_if_not_exists(parts_path)
31
+ # file_name, file_extension = os.path.splitext(file_path)
32
+ # file_name = os.path.basename(file_path)
33
+ # file_name, folder = get_file_name_and_folder(file_path)
34
+
35
+ if os.path.isdir(file_path):
36
+ self.create_archive_from_folder(zip_name, file_path, output_path)
37
+ elif os.path.isfile(file_path):
38
+ self.create_archive_from_file(zip_name, file_path, output_path)
39
+ else:
40
+ return
41
+ with open(output_path+'/'+zip_name, 'rb') as f:
42
+ chunk_number = 1
43
+ while True:
44
+ chunk = f.read(chunk_size)
45
+ if not chunk:
46
+ break
47
+ with open(f"{output_path}/{zip_name}.part{chunk_number:03}", 'wb') as chunk_file:
48
+ chunk_file.write(chunk)
49
+ chunk_number += 1
50
+ if os.path.exists(output_path+'/'+zip_name):
51
+ os.remove(output_path+'/'+zip_name)
52
+
53
+ def create_archive(self, zip_prefix, input_path, output_path, chunk_size):
54
+ files_paths = [input_path+'/' + p for p in os.listdir(input_path)]
55
+ count_of_chunks = math.ceil(len(files_paths) / chunk_size)
56
+ zero_padding_length = len(str(int(count_of_chunks))) + 2
57
+
58
+ if not os.path.exists(output_path):
59
+ os.makedirs(output_path)
60
+
61
+ part = 1
62
+ i = 0
63
+ zip_dict = defaultdict(list)
64
+ for filePath in files_paths:
65
+ padded_part = f'{part}'.zfill(zero_padding_length)
66
+ key = f'{zip_prefix}.{padded_part}'
67
+ zip_dict[key].append(filePath)
68
+ i += 1
69
+ if i % chunk_size == 0:
70
+ i = 0
71
+ part += 1
72
+
73
+ for key, value in zip_dict.items():
74
+ with py7zr.SevenZipFile(f'{output_path}/{key}.7z', 'w') as archive:
75
+ for file_path in value:
76
+ archive.write(file_path, basename(file_path))
77
+
78
+ def extract(self, input_path, output_path):
79
+ files_paths = [input_path+'/' + p for p in os.listdir(input_path)]
80
+ if not os.path.exists(output_path):
81
+ os.makedirs(output_path)
82
+ for file_path in files_paths:
83
+ if file_path.endswith('7z'):
84
+ with py7zr.SevenZipFile(file_path, 'r') as z1:
85
+ z1.extractall(path=output_path)
86
+ print(f'{file_path} has been extracted')
87
+
88
+ def extract_archive(self, archive_name, extract_path):
89
+ with py7zr.SevenZipFile(archive_name, 'r') as archive:
90
+ archive.extractall(path=extract_path)
91
+
92
+ def extract_multiparts(self, input_path, output_path, output_file):
93
+ parts = [input_path+'/' + p for p in os.listdir(input_path)]
94
+ # create_folder_if_not_exists(output_path)
95
+ with open(f"{output_path}/{output_file}", 'wb') as outfile:
96
+ for part in parts:
97
+ with open(part, 'rb') as infile:
98
+ outfile.write(infile.read())
99
+ self.extract_archive(f"{output_path}/{output_file}", output_path)
100
+ os.remove(f"{output_path}/{output_file}")
@@ -58,7 +58,7 @@ class ZipHelper:
58
58
  chunk = f.read(chunk_size)
59
59
  if not chunk:
60
60
  break
61
- with open(f"{output_path}/{zip_name}.part{chunk_number:03}.zip", 'wb') as chunk_file:
61
+ with open(f"{output_path}/{zip_name}.zip.part{chunk_number:03}", 'wb') as chunk_file:
62
62
  chunk_file.write(chunk)
63
63
  chunk_number += 1
64
64
  if os.path.exists(output_path+'/'+zip_name+'.zip'):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ddi_fw
3
- Version: 0.0.27
3
+ Version: 0.0.28
4
4
  Summary: Do not use :)
5
5
  Author-email: Kıvanç Bayraktar <bayraktarkivanc@gmail.com>
6
6
  Maintainer-email: Kıvanç Bayraktar <bayraktarkivanc@gmail.com>
@@ -40,4 +40,5 @@ Requires-Dist: tokenizers
40
40
  Requires-Dist: tqdm
41
41
  Requires-Dist: xmlschema
42
42
  Requires-Dist: zipp
43
+ Requires-Dist: py7zr
43
44
 
@@ -75,11 +75,12 @@ ddi_fw/test/sklearn-tfidf.py,sha256=cjtg27vLskEMXgrsqUR_EapRGVd4xgwOQ9zYsu72zjs,
75
75
  ddi_fw/test/test.py,sha256=zJh9ZBcZl-vZIFDvuftcRrRV8WAwtiFVhPPd6Et4OU4,2997
76
76
  ddi_fw/test/torch_cuda_test.py,sha256=R-4VGVErl_Ufk54DoZbgL_YXWoCYFyanIVWd6P39IEk,312
77
77
  ddi_fw/test/type_guarding_test.py,sha256=KxjyBxohDu7lwpejalCj-REjtJ-k1S1wQbOB6TGY0O8,766
78
- ddi_fw/utils/__init__.py,sha256=nhNU_sEp55xsZ5VtvhozjKg6r4GWP6SJI13v8F_jbCg,217
78
+ ddi_fw/utils/__init__.py,sha256=cbvKldLWGINnVWIVwRQ04zdJpqOf-Ci9X03I8OgmJcw,257
79
79
  ddi_fw/utils/enums.py,sha256=19eJ3fX5eRK_xPvkYcukmug144jXPH4X9zQqtsFBj5A,671
80
+ ddi_fw/utils/py7zr_helper.py,sha256=c3itu4YwcnHX4gwxKd-7v3q50cz4doyJwHUEQnHR7zM,4305
80
81
  ddi_fw/utils/utils.py,sha256=Na6Y8mY-CFbQjrgd9xC8agcrjVvTj_7KIXqFm1H_3qU,3549
81
- ddi_fw/utils/zip_helper.py,sha256=9BzT5jnpqtiEprV8sI-fIz-2-og-8o2wlifSXPp_jv0,5479
82
- ddi_fw-0.0.27.dist-info/METADATA,sha256=xq1C1HN_BnaimD50kcijGFTqDR9HjGmb1a_2QsXPu5I,1541
83
- ddi_fw-0.0.27.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
84
- ddi_fw-0.0.27.dist-info/top_level.txt,sha256=PMwHICFZTZtcpzQNPV4UQnfNXYIeLR_Ste-Wfc1h810,7
85
- ddi_fw-0.0.27.dist-info/RECORD,,
82
+ ddi_fw/utils/zip_helper.py,sha256=7HHxOVAeltxRfNNtQPGojCAo7WiypWg_aVMR4NSj0Ys,5479
83
+ ddi_fw-0.0.28.dist-info/METADATA,sha256=fxaezPvDWpy98dSdPTnF-PCK0HJFfBbOm2IHCuo5r5k,1563
84
+ ddi_fw-0.0.28.dist-info/WHEEL,sha256=5Mi1sN9lKoFv_gxcPtisEVrJZihrm_beibeg5R6xb4I,91
85
+ ddi_fw-0.0.28.dist-info/top_level.txt,sha256=PMwHICFZTZtcpzQNPV4UQnfNXYIeLR_Ste-Wfc1h810,7
86
+ ddi_fw-0.0.28.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (74.1.2)
2
+ Generator: setuptools (75.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5