CCCP-DOS
这是一个在暑假期间就开发的程序
也不晓得有什么用,把它当一个基于cmd的工具就好了(该程序正在尽量摆脱对cmd的依赖)
你可以在这里获取 CCCP-DOS:http://www.cccp-dos.mysxl.cn
好了,不废话了
源码公布:
主要变量:
#i == 获取输入的值
#c == 存储固定的值
#gzlj == 获取当前工作路径
#jue == 存储判断的条件,是否再次判断
#jfj == 决定是否判断该项
所需要的库:
from easygui import *
import os
import shutil
import time
import random
正片开始:
gzlj = os.getcwd() #获取当前工作路径
'--------------------------------cccp--------------------------------'
#以下是个性化设置(可以删掉)
us = gzlj + '\\user.txt'
user = open(us,mode = 'r')
c = user.readlines()
csb = c[0].split(',')[0]
name = c[0].split(',')[0]
color = c[0].split(',')[1]
user.close()
if csb == '#*&^$#@!':
print('您好!')
print('欢迎使用CCCP-DOS!')
print('接下来让我们进行一些基础设置')
name = input('首先请为您自己取一个名字>>> ')
print('很好',name)
while True:
color = input('\n现在,请选择一个颜色主题\n \n1.默认CMD白色\n2.黑客帝国绿色主题\n3.苏维埃红色主题\n4.黄蓝式主题\n5.当前CMD主题\n>>> ')
if color == '1':
os.system('color 7')
color = 'color 7'
break
elif color == '2':
os.system('color 2')
color = 'color 2'
break
elif color == '3':
os.system('color 4')
color = 'color 4'
break
elif color == '4':
os.system('color 16')
color = 'color 16'
break
elif color == '5':
os.system('color ')
color = 'color '
break
else:
print('请输入1~5范围内的有效数字!')
user = open(us,mode = 'w')
wt = name + ',' +color
user.write(wt)
user.close()
cccp_show = print
cccp_show('欢迎',name,'!')
cccp_show(' ')
os.system(color)
显示的信息:
'--------------------------------cccp--------------------------------'
cccp_show('''
_______ _______ _______ _________
/ _____\ / _____\ / _____\ | _______ \\
/ | / | / | | | | |
| | | | | | | |______| |
| | | | | | | |_________/
\ _______ \ _______ \ _______ | |
\_______/ \_______/ \_______/ |_|
''')
cccp_show('CCCP-DOS 版本【1.0.9】\n版权所有<c> 2022 CCCP ZZJ。保留所有权利\n输入''help''查看帮助')
'--------------------------------cccp--------------------------------'
开始判断:(不建议仔细阅读,会疯掉的,因为我基本没写注释)
jue = 'True'
jfj = 'None'
i = 0
def pd():
import time
c = 'CCCP-DOS>'
global jue
global jfj
global i
if jue != 'False':
i = input(c)
if i == 'help' or i == 'help(1)':
cccp_show('''帮助(第1页),共2页:
message 查看关于CCCP-DOS的信息
color 设置颜色,格式:color 数字(0~99之间的数字),注:输入 color 00 会随机抽取颜色
cmd 使用Windows的命令提示符
new 新建一个空白文档,例如:new C:\cccp.txt(在 C:\ 目录下 新建一个 叫做‘cccp’的文档,如果此文档已存在,将会被覆盖)
taskmgr 启动任务管理器
del 删除一个文件或文件夹,正确格式:del 文件路径
calc 启动计算器
help() 获取帮助,输入'help'查看第一页,'help(2)'查看第二页
''')
'--------------------------------cccp--------------------------------'
elif i == 'help(2)':
print('''帮助(第2页),共2页:
now_time 显示当前时间
ren 修改文件名称,格式:ren 文件路径(带后缀名) 新文件名(带后缀名)
md 新建一个文件夹,格式:md 新建的文件夹的路径
gui 启动新建窗口程序
exit 退出CCCP-DOS
cccp_show 显示消息
clear_setup 清除设置
''')
elif i == 'clear_setup':
user = open(us,mode = 'w')
user.write('#*&^$#@!,#####*&^%$#')
user.close()
print('清除成功!重新打开程序生效')
elif i == 'cmd':
try:
try:
cccp_show('进入命令提示符后,请输入‘exit’退出')
os.system('cmd')
except:
cccp_show('进入命令提示符后,请输入‘exit’退出')
os.system('command')
except:
cccp_show('''Can't found file''')
'--------------------------------cccp--------------------------------'
elif i == 'taskmgr':
try:
os.startfile('taskmgr')
os.system('exit')
except:
cccp_show('''Can't found file''')
'--------------------------------cccp--------------------------------'
elif 'new' in i and jfj != 'new':
try:
lie = i.split(' ')
if lie[0] == 'new':
try:
a = i.split(' ')
print(a[1])
f = open(a[1], mode='w+')
try:
c = f.read()
cccp_show('新建成功')
except:
print('‘', a[1], '’', '文件目录不存在')
except:
cccp_show('格式可能错误,\n正确格式:new 文件路径')
jue = 'True'
jfj = 'None'
else:
jfj = 'new'
jue = 'False'
except:
jue = 'False'
jfj = 'new'
'--------------------------------cccp--------------------------------'
elif 'cccp_show' in i and jfj != 'cccp_show':
try:
lie = i.split(' ')
if lie[0] == 'cccp_show':
try:
print(lie[1])
jfj = 'True'
jue = 'None'
except:
print('Error:没有可供输出的内容')
jfj = 'True'
jue = 'None'
else:
jue = 'False'
jfj = 'cccp_show'
except:
jue = 'False'
jfj = 'cccp_show'
elif 'cd' in i and jfj != 'cd':
try:
lie = i.split(' ')
if lie[0] == 'cd':
try:
os.system('cd')
cccp_show('cccp-show-cccp-dos isn')
except:
pass
except:
jue = 'False'
jfj = 'cd'
elif 'del' in i and jfj != 'del':
a = i.split(' ')
if a[0] == 'del':
try:
os.remove(a[1])
print('删除成功!')
except:
try:
os.removedirs(a[1])
print('删除成功!')
except:
try:
shutil.rmtree(a[1])
print('删除成功!')
except:
print('系统找不到',a[1])
jue = 'True'
jfj = 'None'
else:
jue = 'False'
jfj = 'del'
'--------------------------------cccp--------------------------------'
elif i == 'calc':
try:
cccp_show(' ')
os.startfile('calc')
except:
cccp_show('''Can't found file''')
'--------------------------------cccp--------------------------------'
elif i == 'now_time':
print(time.ctime())
'--------------------------------cccp--------------------------------'
elif 'Don’t see it!' in i: #不要看这里,功能被我砍了
try:
a = i.split['.']
if a[-1] != 'bat':
cccp_show('试图执行非bat文件')
else:
a = 0
a = i.split(' ')
b = a[1]
os.system(b)
except:
print(i)
cccp_show('格式错误,正确格式:run_cmd 文件路径(带后缀名)')
'--------------------------------cccp--------------------------------'
elif 'Don’t see it too!' in i: #不要看这里,功能被我砍了
try:
a = i.split('.')
if a[-1] != 'txt':
cccp_show('无法打开')
else:
a = i.split(' ')
cccp_show('execute-cccp-1')
cccp_show('execute-cccp-2')
f = open(a[1],mode = 'r')
cccp_show('execute-cccp-3')
w = f.read()
text = w.split('\n')
try:
#开始执行
i = 0
print('程序开始执行')
while i <= len(text) - 1:
com = text[i]
if i == 0:
if not com == '#cccp-lf#':
cccp_show('无法识别的非LF文件')
break
elif 'cccp_show' in com:
try:
a = com.split(' ')
cccp_show(a[1])
except:
error = i+1
print('error:','第',error,'行出现错误,可能缺少空格')
break
elif 'stop' in com:
try:
a = com.split(' ')
time = a[1]
t = int(time)
time.sleep(int(a[1]))
except:
error = i+1
print('error:','第',error,'行出现错误,可能缺少空格')
break
else:
print('error','第',i+1,'行出现错误,未知的代码')
i = i + 1
cccp_show('程序执行结束')
except:
cccp_show('出现未知错误')
except:
print(i)
cccp_show('格式错误或文件不存在!正确格式:run 文件路径(例如C:\Soviet\c.txt)(带后缀名)')
'--------------------------------cccp--------------------------------'
elif i == 'color 00':
c = random.randint(0,99)
print(c)
co = str(c)
color = 'color ' + co
os.system(color)
elif i == 'cccp':
os.system('tree C:\\')
elif i == 'message':
te = '''关于CCCP-DOS
版本:1.0.9
支持网站:cccp-dos.mysxl.cn
程序编写:张志杰
Logo设计:张叶文
'''
gzlj1 = gzlj + '\logo.gif'
buttonbox(te, image=gzlj1,choices=('确定'))
elif i == 'exit':
exit()
elif i == 'destroy':
pass
elif i == 'calc-dos': #不要看这里,功能被我砍了
cccp_show('无产阶级的计算器--1.0.0')
while True:
cccp_show('输入exit退出\n请选择计算模式\n1--正常计算\n2--特殊计算')
shuru = input('>>>')
if shuru == '1' or shuru == '2':
break
elif 'ren' in i and jfj != 'ren':
try:
lie = i.split(' ')
if lie[0] == 'ren':
try:
os.rename(lie[1],lie[2])
print('修改成功!')
except:
print('错误!文件路径或格式错误!\n格式:ren 文件路径(带后缀名) 新文件名(带后缀名)\n示范:ren C:\cccp.txt soviet.txt')
jue = 'True'
jfj = 'None'
else:
jfj = 'ren'
jue = 'False'
except:
jfj = 'ren'
jue = 'False'
elif 'md' in i and jfj != 'md':
try:
try:
lie = i.split(' ')
def mkdir(path):
folder = os.path.exists(path)
if not folder:
os.makedirs(path)
print('创建成功!')
else:
print('文件夹已存在!')
mkdir(lie[1])
jue = 'True'
jfj = 'None'
except:
print('错误!格式错误!\n格式:md 新建的文件夹的路径')
jfj = 'True'
jue = 'None'
except:
jue = 'False'
jfj = 'md'
elif i == 'gui':
nopen = open(gzlj + '\\data.txt',mode = 'w',encoding = 'UTF-8')
print(' ')
xdi = input('请选择窗口格式:\n1.通知式窗口\n2.选择式窗口\n>>>')
if xdi == '1':
nopen.write('tz\n')
xdi = input('请输入窗口标题:')
nopen.write(xdi + '\n')
xdi = input('请输入窗口内容:')
nopen.write(xdi + '\n')
elif xdi == '2':
nopen.write('ccbox\n')
xdi = input('请输入窗口标题:')
nopen.write(xdi + '\n')
xdi = input('请输入窗口内容:')
nopen.write(xdi + '\n')
xdi = input('请输入第一个选项:')
nopen.write(xdi + '\n')
xdi = input('请输入第二个选项:')
nopen.write(xdi + '\n')
nopen.close()
os.startfile(gzlj + '\\newgui.exe')
else:
try:
if not 'ren' in i:
pass
os.system(i)
jfj = 'True'
jue = 'None'
except:
cccp_show('Error:未知的指令,请输入‘help’查看帮助')
'--------------------------------cccp--------------------------------'
while True:
pd()
cccp_show('--------------------------------cccp--------------------------------')
最后:
我原本是想开发成操作系统的,但想了想,我只会Python,还是算了(悲)