为什么80%的码农都做不了架构师?>>>
#编者注 在2010年底左右编写的这个功能的代码,在当时为了满足生产部门的需求,只对镜头列表实施了execl导出,并把系统当中的缩略图导出,但是该代码并为按照TACTIC内部逻辑进行实现。问题1:缩略图的命名规范是手动编写到代码中。问题2:只能获取镜头的缩略图,其他缩略图无法实现。
#CSV代码调用位置与跟踪 ##浏览器访问的Debug 通过Debug信息,我们可以知道浏览器通过rpc的接口,调用了pyasm.widget.CsvDownloadWdg
request_id: 139918269470464 - #0000001
timestamp: 2016-11-14 13:29:31
user: admin
simple method: <function get_widget at 0x21cb050>
ticket: 727bb5e01e791bbc76ae5755919a377a
( 'pyasm.widget.CsvDownloadWdg',{ 'args': { 'column_names': [ 'files','general_checkin','history','description','shot_code'],'filename': 'vfx_leica_project_vfx_leica.csv','include_id': True,'search_keys': [],'search_type': 'vfx/leica?project=vfx','view': 'leica'},'libraries': { 'spt_button': True,'spt_calendar': True,'spt_html5upload': True,'spt_icon_button': True,'spt_popup': True,'spt_tab': True,'spt_table': True,'spt_view_panel': True},'values': { }})
/vfx_leica_project_vfx_leica.csv
SQL Query Count: 13
BVR Count: None
Sending: 0 KB
Num SObjects: 7
Duration: 0.065 seconds (request_id: 139918269470464 - #0000001)
Memory: 50232 KB
Increment: 12420 KB
127.0.0.1 - - [14/Nov/2016:13:29:32] "POST /tactic/default/Api/ HTTP/1.1" 200 222 "localhost/tactic/vfx/link/leica" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
DEPRECATED: dynamic file in app_server.py
127.0.0.1 - - [14/Nov/2016:13:29:32] "GET /tactic/default/WidgetServer/?project=vfx&dynamic_file=true&widget=pyasm.widget.CsvGenerator&filepath=%2Fhome%2Fapache%2Ftactic_temp%2Fupload%2F727bb5e01e791bbc76ae5755919a377a%2Fvfx_leica_project_vfx_leica.csv%0A& HTTP/1.1" 200 120 "localhost/tactic/vfx/link/leica" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
##定位代码 在CsvDownloadWdg中添加自定代码,查找实际执行的命令与参数
def get_display(my):web = _web()column_names = my.column_namescolumn_names = [ x for x in column_names if x ]# create the file pathtmp_dir = _upload_dir()file_path = "%s/%s" % (tmp_dir, my.filename)from pyasmmand import CsvExportCmdcmd = CsvExportCmd(my.search_type, my.view, column_names, file_path)if my.search_keys:cmd.set_search_keys(my.search_keys)cmd.set_include_id(my.include_id)ute()except Exception, e:raiseprint "[file_path]:" + file_pathreturn file_path
Class CsvDownloadWdg Method get_display Debug:[search_type]:vfx/leica?project=vfx
Class CsvDownloadWdg Method get_display Debug:[view]:leica
Class CsvDownloadWdg Method get_display Debug:[column_names]:['files', 'general_checkin', 'history', 'description', 'shot_code']
Class CsvDownloadWdg Method get_display Debug:[file_path]:/home/apache/tactic_temp/upload/727bb5e01e791bbc76ae5755919a377a/vfx_leica_project_vfx_leica.csv
通过分析可以了解,该代码使用CsvExportCmd,添加相关参数,最终执行execute函数,生成csv代码内容,在返回csv路径。 ##执行代码 通过查询CsvExportCmd在pyasmmand.CsvExportCmd路径,可以通过execute代码查看
def execute(my):assert my.search_typeassert my.viewassert my.file_pathsearch = Search(my.search_type)if my.search_ids:search.add_enum_order_by("id", my.search_ids)search.add_filters("id", my.search_ids)sobjects = _sobjects()elif my.search_keys:sobjects = _by_search_keys(my.search_keys, keep_order=True)"""search_codes = [act_code(i) for i in my.search_keys act_code(i) ]if search_codes:search.add_filters("code", search_codes)else:search_ids = [act_id(i) for i in my.search_keys act_id(i) ]search.add_filters("id", search_ids)"""else:sobjects = _sobjects()from pyasm.widget import WidgetConfigViewfrom pyasm.web import Widgetconfig = _by_search_type(my.search_type, my.view)columns = []lumn_names:columns = my.column_names# should allow exporting ids only"""else:if not config:columns = _columns()else:columns = _element_names()"""if my.include_id:columns.insert(0, "id")# create the csv fileorg_file = file(my.file_path, 'w')csvwriter = csv.writer(org_file, quoting=csv.QUOTE_NONNUMERIC)# write the titlescsvwriter.writerow(columns)elements = my.get_elements(config, columns)display_option_dict = {}# this is for widgets that do preprocessing on all sobjectsfor idx, element in enumerate(elements):element.set_sobjects(sobjects)element.preprocess()display_options = _display_options(columns[idx])display_option_dict[element] = display_optionsfor idx, sobject in enumerate(sobjects):values = []for element in elements:element.set_current_index(idx)value = _text_value()if isinstance(value, Widget):value = _buffer_display()elif isinstance(value, basestring):if isinstance(value, unicode):value = de('UTF-8', 'ignore')else:value = str(value)options = display_(element)('csv_force_string')=='true' and value:value= '#FORCESTRING#%s'%valuevalues.append( value )# write the values as listcsvwriter.writerow(values)org_file.close()file2 = open(my.file_path, 'r')mod_file_path = '%s_mod' %my.file_pathmod_file = open(mod_file_path, 'w')for line in file2:mod_line = re.sub(r'('|"|)(#FORCESTRING#)', '=\1', line)mod_file.write(mod_line)# new filefile2.close()mod_file.close()#os.unlink(my.file_ve(mod_file_path, my.file_path)
#xls write
##xlwt插入图片24bit异常 异常报告
24bit
解决方法
snapshot_image = Image.open(snapshot_path).convert('RGB')
bmp = snapshot_image.save('/tmp/temp.bmp')
sheet.insert_bitmap('/tmp/temp.bmp',row=row,col=col)
##image to big
snapshot_path = _path_from_snapshot(snapshot_code, file_type='web', mode='local_repo')
##code
def execute(my,temp_dir):print "Class CsvExportCmd Method execute Debug:run"assert my.search_typeassert my.viewassert my.file_pathprint "Class CsvExportCmd Method execute Debug:[my.search_type]:" + my.search_typeprint "Class CsvExportCmd Method execute Debug:[my.view]:" + my.viewprint "Class CsvExportCmd Method execute Debug:[my.file_path]:" + my.file_pathprint "Class CsvExportCmd Method execute Debug:[my.column_names]:" + lumn_names)print "Class CsvExportCmd Method execute Debug:[my.search_ids]:" + str(my.search_ids)print "Class CsvExportCmd Method execute Debug:[my.search_keys]:" + str(my.search_keys)print "Class CsvExportCmd Method execute Debug: by search_type,search_ids,search_keys get sobjects"search = Search(my.search_type)if my.search_ids:search.add_enum_order_by("id", my.search_ids)search.add_filters("id", my.search_ids)sobjects = _sobjects()elif my.search_keys:print 'elif my.search_keys'sobjects = _by_search_keys(my.search_keys, keep_order=True)"""search_codes = [act_code(i) for i in my.search_keys act_code(i) ]if search_codes:search.add_filters("code", search_codes)else:search_ids = [act_id(i) for i in my.search_keys act_id(i) ]search.add_filters("id", search_ids)"""else:sobjects = _sobjects()print "Class CsvExportCmd Method execute Debug:[sobjects]:" + str(sobjects)from pyasm.widget import WidgetConfigViewfrom pyasm.web import Widgetconfig = _by_search_type(my.search_type, my.view)print "Class CsvExportCmd Method execute Debug:[config]:" + str(config)columns = []lumn_names:columns = my.column_names# should allow exporting ids only"""else:if not config:columns = _columns()else:columns = _element_names()"""if my.include_id:columns.insert(0, "id")# create the csv file# org_file = file(my.file_path, 'w')# csvwriter = csv.writer(org_file, quoting=csv.QUOTE_NONNUMERIC)# by hava# xls pathxls_path = my.place('.csv','.xls')print "Class CsvExportCmd Method execute Debug:[xls_path]:" + xls_pathwbk = xlwt.Workbook()sheet = wbk.add_sheet(my.view, cell_overwrite_ok=True)# save the preview column in the datapreview_col = -1# write the titles to the xlsfor col,title in enumerate(columns):if title == 'preview':preview_col = colsheet.write(0,col,title)print "[title]:" + title + " [col]:" + str(col)# old code get the columns configelements = my.get_elements(config, columns)display_option_dict = {}# this is for widgets that do preprocessing on all sobjectsfor idx, element in enumerate(elements):element.set_sobjects(sobjects)element.preprocess()display_options = _display_options(columns[idx])display_option_dict[element] = display_optionsrow = 1for idx,sobject in enumerate(sobjects):print "[idx]:" + str(idx)values = []for element in elements:element.set_current_index(idx)value = _text_value()if isinstance(value, Widget):value = _buffer_display()elif isinstance(value, basestring):if isinstance(value, unicode):value = de('UTF-8', 'ignore')else:value = str(value)options = display_(element)('csv_force_string') == 'true' and value:value = '#FORCESTRING#%s' % valuevalues.append(value)row = idx + 1# write the context to the xlsfor col,item in enumerate(values):sheet.write(row,col,item.decode('utf-8','ignore'))# write the icon to the xlsif preview_col != -1:# 1.get the icon pathfrom tactic_client_lib import TacticServerStubserver = TacticServerStub()if len(my.search_keys) == 0:continuesearch_key = my.search_keys[idx]print "[search_key]:" + search_keysnapshot = _snapshot(search_key, context='icon', version=-1)snapshot_code = ("code")# fixed:some demo project export xls not imageif snapshot_code is None:snapshot = _snapshot(search_key, context='publish', version=-1)snapshot_code = ('code')# endsnapshot_path = _path_from_snapshot(snapshot_code, file_type='web', mode='local_repo')print "[snapshot_path]:" + snapshot_pathfor col,item in enumerate(values):if col == preview_col:try:snapshot_image = Image.open(snapshot_path).convert('RGB')bmp = snapshot_image.save(temp_dir + '/temp.bmp')sheet.insert_bitmap(temp_dir + '/temp.bmp',row=row,col=col)except Exception,ex:print "[Exception]:" + str(ex)finally:ve(temp_dir + '/temp.bmp')except Exception,ex:print "[Exception]:" + str(ex)wbk.save(xls_path)return xls_path
# end hava
change the xls
def get_display(my):web = _web()column_names = my.column_namescolumn_names = [ x for x in column_names if x ]# create the file pathtmp_dir = _upload_dir()file_path = "%s/%s" % (tmp_dir, my.filename)from pyasmmand import CsvExportCmdprint "Class CsvDownloadWdg Method get_display Debug:[search_type]:" + my.search_typeprint "Class CsvDownloadWdg Method get_display Debug:[view]:" + my.viewprint "Class CsvDownloadWdg Method get_display Debug:[column_names]:" + str(column_names)print "Class CsvDownloadWdg Method get_display Debug:[file_path]:" + file_pathcmd = CsvExportCmd(my.search_type, my.view, column_names, file_path)if my.search_keys:print "Class CsvDownloadWdg Method get_display Debug:[search_keys]:" + str(my.search_keys)cmd.set_search_keys(my.search_keys)print "Class CsvDownloadWdg Method get_display Debug:[include_id]:" + str(my.include_id)cmd.set_include_id(my.include_id)try:# ute()xls_path = ute(tmp_dir)print "[xls_path]:" + xls_pathreturn xls_pathexcept Exception, e:raiseprint "[file_path]:" + file_pathreturn file_path
转载于:
本文发布于:2024-01-29 09:09:12,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170649055914216.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |