Skip to content

Commit a87401c

Browse files
committed
Add mkdir and mkfile
0 parents  commit a87401c

16 files changed

+321
-0
lines changed

LICENSE

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The MIT License (MIT)
2+
Copyright © 2023 JasonMo
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
8+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

readme.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# About
2+
3+
Owl Shell is a shell that you can startto use it very easily. I want to make a good-looking shell and lower the threshold for using the command line.
4+
5+
You can donate me at
6+
7+
# Commands
8+
9+
cd `<path>`
10+
11+
ls </>
12+
13+
# Authors
14+
15+
`JasonMo` `[email protected]`
16+
17+
# Sponsors
18+
19+
# Thanks
20+
21+
`CSDN@1学习者1`
22+
23+
[(21条消息) python 文件读写(追加、覆盖)_python write覆盖_1学习者1的博客-CSDN博客](https://blog.csdn.net/u011280778/article/details/104283319)
24+
25+
`CSDN@allway2`
26+
27+
[(21条消息) Python 列出目录中的文件_python 文件列表_allway2的博客-CSDN博客](https://blog.csdn.net/allway2/article/details/124176562)
28+
29+
`www.runoob.com`
30+
31+
[Python os.path 模块 | 菜鸟教程 (runoob.com)](https://www.runoob.com/python/python-os-path.html)
32+
33+
`CSDN@seven_five577`
34+
35+
[(21条消息) 使用python遍历目录浏览文件属性_seven_five577的博客-CSDN博客](https://blog.csdn.net/seven_five577/article/details/48466127)
36+
37+
`CSDN@老Amy`
38+
39+
[(21条消息) 最详细的解决:UnboundLocalError: local variable ‘a‘ referenced before assignment_unboundlocalerror: local variable &#39;a&#39; referenced b_老Amy的博客-CSDN博客](https://blog.csdn.net/weixin_44352981/article/details/110819292)
40+
41+
`CSDN@Dontla`
42+
43+
[(21条消息) python如何判断一段代码运行是否超出一定时间,如果超出则抛出异常?(检测函数运行是否超时,规定时间内执行,限制时间)eventlet模块 (eventlet.timeout.Timeout)_python 判断运行zai一定时间范围内否则_Dontla的博客-CSDN博客](https://blog.csdn.net/Dontla/article/details/104786085#:~:text=%23%20-%2A-%20encoding%3A%20utf-8%20-%2A-%20%22%22%22%20%40File%20%3A,%E8%B6%85%E6%97%B6%E5%B0%86%E6%8A%9B%E5%87%BA%E5%BC%82%E5%B8%B8%20with%20eventlet.Timeout%282%2C%20True%29%3A%20%23%20%E8%AE%BE%E7%BD%AE%E8%B6%85%E6%97%B6%E6%97%B6%E9%97%B4%E4%B8%BA2%E7%A7%92%20time.sleep%284%29%20print%28%27%E7%A8%8B%E5%BA%8F%E8%BF%90%E8%A1%8C%E6%9C%AA%E8%B6%85%E6%97%B6%EF%BC%81)

setup.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Written by JasonMo on 2023.06.02
2+
# Copyright (c) 2021-2025 JasonMo All Rights Reserved
3+
4+
from setuptools import *
5+
6+
setup(
7+
8+
name="OwlShell",
9+
version="0.0.1",
10+
author="JasonMo",
11+
author_email="[email protected]",
12+
description="A shell written by python",
13+
packages=['owl', 'owl.commands'],
14+
install_requires=['prettytable>=3.7.0'],
15+
tests_require=['prettytable>=3.7.0'],
16+
python_requires='>=3.10',
17+
18+
classifiers = [
19+
# 发展时期,常见的如下
20+
# 3 - Alpha
21+
# 4 - Beta
22+
# 5 - Production/Stable
23+
'Development Status :: 3 - Alpha',
24+
25+
# 开发的目标用户
26+
'Intended Audience :: Developers',
27+
28+
# 许可证信息
29+
'License :: OSI Approved :: MIT License',
30+
31+
# 目标 Python 版本
32+
'Programming Language :: Python :: 3.11',
33+
]
34+
)

src/owl/114514/huhhuhhuhhaaa.py

Whitespace-only changes.

src/owl/__init__.py

Whitespace-only changes.
733 Bytes
Binary file not shown.

src/owl/commands/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

src/owl/commands/commandlist.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Written by JasonMo on 2023.06.02
2+
# Copyright (c) 2021-2025 JasonMo All Rights Reserved
3+
4+
commandlist = {"exit" : "commands.progress_exit.owl_exit(inptcommand)", "cd" : "special command", "ls" : "commands.file_operation.owl_ls(path, inptcommand)", 'mkdir' : 'commands.file_operation.owl_mkdir(path, inptcommand[1])', 'mkfile' : 'commands.file_operation.owl_mkfile(path, inptcommand[1])'}

src/owl/commands/file_operation.py

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# Written by JasonMo on 2023.05.31
2+
# Copyright (c) 2021-2025 JasonMo All Rights Reserved
3+
4+
import os
5+
import sys
6+
import time
7+
import datetime
8+
from prettytable import *
9+
sys.path.append("..")
10+
11+
from owl_errors import *
12+
13+
14+
def owl_cd(oldpath:str, newpath:str):
15+
16+
17+
if os.path.exists(newpath):
18+
return newpath
19+
else:
20+
owl_errors(200)
21+
return oldpath
22+
23+
def owl_ls(path:str, inptcommand:list):
24+
25+
if os.path.exists(path):
26+
if '-dirsize' in inptcommand:
27+
dirsize = True
28+
owl_ls_createtable(path, dirsize)
29+
elif '-h' in inptcommand:
30+
print('\nusage: ls [-h][-dirsize]\n\n[-h]:show help message\n[dirsize]:show the size of the directory')
31+
else:
32+
dirsize = False
33+
owl_ls_createtable(path, dirsize)
34+
35+
36+
else:
37+
owl_errors(201)
38+
39+
def owl_ls_createtable(path:str, dirsize:bool=False):
40+
table = PrettyTable(['#','name','type', 'size', 'modified','created'])
41+
42+
table.align = 'l'
43+
44+
objarg = owl_ls_getobjarg(path, dirsize)
45+
46+
table.add_rows(objarg)
47+
48+
# 用PrettyTable的哪有不疯的? 妈的,忍不了,一拳把地球打爆!
49+
# Every person who use Prettytable are all mad. Damn it!
50+
51+
table.border = True
52+
table.left_junction_char = '├'
53+
table.right_junction_char = '┤'
54+
table.top_left_junction_char = '╭'
55+
table.top_right_junction_char = '╮'
56+
table.bottom_left_junction_char = '╰'
57+
table.bottom_right_junction_char = '╯'
58+
table.top_junction_char = '┬'
59+
table.bottom_junction_char = '┴'
60+
table.junction_char = '┼'
61+
table.horizontal_char = '─'
62+
table.vertical_char = '│'
63+
64+
print('')
65+
print(table)
66+
67+
def owl_ls_getobjarg(path:str, dirsize:bool=False):
68+
listeddir = os.listdir(path)
69+
index = 0
70+
objalllist = []
71+
72+
for filepath in listeddir:
73+
74+
pathname=os.path.join(path,filepath)
75+
76+
state = os.stat(pathname)
77+
78+
objctimes = time.strftime("%Y-%m-%d %X", time.localtime(state[-1]))
79+
objmtimes = time.strftime("%Y-%m-%d %X", time.localtime(state[-2]))
80+
81+
objctime = str(owl_ls_timepassed(objctimes))
82+
objmtime = str(owl_ls_timepassed(objmtimes))
83+
84+
objname = filepath
85+
objsize = ("%d" %state[-4])
86+
87+
if not os.path.isfile(pathname):
88+
objtype = 'dir'
89+
90+
if dirsize == True:
91+
objsize = owl_ls_getdirsize(pathname)
92+
else:
93+
objsize = 'Disabled'
94+
95+
96+
elif os.path.isfile(pathname):
97+
objtype = 'file'
98+
99+
objreslist = [index, objname, objtype, objsize, objmtime, objctime]
100+
101+
objalllist.append(objreslist)
102+
103+
index += 1
104+
105+
return objalllist
106+
107+
def owl_ls_getdirsize(dir:str):
108+
size = 0
109+
for root, dirs, files in os.walk(dir):
110+
size += sum([os.path.getsize(os.path.join(root, name)) for name in files])
111+
return size
112+
113+
def owl_ls_timepassed(time1):
114+
115+
nowtime = datetime.datetime.now()
116+
time2 = datetime.datetime.strptime(time1, "%Y-%m-%d %H:%M:%S")
117+
118+
passedsecs = (nowtime - time2).seconds
119+
passeddays = (nowtime - time2).days
120+
passedmonths = int(passeddays/30)
121+
passedyears = int(passedmonths/12)
122+
passedweeks = int(passeddays/7)
123+
passedmins = int(passedsecs/60)
124+
passedhours = int(passedmins/60)
125+
126+
if passedyears > 0:
127+
passedtime = str(passedyears)+' years ago'
128+
elif passedmonths > 0:
129+
passedtime = str(passedmonths)+' months ago'
130+
elif passedweeks > 0:
131+
passedtime = str(passedweeks)+' weeks ago'
132+
elif passeddays > 0:
133+
passedtime = str(passeddays)+' days ago'
134+
elif passedhours > 0:
135+
passedtime = str(passedhours)+' hours ago'
136+
elif passedmins > 0:
137+
passedtime = str(passedmins)+' minutes ago'
138+
else:
139+
passedtime = 'Just now'
140+
141+
return passedtime
142+
143+
def owl_mkdir(path:str, name:str):
144+
mkpath = path+"\\"+name
145+
os.mkdir(mkpath)
146+
147+
def owl_mkfile(path:str, name:str):
148+
mkpath = mkpath = path+"\\"+name
149+
open(mkpath, 'w')

src/owl/commands/progress_exit.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Written by JasonMo on 2023.05.30
2+
# Copyright (c) 2021-2025 JasonMo All Rights Reserved
3+
4+
# Happy children's Day!🥳
5+
6+
def owl_exit(inptcmd:list, exitcode:int=100):
7+
ipcmlen = inptcmd.__len__()
8+
if ipcmlen >= 2:
9+
exitcode = inptcmd[1]
10+
print("\n \033[33mExiting owl shell with exit code:"+str(exitcode)+"\033[0m\n")
11+
exit(exitcode)
12+
13+
if __name__ == "__main__":
14+
owl_exit(101)

src/owl/owl.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Written by JasonMo on 2023.06.02
2+
# Copyright (c) 2021-2025 JasonMo All Rights Reserved
3+
4+
import sys
5+
import os
6+
import getpass
7+
import socket
8+
9+
from commands.commandlist import *
10+
import commands.progress_exit
11+
import commands.file_operation
12+
from owl_errors import *
13+
14+
class Owlshell_Main(object):
15+
16+
def shellmain(self):
17+
18+
usrname = getpass.getuser()
19+
pcname = socket.gethostname()
20+
path = os.getcwd()
21+
22+
print(" 🦉 Thank you for using Owl shell!")
23+
print(" You can donate me at https://afdian.net/a/jasonmo666\n\n")
24+
25+
while 1:
26+
print("╭──["+pcname+"◍"+usrname+"]")
27+
print('│')
28+
print('│')
29+
30+
consolinput = input("╰──["+path+">")
31+
32+
inptcommand = consolinput.split()
33+
34+
if inptcommand.__len__() < 1:
35+
print("")
36+
37+
else:
38+
39+
if inptcommand[0] in commandlist.keys():
40+
41+
if inptcommand[0] == "cd":
42+
path = commands.file_operation.owl_cd(path, inptcommand[1])
43+
print("")
44+
45+
else:
46+
runcommand = commandlist[inptcommand[0]]
47+
eval(runcommand)
48+
print("")
49+
50+
elif inptcommand[0] not in commandlist.keys():
51+
owl_errors(000)
52+
53+
54+
55+
if __name__ == "__main__":
56+
Owlshell_Main.shellmain(self=None)

src/owl/owl_errors.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Written by JasonMo on 2023.05.30
2+
# Copyright (c) 2021-2025 JasonMo All Rights Reserved
3+
4+
def owl_errors(errnum:int):
5+
if errnum == 000:
6+
print("\n \033[31mOwl shell error 000: Command not exists\033[0m\n")
7+
8+
elif errnum == 200:
9+
print("\n \033[31mOwl shell error 200: Path not exists\033[0m")
10+
11+
elif errnum == 201:
12+
print("\n \033[31mOwl shell error 201: Path not exists\033[0m")
13+

0 commit comments

Comments
 (0)