Go to the documentation of this file.00001
00002
00003 import sys, os, time
00004
00005
00006 def untar(path=None):
00007 basename_list = []
00008 if path == None:
00009 path = '.'
00010 list = os.listdir(path)
00011 for i in list:
00012 basename_list.append(FileNames(i, i.split('.')[0]))
00013 for j in basename_list:
00014 command = 'mkdir ' + j.bn + '; cd ' + j.bn + '; tar xvvf ../' + j.fn + '; cd ..'
00015 print command;
00016 os.system(command)
00017
00018 def tar(path=None, keys = []):
00019 pcdlist = []
00020 if path == None:
00021 path = '.'
00022 list = os.listdir(path)
00023 for file in list:
00024 append = True
00025 for k in keys:
00026 if file.find(k) == -1:
00027 append = False
00028 break;
00029 if append == True:
00030 pcdlist.append(file)
00031 objects_list = []
00032 for file in pcdlist:
00033 if file.split('_')[0] not in objects_list:
00034 objects_list.append(file.split('_')[0])
00035 print 'objects_list: ', objects_list, '\n'
00036 tar_str = ''
00037 for obj in objects_list:
00038 for file in pcdlist:
00039 if file.find(obj) != -1:
00040 tar_str += ' ' + file
00041 if 'delimited'in keys and not 'denoised' in keys and not 'rotated' in keys :
00042 command = 'tar cjf ' + obj + '.delimited.pcd.tar.bz2' + tar_str
00043 elif 'delimited' in keys and 'denoised' in keys and not 'rotated' in keys:
00044 command = 'tar cjf ' + obj + '.delimited.denoised.pcd.tar.bz2' + tar_str
00045 elif 'delimited' in keys and 'denoised' in keys and 'rotated' in keys:
00046 command = 'tar cjf ' + obj + '.delimited.denoised.rotated.pcd.tar.bz2' + tar_str
00047 elif 'pcd' in keys:
00048 command = 'tar cjf ' + obj + '.pcd.tar.bz2' + tar_str
00049 elif 'png' in keys:
00050 command = 'tar cjf ' + obj + '.png.tar.bz2' + tar_str
00051 elif 'delimited'in keys and 'rotated' in keys :
00052 command = 'tar cjf ' + obj + '.delimited.rotated.pcd.tar.bz2' + tar_str
00053 else:
00054 print "Unknown arguments!!"
00055 quit(0)
00056 os.system(command)
00057 tar_str = ''
00058 print 'obj: ', obj, 'command: ', command, '\n'
00059
00060 def rename_to_fixed_prec(path=None):
00061 pcdlist = []
00062 if path == None:
00063 path = '.'
00064 list = os.listdir(path)
00065 for file in list:
00066 nr_old = file.split('_')[1]
00067 nr_new = '%04.d' %int(nr_old)
00068 file_renamed=file.replace(nr_old, nr_new)
00069 command = 'mv ' + file + ' ' + file_renamed
00070 print "moving: ", command, "\n"
00071 os.system(command)
00072
00073 def find_missing (key, path=None):
00074 angles = ['-180', '0180', '-150', '0150', '-120', '0120', '-090', '0090', '-060', '0060', '-030', '0030', '0000']
00075 s_a = set(angles)
00076 if path == None:
00077 path = '.'
00078 dir_list = os.listdir(path)
00079 f=open('missing.log', 'a+')
00080 print 'dir list', dir_list
00081 for dir in dir_list:
00082 file_list = os.listdir(dir)
00083 angle_list = []
00084 for file in file_list:
00085 if file.find(key) != -1:
00086
00087 angle_list.append (str(file.split('_')[1]))
00088
00089 if s_a.difference(set(angle_list)).__len__() != 0:
00090
00091
00092 f.write(file.split('_')[0] + ' ')
00093 f.write(str(s_a.difference(set(angle_list))) + '\n')
00094 f.close()
00095
00096 header = """<tr> \n <th>Object</th> \n <th>Img</th> \n <th>PCD-Delimited</th>
00097 <th>PCD-Rotated</th> \n <th>PCD-Full</th> \n <th>Raw</th> \n <th>Img-ROI</th> \n </tr> \n"""
00098
00099 def create_html(prefix, suffix, file, path=None):
00100 f = open(file, 'w')
00101 if path == None:
00102 path = '.'
00103 list = os.listdir(path)
00104 list.sort()
00105 f.write('<table border="1">\n')
00106 f.write(header)
00107 for file in list:
00108 if file[-3:] == suffix:
00109 name = file.split('.')[0]
00110 f.write('<tr>\n')
00111 f.write('\t<td>' + name + '</td>\n')
00112 f.write('\t<td><img src=' + prefix + '/thumbs/' + name + '.png/></td>\n')
00113 f.write('\t<td><a href="' + prefix + '/pcds-delimited/' + name + '.delimited.pcd.tar.bz2">' + 'download</a></td>\n')
00114 f.write('\t<td><a href="' + prefix + '/pcds-rotated/' + name + '.delimited.rotated.pcd.tar.bz2">' + 'download</a></td>\n')
00115 f.write('\t<td><a href="' + prefix + '/pcds-full/' + name + '.pcd.tar.bz2">' + 'download</a></td>\n')
00116 f.write('\t<td><a href="' + prefix + '/raw/' + name + '.tar.bz2">' + 'download</a></td>\n')
00117 f.write('\t<td><a href="' + prefix + '/images-roi/' + name + '.png.tar.bz2">' + 'download</a></td>\n')
00118 f.write('</tr>\n')
00119 f.write('</table>')
00120 f.close
00121
00122 class FileNames:
00123 def __init__(self, fullname, basename):
00124 self.fn = fullname
00125 self.bn = basename
00126
00127
00128 if __name__ == "__main__":
00129 if sys.argv[1] == '0':
00130 untar()
00131 elif sys.argv[1] == 'r':
00132 rename_to_fixed_prec()
00133 elif sys.argv[1] == 'f':
00134 find_missing(sys.argv[2], None)
00135 elif sys.argv[1] == 'html':
00136 create_html(sys.argv[2], sys.argv[3], sys.argv[4])
00137 else:
00138 keys = sys.argv[1:]
00139 tar(None, keys)