-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
168 lines (105 loc) · 4.56 KB
/
Copy pathmain.py
File metadata and controls
168 lines (105 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 20 01:31:02 2025
@author: duidu, MCHIGM
"""
# %%
class FileTransfer:
def __init__(self, folder_path, zip_name): # Initialize class
self.folder_path = folder_path
self.zip_name = zip_name
self.default_path = r"C:\/\/Program Files\/CHATu\/temp\/Files"
# This code provides a class to create a zip archive from a file/folder.
class ZipFolder:
def create_zip1(self): # Zip file for small files
import shutil
shutil.make_archive(self.zip_name, 'zip', self.folder_path)
return 1
def create_zip2(self): # Zip file for large folders
import zipfile
import os
with zipfile.ZipFile(self.zip_name, 'w', zipfile.ZIP_DEFLATED) as zipf:
for root, dirs, files in os.walk(self.folder_path):
for file in files:
file_path = os.path.join(root, file)
arcname = os.path.relpath(file_path, self.folder_path)
zipf.write(file_path, arcname)
return 1
ZF = ZipFolder # This is to make things eazier
### DO NOT MESS UP WITH zipfile.Zipfile since that has low compress rate ###
# This code provides a class to get file size f
class FileSize:
def filesize(self): # Get file size for small file
from pathlib import Path
p = Path(self.zip_name)
size_bytes = p.stat().st_size
return f"Size: {size_bytes} bytes"
def folder_size(self): # Get folder size
import os
total_size = 0
for dirpath, dirnames, filenames in os.walk(self.folder_path):
for f in filenames:
fp = os.path.join(dirpath, f)
total_size += os.path.getsize(fp)
return total_size
def zip_suffle(self): # Get all file size in a folder
import os
l = []
for root, dirs, files in os.walk(self.folder_path):
for file_name in files: l.append(os.path.getsize(os.path.join(root, file_name)))
return l
# This code provides a class to unzip file sizes
class UnzipFolder:
def __init__(): # Check selected PATH existance
pass
def extract(self): # Take out specific files
from zipfile import Zipfile
with Zipfile(self.file_path) as zf:
zf.extract(self.zip_name, self.default_path)
return 1
def unpack(self): # Unzpi all files&folders
import os
import shutil
shutil.unpack_archive(os.path.join(self.file_path, self.zip_name), self.default_path)
return 1
UF = UnzipFolder # This is to make things eazier
# Gerneral settings
class Settings:
class general:
pass
class safty:
import warnings, re
def check(self, check=bool('TRUE'), **ListOfPrograms):
import os
current = ListOfPrograms
while check:
# =============
# Tutorial: Using the BugChecker 129-139
# =============
try:
''' # Basically: Call -> verify -> run -> feedback -> output
Let say: Unzip a file from zip
'''
# Then
FileTransfer.__init__("PATH", "path") # Call initialize object
pass
except IndentationError(): #Example error case
pass
finally:
responce = FileTransfer.UF.extract() # Run the command
Settings.safty.log.Problem(current) if responce != 0 else os.exit(1)
current = current()
pass
class ERROR:
pass
class WARNING:
pass
class log:
pass
def Problem():
pass
def Exit():
pass
def NoResponce():
pass
# %%