代码拉取完成,页面将自动刷新
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
def colortext(col,str):
if col == 'red':
return '\033[1;31m%s\033[0m'%str
elif col == 'pink':
return '\033[1;35m%s\033[0m'%str
elif col == 'gold':
return '\033[1;33m%s\033[0m'%str
elif col == 'blue':
return '\033[1;34m%s\033[0m'%str
else:
return str
def get_the_file_line(filepath):
fileid=file(filepath,'r')
i=0
while True:
s=fileid.readline()
if len(s) !=0:
i=i+1
else:
break
fileid.close()
return i
def lastnamesame(s,sduibi,n):
if s[len(s)-n:len(s)]==sduibi:
return True
else:
return False
def get_the_last_(s):#abcd_aaaa 返回4
n = 0
tmp = s
while tmp.find('_') != -1:
tmp = tmp[tmp.find('_')+1:]
n = s.find(tmp)-1
return n
def noxg(s):
while s[len(s)-1:len(s)]=='/':
s=s[0:len(s)-1]
return s
def check_root():
pipe=os.popen('/usr/bin/id -u')
a=pipe.read()
pipe.close()
a=a[0:len(a)-1]
if a=='0':
return True
else:
return False
def get_the_dir_path(dirpath):
home = os.environ['HOME']
if dirpath[0:2]=='./':#如果是以./开头的,表示是当前工作目录下的目录
path=os.getcwd()+'/'+dirpath[2:len(dirpath)]
return path
elif dirpath[0:3]=='../':#如果是以../开头的,表示是工作目录上层目录下的目录
path=os.path.dirname(os.getcwd())+dirpath[2:len(dirpath)]
return path
elif dirpath[0:1]=='/':#如果是以/开头的,表示第三个参数即为目录
path=dirpath
return path
elif dirpath[0:1]=='~':
path = dirpath.replace('~','%s'%home)
return path
else:
path=os.getcwd()+'/'+dirpath
return path
def get_the_dir_size(path):
home = os.environ['HOME'] #/home/user
tmp_file_list = '%s/.tmp/tmp_file_list'%(home)
os.system('find %s >%s '%(path,tmp_file_list))
f_line_num = get_the_file_line(tmp_file_list) #获取文件行数
f = file(tmp_file_list,'r')
i = 0
sum = 0
for i in range(0,f_line_num):
line_str = f.readline()[:-1]
if os.path.isfile(line_str):
#print os.path.getsize(line_str)
sum = sum + os.path.getsize(line_str)
#print 'sum=%s'%sum
elif os.path.isdir(line_str):
#print os.path.getsize(line_str)
sum = sum + 4096
f.close()
return sum
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。