Skip to content

Commit

Permalink
finish v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
li9633 committed Mar 23, 2024
1 parent a4c4904 commit 31cf8e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
15 changes: 7 additions & 8 deletions CLIprocess.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from fileprocess import generateFile, replaceFile


def generateCLI(compressPath: str, compressFile: str, password=None, compresslevel=None, size: str = None):
def generateCLI(compressPath: str, compressFile: str, password=None, compresslevel=None, size: str = None, mhe=True):
generStr = "7z a "
if password is not None:
generStr += f"-p{password} "
if compresslevel is not None:
generStr += f"-mx{compresslevel} "
if size is not None:
generStr += f"-v{size} "
if True:
if mhe is True:
generStr += f"-mhe=on "
generStr += f"\"{compressPath}.7z\" \"{compressFile}\"\n"
return generStr
Expand Down Expand Up @@ -83,6 +83,7 @@ def processCLIArgs(args: list[str]):
isVaildArg = []
option = {"password": None, "size": None, "mhe": True}
for arg in args:
isVaild = 0
for i in range(0, len(validCLI)):
if arg.find(validCLI[i]) != -1:
if arg[arg.find(validCLI[i]):len(validCLI[i])] == "-p":
Expand All @@ -93,15 +94,13 @@ def processCLIArgs(args: list[str]):
helpMenu(validCLI)
if arg[arg.find(validCLI[i]):len(validCLI[i])] == "-mhe":
option["mhe"] = False
# isVaild -= 1
isVaild -= 1
else:
isVaild += 1
try:
isVaildArg.index(arg)
except ValueError:
isVaildArg.append(arg)
if isVaild == len(validCLI):
isVaildArg.append(arg)

if isVaild == len(validCLI)*len(args):
if len(isVaildArg) != 0:
return ValueError, isVaildArg
else:
return option, None
11 changes: 2 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys
import msvcrt
from fileprocess import *
from CLIprocess import *

Expand All @@ -14,29 +13,23 @@
except ValueError:
None
else:
# print("请按任意键继续...")
# msvcrt.getch()
os._exit(1)

if option is ValueError:
print("传入参数错误!")
print(f"未知的参数->\'{falidArgs}\'")
# print("请按任意键继续...")
# msvcrt.getch()
os._exit(1)

if os.path.exists("path.txt") is not True:
print("(path.txt)目录文件不存在!")
# print("请按任意键继续...")
# msvcrt.getch()
os._exit(1)

compressFile, compressPath = getCompressPath()
runCLI: list = []

for i in range(0, len(compressPath)):
runCLI.append(generateCLI(
compressFile[i], compressPath[i], password=option["password"], size=option["size"]))
compressFile[i], compressPath[i], password=option["password"], size=option["size"], mhe=option["mhe"]))
runCLI.insert(0, "chcp 65001\n")
runCLI.append("pause\n")
runCLI.append("pause")
swtichRunMode(runCLI, method)

0 comments on commit 31cf8e9

Please sign in to comment.