westdc-zf1/tools/g6-datafile.py

92 lines
3.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import codecs
#设置相对路径
def homeDir():
path = sys.path[0]
if os.path.isdir(path):
return path
elif os.path.isfile(path):
return os.path.dirname(path)
if __name__=='__main__':
filename = homeDir()+'/datalist.txt'
f = open(filename,'r')
file_uuid=homeDir()+'/uuid_path.txt'
f_uuid= open(file_uuid,'r')
file_dataset=homeDir()+'/dataset.txt'
f_dataset=open(file_dataset,'w')
uuid_list=[] #从uuid-path文件中提取的uuid列表
ftp_list=[] #从uuid-path文件中提取的ftp虚拟目录列表
file_path=[] #与uuid-pathftp虚拟目录对应的物理地址目录列表
ftp_list2=[] #从datalist文件中提取的ftp虚拟目录列表
file_path2=[] #从datalist文件中提取的物理地址列表
##从uuid-path文件中提取uuid和ftp虚拟目录并标准化
for my_line in f_uuid:
my_line=my_line.replace('"','')
my_line=my_line.replace('\n','')
my_line=my_line.split(';')
uuid_list.append(my_line[0])
ftp_str1=my_line[1]+'|'
ftp_str1=ftp_str1.replace('/|','/')
ftp_str1=ftp_str1.replace('|','/')
ftp_list.append(ftp_str1)
##从datalist文件中提取ftp虚拟目录和物理地址并标准化
for line in f:
path= line.split(',')
ftp_str='ftp://ftp.westgis.ac.cn'+path[0]+'|'
ftp_str=ftp_str.replace('/|','/')
ftp_str=ftp_str.replace('|','/')
ftp_list2.append(ftp_str)
file_path2.append(path[1])
#根据uuid-path提供的ftp虚拟目录求序列出对应的物理地址目录
for index in range(len(uuid_list)):
file_temp='a'
ftp_path=ftp_list[index]
for i in range(len(ftp_list2)):
if ftp_path==ftp_list2[i]:
file_temp=file_path2[i]
file_path.append(file_temp)
##输出文件
for k in range(len(uuid_list)):
#输出dataset.txt文件
uuid=uuid_list[k]
f_dataset.write(ftp_list[k].replace('ftp://ftp.westgis.ac.cn','')+'\n')
f_dataset.write(uuid_list[k]+'\n')
path_temp=file_path[k]
path_temp=unicode(path_temp,'utf8')
#输出uuid.txt文件
temp_file=homeDir()+'/data/'+uuid+'.txt'
if os.path.isfile(temp_file):
f_temp=codecs.open(temp_file,'w+','utf-8')
else:
f_temp=codecs.open(temp_file,'w','utf-8')
if path_temp<>'a':
result=os.walk(path_temp)
for root_dir,sub_dir,base_file in result:
root_str=str(sum([os.path.getsize(root_dir+'\\'+filename) for filename in base_file]))+'\t'+root_dir
root_str=root_str.replace(path_temp,ftp_list[k].replace('ftp://ftp.westgis.ac.cn',''))
root_str=root_str.replace('\\','/')
f_temp.write(root_str.replace('//','/')+'\n')
f_temp.write('directory\n')
for base_name in base_file:
file_str=str(os.path.getsize(root_dir+'\\'+base_name))+'\t'+root_dir+'/'+base_name
file_str=file_str.replace(path_temp,ftp_list[k].replace('ftp://ftp.westgis.ac.cn',''))
file_str=file_str.replace('\\','/')
f_temp.write(file_str.replace('//','/')+'\n')
f_temp.write('file\n')
f_temp.close()
f.close()
f_uuid.close()
f_dataset.close()
print '===end====='