def _process_video(my, file_name): if not HAS_FFMPEG: return thumb_web_size = my.get_web_file_size() thumb_icon_size = (120, 100) exts = File.get_extensions(file_name) base, ext = os.path.splitext(file_name) icon_file_name = "%s_icon.png" % base web_file_name = "%s_web.jpg" % base tmp_icon_path = "%s/%s" % (my.tmp_dir, icon_file_name) tmp_web_path = "%s/%s" % (my.tmp_dir, web_file_name) #cmd = '''"%s" -i "%s" -r 1 -ss 00:00:01 -t 1 -s %sx%s -vframes 1 "%s"''' % (ffmpeg, my.file_path, thumb_web_size[0], thumb_web_size[1], tmp_web_path) #os.system(cmd) import subprocess try: subprocess.call([ffmpeg_exe, '-i', my.file_path, "-y", "-ss", "00:00:00","-t","1",\ "-s","%sx%s"%(thumb_web_size[0], thumb_web_size[1]),"-vframes","1","-f","image2", tmp_web_path]) if os.path.exists(tmp_web_path): my.web_path = tmp_web_path else: my.web_path = None except Exception, e: Environment.add_warning("Could not process file", \ "%s - %s" % (my.file_path, e.__str__())) pass
def get_columns(my, required_only=False): if my.search_type == 'sthpw/virtual': return [] search_type_obj = SearchType.get(my.search_type) table = search_type_obj.get_table() from pyasm.biz import Project db_resource = Project.get_db_resource_by_search_type(my.search_type) database_name = db_resource.get_database() db = DbContainer.get(db_resource) # table may not exist try: all_columns = db.get_columns(table) columns = [] if required_only: nullables = db.get_column_nullables(table) for column in all_columns: null_ok = nullables.get(column) if not null_ok: columns.append(column) # if there are no required columns if not columns: columns = all_columns else: columns = all_columns except SqlException: Environment.add_warning('missing table', 'Table [%s] does not exist in database [%s]' %(table, database_name)) return [] return columns
def get_display(my): widget = Widget() if not my.select: return widget if not my.schema: Environment.add_warning("No schema defined") widget.add("No schema defined") return widget if not my.search_type: Environment.add_warning("HierarchicalFilterWdg: Cannot find current search_type") widget.add("Cannot find current search_type") return widget span = SpanWdg(css="med") parent_type = my.get_parent_type() if parent_type: parent_type_obj = SearchType.get(parent_type) span.add("%s: " % parent_type_obj.get_value("title")) # assume that there is a code in the parent my.select.add_empty_option("-- Select --") my.select.set_option("query", "%s|code|code" % my.parent_type) span.add(my.select) widget.add(span) return widget
def get_display(self): widget = Widget() if not self.select: return widget if not self.schema: Environment.add_warning("No schema defined") widget.add("No schema defined") return widget if not self.search_type: Environment.add_warning("HierarchicalFilterWdg: Cannot find current search_type") widget.add("Cannot find current search_type") return widget span = SpanWdg(css="med") parent_type = self.get_parent_type() if parent_type: parent_type_obj = SearchType.get(parent_type) span.add("%s: " % parent_type_obj.get_value("title")) # assume that there is a code in the parent self.select.add_empty_option("-- Select --") self.select.set_option("query", "%s|code|code" % self.parent_type) span.add(self.select) widget.add(span) return widget
def get_file_info(xml, file_objects, sobject, snapshot, show_versionless=False, is_list=False): info = {} #TODO: {'file_type': [file_type]: [path], 'base_type': [base_type]: [file|directory|sequence]} if is_list: info = [] else: repo_info = {} info['_repo'] = repo_info nodes = xml.get_nodes("snapshot/file") for node in nodes: type = Xml.get_attribute(node, "type") file_code = Xml.get_attribute(node, "file_code") file_object = file_objects.get(file_code) if not file_object: if isinstance(info, dict): info[type] = ThumbWdg.get_no_image() else: info.append((type, ThumbWdg.get_no_image())) Environment.add_warning( "No file object", "No file object found for file code '%s'" % file_code) continue file_name = file_object.get_full_file_name() web_dir = sobject.get_web_dir(snapshot, file_object=file_object) # handle a range if it exists file_range = file_object.get_value("file_range") if file_range: from pyasm.biz import FileGroup, FileRange file_range = FileRange.get(file_range) file_names = FileGroup.expand_paths(file_name, file_range) # just check the first frame if file_names: file_name = file_names[0] path = "%s/%s" % (web_dir, file_name) if isinstance(info, dict): info[type] = path lib_dir = sobject.get_lib_dir(snapshot, file_object=file_object) repo_info[type] = "%s/%s" % (lib_dir, file_name) else: info.append((type, path)) return info
def get_by_code(cls, code, allow_default=False): '''it is fatal not to have a pipeline, so put a default''' if not code: return None # first look at project specific pipeline pipeline = Search.get_by_code("config/pipeline", code) if not pipeline: pipeline = super(Pipeline,cls).get_by_code(code) if not pipeline and code == 'task': # Create a default task pipeline pipeline = SearchType.create("sthpw/pipeline") pipeline.set_value("code", "task") from pyasm.biz import Task xml = Task.get_default_task_xml() pipeline.set_value("pipeline", xml) pipeline.set_pipeline(xml) pipeline.set_value("search_type", "sthpw/task") #pipeline.commit() if not pipeline and allow_default: search = Search(cls) search.add_filter('code', 'default') pipeline = search.get_sobject() if not pipeline: pipeline = cls.create('default', \ 'default pipeline', '') xml = pipeline.get_xml_value("pipeline") # create a default process for the table root = xml.get_root_node() element = xml.create_element("process") Xml.set_attribute(element,"name", "default_process") Xml.append_child(root, element) pipeline.set_value('pipeline', xml.get_xml()) pipeline.commit() # set the pipeline pipeline.set_pipeline(pipeline.get_value('pipeline')) Environment.add_warning("pipeline autogenerated", \ "[default] pipeline has just been created.") # Sometimes, a pipeline is instantiated without calling set_pipeline() # to be looked into if pipeline and not pipeline.get_processes(): pipeline.set_pipeline(pipeline.get_value('pipeline')) return pipeline
def get_by_code(cls, code, allow_default=False): '''it is fatal not to have a pipeline, so put a default''' if not code: return None # first look at project specific pipeline pipeline = Search.get_by_code("config/pipeline", code) if not pipeline: pipeline = super(Pipeline, cls).get_by_code(code) if not pipeline and code == 'task': # Create a default task pipeline pipeline = SearchType.create("sthpw/pipeline") pipeline.set_value("code", "task") from pyasm.biz import Task xml = Task.get_default_task_xml() pipeline.set_value("pipeline", xml) pipeline.set_pipeline(xml) pipeline.set_value("search_type", "sthpw/task") #pipeline.commit() if not pipeline and allow_default: search = Search(cls) search.add_filter('code', 'default') pipeline = search.get_sobject() if not pipeline: pipeline = cls.create('default', \ 'default pipeline', '') xml = pipeline.get_xml_value("pipeline") # create a default process for the table root = xml.get_root_node() element = xml.create_element("process") Xml.set_attribute(element, "name", "default_process") Xml.append_child(root, element) pipeline.set_value('pipeline', xml.get_xml()) pipeline.commit() # set the pipeline pipeline.set_pipeline(pipeline.get_value('pipeline')) Environment.add_warning("pipeline autogenerated", \ "[default] pipeline has just been created.") # Sometimes, a pipeline is instantiated without calling set_pipeline() # to be looked into if pipeline and not pipeline.get_processes(): pipeline.set_pipeline(pipeline.get_value('pipeline')) return pipeline
def get_file_info(xml, file_objects, sobject, snapshot, show_versionless=False, is_list=False, protocol='http'): info = {} #TODO: {'file_type': [file_type]: [path], 'base_type': [base_type]: [file|directory|sequence]} if is_list: info = [] else: repo_info = {} info['_repo'] = repo_info nodes = xml.get_nodes("snapshot/file") for node in nodes: type = Xml.get_attribute(node, "type") file_code = Xml.get_attribute(node, "file_code") file_object = file_objects.get(file_code) if not file_object: if isinstance(info, dict): info[type] = ThumbWdg.get_no_image() else: info.append((type, ThumbWdg.get_no_image())) Environment.add_warning("No file object", "No file object found for file code '%s'" % file_code) continue file_name = file_object.get_full_file_name() web_dir = sobject.get_web_dir(snapshot, file_object=file_object) # handle a range if it exists file_range = file_object.get_value("file_range") if file_range: from pyasm.biz import FileGroup, FileRange file_range = FileRange.get(file_range) file_names = FileGroup.expand_paths(file_name, file_range) # just check the first frame if file_names: file_name = file_names[0] path = "%s/%s" % (web_dir, file_name) if protocol != "file": path = urllib.pathname2url(path) if isinstance(info, dict): info[type] = path lib_dir = sobject.get_lib_dir(snapshot, file_object=file_object) repo_info[type] = "%s/%s" % (lib_dir, file_name) else: info.append((type, path)) return info
def get_to(my): # add the assigned user to the list of users sent. recipients = super(TaskAssignEmailHandler, my).get_to() task = my.sobject assigned = task.get_value("assigned") login = Login.get_by_login(assigned) if not login: Environment.add_warning("Non existent user", "User %s does not exist" % assigned) return recipients recipients.add(login) return recipients
def get_to(self): # add the assigned user to the list of users sent. recipients = super(TaskAssignEmailHandler, self).get_to() task = self.sobject assigned = task.get_value("assigned") login = Login.get_by_login(assigned) if not login: Environment.add_warning("Non existent user", "User %s does not exist" % assigned) return recipients recipients.add(login) return recipients
def create(src_sobject, dst_sobject, context="reference", direction="both"): project_code = Project.get_project_code() if not context: context = "reference" # ensure that the connection doesn't already exist search = Search("sthpw/connection") search.add_sobject_filter(src_sobject, prefix="src_") search.add_sobject_filter(dst_sobject, prefix="dst_") if search.get_count(): Environment.add_warning( "Already connected", "%s is already connected to %s" % (src_sobject.get_code(), dst_sobject.get_code())) return connection = SearchType.create("sthpw/connection") connection.set_value("src_search_type", src_sobject.get_search_type()) connection.set_value("dst_search_type", dst_sobject.get_search_type()) connection.set_value("src_search_id", src_sobject.get_id()) connection.set_value("dst_search_id", dst_sobject.get_id()) connection.set_value("context", context) connection.set_value("project_code", project_code) connection.commit() if direction == "both": connection = SearchType.create("sthpw/connection") connection.set_value("src_search_type", dst_sobject.get_search_type()) connection.set_value("dst_search_type", src_sobject.get_search_type()) connection.set_value("src_search_id", dst_sobject.get_id()) connection.set_value("dst_search_id", src_sobject.get_id()) connection.set_value("context", context) connection.set_value("project_code", project_code) connection.commit() return connection
def execute(my): # check file name file_name = os.path.basename(my.file_path) ext = File.get_extension(file_name) type = string.lower(ext) if type == "pdf": my._process_pdf(file_name) elif type in File.NORMAL_EXT: # skip icon generation for normal or video files pass elif type in File.VIDEO_EXT: try: my._process_video(file_name) except IOError, e: '''This is an unknown file type. Do nothing and except as a file''' print "WARNING: ", e.__str__() Environment.add_warning("Unknown file type", e.__str__())
def execute(self): # check file name file_name = os.path.basename(self.file_path) ext = File.get_extension(file_name) type = string.lower(ext) if type == "pdf": self._process_pdf( file_name ) elif type != "psd" and type in File.NORMAL_EXT: # skip icon generation for normal or video files pass elif type in File.VIDEO_EXT: try: self._process_video( file_name ) except IOError, e: '''This is an unknown file type. Do nothing and except as a file''' print("WARNING: ", e.__str__()) Environment.add_warning("Unknown file type", e.__str__())
def get_display(my): sobject = my.get_current_sobject() try: import qb except ImportError: Environment.add_warning("Qube not installed", "Qube not installed") return "---" dispatcher_id = sobject.get_value("dispatcher_id") all_jobinfo = qb.jobinfo(filters={'id': dispatcher_id}) if not all_jobinfo: return "---" job_info = all_jobinfo[0] status = job_info.get('status') timestart = job_info.get('timestart') timecomplete = job_info.get('timecomplete') timeelapsed = int(timecomplete) - int(timestart) return "%s (%ss)" % (status, timeelapsed)
def create(src_sobject, dst_sobject, context="reference", direction="both"): project_code = Project.get_project_code() if not context: context = "reference" # ensure that the connection doesn't already exist search = Search("sthpw/connection") search.add_sobject_filter(src_sobject, prefix="src_") search.add_sobject_filter(dst_sobject, prefix="dst_") if search.get_count(): Environment.add_warning("Already connected", "%s is already connected to %s" % (src_sobject.get_code(), dst_sobject.get_code() ) ) return connection = SearchType.create("sthpw/connection") connection.set_value("src_search_type", src_sobject.get_search_type() ) connection.set_value("dst_search_type", dst_sobject.get_search_type() ) connection.set_value("src_search_id", src_sobject.get_id() ) connection.set_value("dst_search_id", dst_sobject.get_id() ) connection.set_value("context", context) connection.set_value("project_code", project_code) connection.commit() if direction == "both": connection = SearchType.create("sthpw/connection") connection.set_value("src_search_type", dst_sobject.get_search_type() ) connection.set_value("dst_search_type", src_sobject.get_search_type() ) connection.set_value("src_search_id", dst_sobject.get_id() ) connection.set_value("dst_search_id", src_sobject.get_id() ) connection.set_value("context", context) connection.set_value("project_code", project_code) connection.commit() return connection
def get_source_link(my, node): search_type = Xml.get_attribute(node, "search_type") search_id = Xml.get_attribute(node, "search_id") context = Xml.get_attribute(node, "context") version = Xml.get_attribute(node, "version") source_snapshot = Snapshot.get_by_version(search_type, search_id, \ context, version ) if not source_snapshot: Environment.add_warning("Snapshot not found", "Reference snapshot for [%s|%s] does not exist" \ % (search_type, search_id) ) return '' #raise WidgetException( "Reference snapshot in '%s' does not exist" \ # % snapshot.get_id() ) source = source_snapshot.get_sobject() # get the file link file_name = source_snapshot.get_name_by_type("main") path = "%s/%s" % (source_snapshot.get_web_dir(), file_name) return HtmlElement.href("Source: %s" %source.get_value("code"), \ ref=path )
def get_columns(self, required_only=False): if self.search_type == 'sthpw/virtual': return [] search_type_obj = SearchType.get(self.search_type) table = search_type_obj.get_table() from pyasm.biz import Project db_resource = Project.get_db_resource_by_search_type(self.search_type) database_name = db_resource.get_database() db = DbContainer.get(db_resource) # table may not exist try: all_columns = db.get_columns(table) columns = [] if required_only: nullables = db.get_column_nullables(table) for column in all_columns: null_ok = nullables.get(column) if not null_ok: columns.append(column) # if there are no required columns if not columns: columns = all_columns else: columns = all_columns except SqlException: Environment.add_warning( 'missing table', 'Table [%s] does not exist in database [%s]' % (table, database_name)) return [] return columns
def get_source_link(self, node): search_type = Xml.get_attribute(node, "search_type") search_id = Xml.get_attribute(node, "search_id") context = Xml.get_attribute(node, "context") version = Xml.get_attribute(node, "version") source_snapshot = Snapshot.get_by_version(search_type, search_id, \ context, version ) if not source_snapshot: Environment.add_warning("Snapshot not found", "Reference snapshot for [%s|%s] does not exist" \ % (search_type, search_id) ) return '' #raise WidgetException( "Reference snapshot in '%s' does not exist" \ # % snapshot.get_id() ) source = source_snapshot.get_sobject() # get the file link file_name = source_snapshot.get_name_by_type("main") path = "%s/%s" % (source_snapshot.get_web_dir(), file_name) return HtmlElement.href("Source: %s" %source.get_value("code"), \ ref=path )
def _process_image(my, file_name): base, ext = os.path.splitext(file_name) # get all of the extensions exts = File.get_extensions(file_name) frame = 0 if len(exts) == 2: try: frame = int(exts[0]) base = base.replace(".%s" % exts[0], '' ) except ValueError: frame = 0 if frame: icon_file_name = "%s_icon.%s.png" % (base, exts[0]) web_file_name = "%s_web.%s.jpg" % (base, exts[0]) else: icon_file_name = "%s_icon.png" % base web_file_name = "%s_web.jpg" % base tmp_icon_path = "%s/%s" % (my.tmp_dir, icon_file_name) tmp_web_path = "%s/%s" % (my.tmp_dir, web_file_name) # create the web image try: if my.texture_mode: my._resize_texture(my.file_path, tmp_web_path, 0.5) my.web_path = tmp_web_path # create the icon thumb_size = (120,100) my._resize_image(tmp_web_path, tmp_icon_path, thumb_size) my.icon_path = tmp_icon_path elif my.icon_mode: # just icon, no web # create the icon only thumb_size = (120,100) my._resize_image(my.file_path, tmp_icon_path, thumb_size) my.icon_path = tmp_icon_path else: from pyasm.prod.biz import ProdSetting web_file_size = ProdSetting.get_value_by_key('web_file_size') thumb_size = (640, 480) if web_file_size: parts = re.split('[\Wx]+', web_file_size) thumb_size = (640, 480) if len(parts) == 2: try: thumb_size = (int(parts[0]), int(parts[1])) except ValueError: thumb_size = (640, 480) my._resize_image(my.file_path, tmp_web_path, thumb_size) my.web_path = tmp_web_path # create the icon thumb_size = (120,100) my._resize_image(tmp_web_path, tmp_icon_path, thumb_size) my.icon_path = tmp_icon_path # check icon file size, reset to none if it is empty # TODO: use finally in Python 2.5 if my.web_path: web_path_size = os.stat(my.web_path)[stat.ST_SIZE] if not web_path_size: my.web_path = None if my.icon_path: icon_path_size = os.stat(my.icon_path)[stat.ST_SIZE] if not icon_path_size: my.icon_path = None except IOError, e: Environment.add_warning("Could not process file", \ "%s - %s" % (my.file_path, e.__str__())) my.web_path = None my.icon_path = None
def update_dependent_tasks(my, top=True): '''for purposes of dependent tasks''' if top: Task.tasks_updated = [] Task.tasks_updated.append(my.get_id()) # get the dependent tasks tasks = my.get_dependent_tasks() bid_start_date = my.get_value("bid_start_date") bid_end_date = my.get_value("bid_end_date") bid_duration_unit = ProdSetting.get_value_by_key("bid_duration_unit") if not bid_duration_unit: bid_duration_unit = 'hour' # if there is no end date specified, return if not bid_end_date: bid_duration = my.get_value("bid_duration") if bid_duration and bid_start_date: date = Date(db=bid_start_date) bid_duration = float(bid_duration) if bid_duration_unit == 'minute': date.add_minutes(bid_duration) else: date.add_hours(bid_duration) bid_end_date = date.get_db_time() else: return for task in tasks: # prevent circular dependency if for some reason they occur. if task.get_id() in Task.tasks_updated: Environment.add_warning("Circular dependency", "Circular dependency with task '%s'" % task.get_id() ) continue Task.tasks_updated.append(my.get_id()) # if the dependency is fixed, update the d #mode = task.get_value("mode") mode = "depend" # put the start date as the end date if mode == "depend": # add one day to the end date to get the start date date = Date(db=bid_end_date) date.add_days(1) bid_start_date = date.get_db_time() task.set_value("bid_start_date", bid_start_date ) # check if there is a duration in hours to this date bid_duration = task.get_value("bid_duration") if bid_duration: bid_duration = int(bid_duration) date = Date(db=bid_start_date) if bid_duration_unit == 'minute': date.add_minutes(bid_duration) else: date.add_hours(bid_duration) bid_end_date = date.get_db_time() task.set_value("bid_end_date", bid_end_date) task.commit() task.update_dependent_tasks(False)
def _process_image(my, file_name): base, ext = os.path.splitext(file_name) # get all of the extensions exts = File.get_extensions(file_name) frame = 0 if len(exts) == 2: try: frame = int(exts[0]) base = base.replace(".%s" % exts[0], '') except ValueError: frame = 0 if frame: icon_file_name = "%s_icon.%s.png" % (base, exts[0]) web_file_name = "%s_web.%s.jpg" % (base, exts[0]) else: icon_file_name = "%s_icon.png" % base web_file_name = "%s_web.jpg" % base tmp_icon_path = "%s/%s" % (my.tmp_dir, icon_file_name) tmp_web_path = "%s/%s" % (my.tmp_dir, web_file_name) # create the web image try: if my.texture_mode: my._resize_texture(my.file_path, tmp_web_path, 0.5) my.web_path = tmp_web_path # create the icon thumb_size = (120, 100) try: my._resize_image(tmp_web_path, tmp_icon_path, thumb_size) except TacticException: my.icon_path = None else: my.icon_path = tmp_icon_path elif my.icon_mode: # just icon, no web # create the icon only thumb_size = (120, 100) try: my._resize_image(my.file_path, tmp_icon_path, thumb_size) except TacticException: my.icon_path = None else: my.icon_path = tmp_icon_path else: thumb_size = my.get_web_file_size() try: my._resize_image(my.file_path, tmp_web_path, thumb_size) except TacticException: my.web_path = None else: my.web_path = tmp_web_path # create the icon thumb_size = (120, 100) try: my._resize_image(tmp_web_path, tmp_icon_path, thumb_size) except TacticException: my.icon_path = None else: my.icon_path = tmp_icon_path # check icon file size, reset to none if it is empty # TODO: use finally in Python 2.5 if my.web_path: web_path_size = os.stat(my.web_path)[stat.ST_SIZE] if not web_path_size: my.web_path = None if my.icon_path: icon_path_size = os.stat(my.icon_path)[stat.ST_SIZE] if not icon_path_size: my.icon_path = None except IOError, e: Environment.add_warning("Could not process file", \ "%s - %s" % (my.file_path, e.__str__())) my.web_path = None my.icon_path = None
def get_schema_wdg(self, schema): web = WebContainer.get_web() div = DivWdg() div.add_style("margin: 10 0 10 0") if not schema: Environment.add_warning("No schema", "No schema found") return div schema_xml = schema.get_xml_value("schema") code = schema.get_code() schema_search_types = schema_xml.get_values("schema/search_type/@name") if not schema_search_types: return title = DivWdg() view_margin_top = '4px' title.add_styles( "margin-top: %s; margin-bottom: 3px; vertical-align: middle" % view_margin_top ) if not web.is_IE(): title.add_styles( "margin-left: -10px; margin-right: -10px;" ) title.add_looks( "navmenu_header" ) title_label = SpanWdg() title_label.add_styles( "margin-left: 6px; padding-bottom: 2px;" ) title_label.add_looks( "fnt_title_5 fnt_bold" ) title_label.add("%s Schema" % code.capitalize()) title.add(title_label) #title.add_style("margin-top: 7px") #title.add_style("font-weight: bold") #title.add_style("font-size: 1.1em") #title.add_style("color: black") #underline = HtmlElement.hr() #underline.add_style("color: black") #underline.add_style("size: 1px") #underline.add_style("margin-top: -3px") #title.add(underline) div.add( title ) for schema_search_type in schema_search_types: try: search_type_obj = SearchType.get(schema_search_type) except SearchException: title = "<span style='color: #F44'>? %s</span>" % schema_search_type else: title = search_type_obj.get_title() span = DivWdg() span.add_style("padding: 1px") options = { 'search_type': schema_search_type, 'view': 'table', 'schema_default_view': 'true', } link = self.get_link_wdg("schema", "main_body", title, options) # walk up the tree current_type = schema_search_type has_parent = False while 1: parent_type = schema.get_parent_type(current_type) if parent_type and parent_type != '*': span.add(" ") has_parent = True else: if has_parent: span.add("+ ") break current_type = parent_type span.add(link) div.add(span) return div
def _process_video(self, file_name): if not HAS_FFMPEG: return thumb_web_size = self.get_web_file_size() thumb_icon_size = (120, 100) exts = File.get_extensions(file_name) base, ext = os.path.splitext(file_name) icon_file_name = "%s_icon.png" % base web_file_name = "%s_web.jpg" % base tmp_icon_path = "%s/%s" % (self.tmp_dir, icon_file_name) tmp_web_path = "%s/%s" % (self.tmp_dir, web_file_name) #cmd = '''"%s" -i "%s" -r 1 -ss 00:00:01 -t 1 -s %sx%s -vframes 1 "%s"''' % (ffmpeg, self.file_path, thumb_web_size[0], thumb_web_size[1], tmp_web_path) #os.system(cmd) import subprocess try: # Attempt to resize only if necessary. Requires ffprobe call. # (More recent version of ffmpeg support the argument # -vf scale="'if(gt(iw, 640), 640, iw)':'if(gt(ih, 6400), 6400, -1)'" # allowing for scaling which preserves aspect ratio and only scales # when necessary. For now, it is necessary to query video size.) free_aspect_ratio = thumb_web_size[1] == -1 try: command = ["ffprobe", "-print_format", "json", "-select_streams", "v:0", "-show_entries", "stream=height,width", self.file_path] p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() data = jsonloads(out) streams = data.get("streams") or [] sample_stream = streams[0] width = int(sample_stream.get("width")) height = int(sample_stream.get("height")) max_width = thumb_web_size[0] max_height = max_width*10 if free_aspect_ratio else thumb_web_size[1] if width < max_width and height < max_height: # Resizing is not necessary size_option = "" size = "" elif not free_aspect_ratio and (width > max_width or height > max_height): size_option = "-s" size = "%sx%s" % (thumb_web_size[0], thumb_web_size[1]) else: if width > height: size_option = "-vf" size = "scale=%s:-1" % thumb_web_size[0] elif height > width: aspect_ratio = float(float(height)/(width)) if aspect_ratio >= 10: size_option = "-vf" size = "scale=-1:%s" % max_height else: new_height = max_height new_width = float(new_height)/height if new_width > max_width: new_width = max_width new_height = height*float(new_width)/width size_option = "-vf" size = "scale=%s:-1" % max_width else: size_option = "-vf" size = "scale=-1:%s" % max_height except Exception as e: if free_aspect_ratio: size_option = "-vf" size = "scale=%s:-1" % thumb_web_size[0] else: size_option = "-s" size = "%sx%s" % (thumb_web_size[0], thumb_web_size[1]) command = [ffmpeg_exe, '-i', self.file_path, "-y", "-ss", "00:00:00","-t","1"] if size_option and size: command.extend([size_option, size]) command.extend(["-vframes","1","-f","image2", tmp_web_path]) subprocess.call(command) if os.path.exists(tmp_web_path): self.web_path = tmp_web_path else: self.web_path = None except Exception as e: Environment.add_warning("Could not process file", \ "%s - %s" % (self.file_path, e.__str__())) pass try: subprocess.call([ffmpeg_exe, '-i', self.file_path, "-y", "-ss", "00:00:00","-t","1",\ "-s","%sx%s"%(thumb_icon_size[0], thumb_icon_size[1]),"-vframes","1","-f","image2", tmp_icon_path]) if os.path.exists(tmp_icon_path): self.icon_path = tmp_icon_path else: self.icon_path = None except Exception as e: Environment.add_warning("Could not process file", \ "%s - %s" % (self.file_path, e.__str__())) pass if (ext == ".gif" and not self.web_path): self._process_image( file_name )
try: self._process_video( file_name ) except IOError, e: '''This is an unknown file type. Do nothing and except as a file''' print("WARNING: ", e.__str__()) Environment.add_warning("Unknown file type", e.__str__()) else: # assume it is an image try: self._process_image( file_name ) except IOError, e: '''This is an unknown file type. Do nothing and except as a file''' print("WARNING: ", e.__str__()) Environment.add_warning("Unknown file type", e.__str__()) def _process_pdf(self, file_name): base, ext = os.path.splitext(file_name) # naming convetion should take care of inserting a suffix like icon, web # but these paths need a unique name icon_file_name = base + "_icon.png" tmp_icon_path = "%s/%s" % (self.tmp_dir, icon_file_name) thumb_web_size = self.get_web_file_size()
try: my._process_video( file_name ) except IOError, e: '''This is an unknown file type. Do nothing and except as a file''' print "WARNING: ", e.__str__() Environment.add_warning("Unknown file type", e.__str__()) else: # assume it is an image try: my._process_image( file_name ) except IOError, e: '''This is an unknown file type. Do nothing and except as a file''' print "WARNING: ", e.__str__() Environment.add_warning("Unknown file type", e.__str__()) def _process_pdf(my, file_name): base, ext = os.path.splitext(file_name) # naming convetion should take care of inserting a suffix like icon, web # but these paths need a unique name icon_file_name = base + "_icon.png" tmp_icon_path = "%s/%s" % (my.tmp_dir, icon_file_name) thumb_web_size = my.get_web_file_size()
# if there is more than one search_type, then go get each parent # individually # NOTE: this is very slow!!!! ref_sobjs = [] if len(search_types) > 1: ref_sobjs = [] for tmp_sobj in my.sobjects: try: ref_sobj = tmp_sobj.get_parent() if ref_sobj: ref_sobjs.append(ref_sobj) else: warning = "Dangling reference: %s" % tmp_sobj.get_search_key() Environment.add_warning(warning, warning) except SearchException, e: # skips unknown search_type/project print e.__str__() continue elif len(search_types) == 1: search_type = my.sobjects[0].get_value("search_type") try: if search_codes != None: ref_sobjs = Search.get_by_code(search_type, search_codes) else: ref_sobjs = Search.get_by_id(search_type, search_ids) except SearchException, e: # skips unknown search_type/project print e.__str__()
def _process_video(self, file_name): if not HAS_FFMPEG: return thumb_web_size = self.get_web_file_size() thumb_icon_size = (120, 100) exts = File.get_extensions(file_name) base, ext = os.path.splitext(file_name) icon_file_name = "%s_icon.png" % base web_file_name = "%s_web.jpg" % base tmp_icon_path = "%s/%s" % (self.tmp_dir, icon_file_name) tmp_web_path = "%s/%s" % (self.tmp_dir, web_file_name) #cmd = '''"%s" -i "%s" -r 1 -ss 00:00:01 -t 1 -s %sx%s -vframes 1 "%s"''' % (ffmpeg, self.file_path, thumb_web_size[0], thumb_web_size[1], tmp_web_path) #os.system(cmd) import subprocess try: # Attempt to resize only if necessary. Requires ffprobe call. # (More recent version of ffmpeg support the argument # -vf scale="'if(gt(iw, 640), 640, iw)':'if(gt(ih, 6400), 6400, -1)'" # allowing for scaling which preserves aspect ratio and only scales # when necessary. For now, it is necessary to query video size.) free_aspect_ratio = thumb_web_size[1] == -1 try: command = [ "ffprobe", "-print_format", "json", "-select_streams", "v:0", "-show_entries", "stream=height,width", self.file_path ] p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() data = jsonloads(out) streams = data.get("streams") or [] sample_stream = streams[0] width = int(sample_stream.get("width")) height = int(sample_stream.get("height")) max_width = thumb_web_size[0] max_height = max_width * 10 if free_aspect_ratio else thumb_web_size[ 1] if width < max_width and height < max_height: # Resizing is not necessary size_option = "" size = "" elif not free_aspect_ratio and (width > max_width or height > max_height): size_option = "-s" size = "%sx%s" % (thumb_web_size[0], thumb_web_size[1]) else: if width > height: size_option = "-vf" size = "scale=%s:-1" % thumb_web_size[0] elif height > width: aspect_ratio = float(float(height) / (width)) if aspect_ratio >= 10: size_option = "-vf" size = "scale=-1:%s" % max_height else: new_height = max_height new_width = float(new_height) / height if new_width > max_width: new_width = max_width new_height = height * float(new_width) / width size_option = "-vf" size = "scale=%s:-1" % max_width else: size_option = "-vf" size = "scale=-1:%s" % max_height except Exception as e: if free_aspect_ratio: size_option = "-vf" size = "scale=%s:-1" % thumb_web_size[0] else: size_option = "-s" size = "%sx%s" % (thumb_web_size[0], thumb_web_size[1]) command = [ ffmpeg_exe, '-i', self.file_path, "-y", "-ss", "00:00:00", "-t", "1" ] if size_option and size: command.extend([size_option, size]) command.extend(["-vframes", "1", "-f", "image2", tmp_web_path]) subprocess.call(command) if os.path.exists(tmp_web_path): self.web_path = tmp_web_path else: self.web_path = None except Exception as e: Environment.add_warning("Could not process file", \ "%s - %s" % (self.file_path, e.__str__())) pass try: subprocess.call([ffmpeg_exe, '-i', self.file_path, "-y", "-ss", "00:00:00","-t","1",\ "-s","%sx%s"%(thumb_icon_size[0], thumb_icon_size[1]),"-vframes","1","-f","image2", tmp_icon_path]) if os.path.exists(tmp_icon_path): self.icon_path = tmp_icon_path else: self.icon_path = None except Exception as e: Environment.add_warning("Could not process file", \ "%s - %s" % (self.file_path, e.__str__())) pass if (ext == ".gif" and not self.web_path): self._process_image(file_name)
def get_schema_wdg(my, schema): web = WebContainer.get_web() div = DivWdg() div.add_style("margin: 10 0 10 0") if not schema: Environment.add_warning("No schema", "No schema found") return div schema_xml = schema.get_xml_value("schema") code = schema.get_code() schema_search_types = schema_xml.get_values("schema/search_type/@name") if not schema_search_types: return title = DivWdg() view_margin_top = '4px' title.add_styles( "margin-top: %s; margin-bottom: 3px; vertical-align: middle" % view_margin_top ) if not web.is_IE(): title.add_styles( "margin-left: -10px; margin-right: -10px;" ) title.add_looks( "navmenu_header" ) title_label = SpanWdg() title_label.add_styles( "margin-left: 6px; padding-bottom: 2px;" ) title_label.add_looks( "fnt_title_5 fnt_bold" ) title_label.add("%s Schema" % code.capitalize()) title.add(title_label) #title.add_style("margin-top: 7px") #title.add_style("font-weight: bold") #title.add_style("font-size: 1.1em") #title.add_style("color: black") #underline = HtmlElement.hr() #underline.add_style("color: black") #underline.add_style("size: 1px") #underline.add_style("margin-top: -3px") #title.add(underline) div.add( title ) for schema_search_type in schema_search_types: try: search_type_obj = SearchType.get(schema_search_type) except SearchException: title = "<span style='color: #F44'>? %s</span>" % schema_search_type else: title = search_type_obj.get_title() span = DivWdg() span.add_style("padding: 1px") options = { 'search_type': schema_search_type, 'view': 'table', 'schema_default_view': 'true', } link = my.get_link_wdg("schema", "main_body", title, options) # walk up the tree current_type = schema_search_type has_parent = False while 1: parent_type = schema.get_parent_type(current_type) if parent_type and parent_type != '*': span.add(" ") has_parent = True else: if has_parent: span.add("+ ") break current_type = parent_type span.add(link) div.add(span) return div
try: self._process_video(file_name) except IOError, e: '''This is an unknown file type. Do nothing and except as a file''' print("WARNING: ", e.__str__()) Environment.add_warning("Unknown file type", e.__str__()) else: # assume it is an image try: self._process_image(file_name) except IOError, e: '''This is an unknown file type. Do nothing and except as a file''' print("WARNING: ", e.__str__()) Environment.add_warning("Unknown file type", e.__str__()) def _process_pdf(self, file_name): base, ext = os.path.splitext(file_name) # naming convetion should take care of inserting a suffix like icon, web # but these paths need a unique name icon_file_name = base + "_icon.png" tmp_icon_path = "%s/%s" % (self.tmp_dir, icon_file_name) thumb_web_size = self.get_web_file_size() web_file_name = base + "_web.png" tmp_web_path = "%s/%s" % (self.tmp_dir, web_file_name) if sys.platform == 'darwin':
try: my._process_video(file_name) except IOError, e: '''This is an unknown file type. Do nothing and except as a file''' print "WARNING: ", e.__str__() Environment.add_warning("Unknown file type", e.__str__()) else: # assume it is an image try: my._process_image(file_name) except IOError, e: '''This is an unknown file type. Do nothing and except as a file''' print "WARNING: ", e.__str__() Environment.add_warning("Unknown file type", e.__str__()) def _process_pdf(my, file_name): base, ext = os.path.splitext(file_name) # naming convetion should take care of inserting a suffix like icon, web # but these paths need a unique name icon_file_name = base + "_icon.png" tmp_icon_path = "%s/%s" % (my.tmp_dir, icon_file_name) thumb_web_size = my.get_web_file_size() web_file_name = base + "_web.png" tmp_web_path = "%s/%s" % (my.tmp_dir, web_file_name) if sys.platform == 'darwin':
def get_display(self): self.task_per_process_dict = {} # get the sobject and relevent parameters sobject = self.get_current_sobject() search_type = sobject.get_search_type() if self.pipeline_code: pipeline = Pipeline.get_by_code(self.pipeline_code) else: pipeline = Pipeline.get_by_sobject(sobject, allow_default=True) if not pipeline: # while default is auto-generated, an empty pipeline code will trigger this Environment.add_warning('missing pipeline code', \ "Pipeline code is empty for [%s]" %sobject.get_code()) return if self.include_sub_task_value: self.recurse = True processes = pipeline.get_processes(recurse=self.recurse) # filter out process names if self.process_names != None: filtered_processes = [] for process in processes: if process.get_name() in self.process_names: filtered_processes.append(process) processes = filtered_processes # draw the proceses top = DivWdg() action = DivWdg() action.add_style("float: right") top.add(action) table = Table() table.add_style("font-size: 11px") top.add(table) #if self.max_count: # percent_width = float(len(processes)) / float(self.max_count+1) * 100 #else: # percent_width = 100 # we want them more squeezed together when in abbr mode if self.label_select_value != 'abbr': percent_width = 100 table.add_style("width: %d%%" % percent_width) tr = table.add_row() for process in processes: completion_wdg = self.get_completion(sobject, process,\ len(processes)) if not completion_wdg: continue td = table.add_cell(completion_wdg) td.add_style('border-width: 0px') tr = table.add_row(css='underline') tr.add_color("color", "color") label_format = self.get_option("label_format") if not label_format: label_format = self.label_select_value tup_list = self._get_labels(processes, label_format, show_sub_pipeline=self.is_ajax()) style = '' for i, tup in enumerate(tup_list): name, process = tup span = SpanWdg() child_pipeline = process.get_child_pipeline() if child_pipeline: title = SpanWdg() title.add("[%s]" % name) title.add_style("margin-left: -5px") swap = SwapDisplayWdg.get_triangle_wdg() content_id = '%s_%s' % (sobject.get_search_key(), child_pipeline.get_id()) content_id = self.generate_unique_id(content_id) content = DivWdg(id=content_id) SwapDisplayWdg.create_swap_title(title, swap, content) dyn_load = AjaxLoader(display_id=content_id) args_dict = {'search_type': sobject.get_search_type()} args_dict['search_id'] = sobject.get_id() args_dict['pipeline_skey'] = child_pipeline.get_search_key() dyn_load.set_load_method('_get_child_wdg') dyn_load.set_load_class('pyasm.widget.ParallelStatusWdg', load_args=args_dict) dyn_load.add_element_name('cal_sub_task') on_script = dyn_load.get_on_script(load_once=True) swap.add_action_script(on_script, "set_display_off('%s')" % content_id) script = "if ($(%s).getStyle('display')=='none') {%s}" \ %(swap.swap1_id, on_script) title.add_event('onclick', script) span.add(swap) span.add(title) span.add(HtmlElement.br()) span.add(HtmlElement.br()) span.add(content) else: span.add(name) if self.task_per_process_dict.get(process) == 0: span.add_class('unused') if label_format == 'small' or label_format == 'abbr': span.add_class('smaller') if not label_format == "none": table.add_cell(span) return top
def preprocess(self): # protect against the case where there is a single sobject that # is an insert (often seen in "insert") if self.is_preprocessed == True: return skip = False if len(self.sobjects) == 1: if not self.sobjects[0].has_value("search_type"): skip = True if not skip: search_types = SObject.get_values(self.sobjects, 'search_type', unique=True) try: search_codes = SObject.get_values(self.sobjects, 'search_code', unique=True) search_ids = None except Exception as e: print "WARNING: ", e search_ids = SObject.get_values(self.sobjects, 'search_id', unique=True) search_codes = None else: search_types = [] search_codes = [] # if there is more than one search_type, then go get each parent # individually # NOTE: this is very slow!!!! ref_sobjs = [] if len(search_types) > 1: ref_sobjs = [] for tmp_sobj in self.sobjects: try: ref_sobj = tmp_sobj.get_parent() if ref_sobj: ref_sobjs.append(ref_sobj) else: warning = "Dangling reference: %s" % tmp_sobj.get_search_key( ) Environment.add_warning(warning, warning) except SearchException as e: # skips unknown search_type/project print e.__str__() continue elif len(search_types) == 1: search_type = self.sobjects[0].get_value("search_type") try: if search_codes != None: ref_sobjs = Search.get_by_code(search_type, search_codes) else: ref_sobjs = Search.get_by_id(search_type, search_ids) except SearchException as e: # skips unknown search_type/project print e.__str__() pass # TODO: None defaults to search_key, should be empty self.ref_sobj_dict = SObject.get_dict(ref_sobjs, None) # when drawn as part of a TbodyWdg, we want to disable the calculation # of most things so that it will not try to display a prev row if self.get_option('disable') == 'true': self.ref_sobj_dict = None self.empty = True self.is_preprocessed = True
def _process_image(self, file_name): base, ext = os.path.splitext(file_name) # get all of the extensions exts = File.get_extensions(file_name) frame = 0 if len(exts) == 2: try: frame = int(exts[0]) base = base.replace(".%s" % exts[0], '' ) except ValueError: frame = 0 if frame: icon_file_name = "%s_icon.%s.png" % (base, exts[0]) web_file_name = "%s_web.%s.jpg" % (base, exts[0]) else: icon_file_name = "%s_icon.png" % base web_file_name = "%s_web.jpg" % base tmp_icon_path = "%s/%s" % (self.tmp_dir, icon_file_name) tmp_web_path = "%s/%s" % (self.tmp_dir, web_file_name) # create the web image try: if self.texture_mode: self._resize_texture(self.file_path, tmp_web_path, 0.5) self.web_path = tmp_web_path # create the icon thumb_size = (120,100) try: self._resize_image(tmp_web_path, tmp_icon_path, thumb_size) except TacticException: self.icon_path = None else: self.icon_path = tmp_icon_path elif self.icon_mode: # just icon, no web # create the icon only thumb_size = (120,100) try: self._resize_image(self.file_path, tmp_icon_path, thumb_size) except TacticException: self.icon_path = None else: self.icon_path = tmp_icon_path else: thumb_size = self.get_web_file_size() try: self._resize_image(self.file_path, tmp_web_path, thumb_size) except TacticException: self.web_path = None else: self.web_path = tmp_web_path # create the icon thumb_size = (120,100) try: self._resize_image(tmp_web_path, tmp_icon_path, thumb_size) except TacticException: self.icon_path = None else: self.icon_path = tmp_icon_path # check icon file size, reset to none if it is empty # TODO: use finally in Python 2.5 if self.web_path: web_path_size = os.stat(self.web_path)[stat.ST_SIZE] if not web_path_size: self.web_path = None if self.icon_path: icon_path_size = os.stat(self.icon_path)[stat.ST_SIZE] if not icon_path_size: self.icon_path = None except IOError, e: Environment.add_warning("Could not process file", \ "%s - %s" % (self.file_path, e.__str__())) self.web_path = None self.icon_path = None
def get_display(my): my.task_per_process_dict = {} # get the sobject and relevent parameters sobject = my.get_current_sobject() search_type = sobject.get_search_type() if my.pipeline_code: pipeline = Pipeline.get_by_code(my.pipeline_code) else: pipeline = Pipeline.get_by_sobject(sobject, allow_default=True) if not pipeline: # while default is auto-generated, an empty pipeline code will trigger this Environment.add_warning('missing pipeline code', \ "Pipeline code is empty for [%s]" %sobject.get_code()) return if my.include_sub_task_value: my.recurse = True processes = pipeline.get_processes(recurse=my.recurse) # filter out process names if my.process_names != None: filtered_processes = [] for process in processes: if process.get_name() in my.process_names: filtered_processes.append(process) processes = filtered_processes # draw the proceses top = DivWdg() action = DivWdg() action.add_style("float: right") top.add(action) table = Table() table.add_style("font-size: 11px") top.add(table) #if my.max_count: # percent_width = float(len(processes)) / float(my.max_count+1) * 100 #else: # percent_width = 100 # we want them more squeezed together when in abbr mode if my.label_select_value != 'abbr': percent_width = 100 table.add_style("width: %d%%" % percent_width) tr = table.add_row() for process in processes: completion_wdg = my.get_completion(sobject, process,\ len(processes)) if not completion_wdg: continue td = table.add_cell( completion_wdg ) td.add_style('border-width: 0px') tr = table.add_row(css='underline') tr.add_color("color", "color") label_format = my.get_option("label_format") if not label_format: label_format = my.label_select_value tup_list = my._get_labels(processes, label_format, show_sub_pipeline=my.is_ajax()) style = '' for i, tup in enumerate(tup_list): name, process = tup span = SpanWdg() child_pipeline = process.get_child_pipeline() if child_pipeline: title = SpanWdg() title.add("[%s]" % name) title.add_style("margin-left: -5px") swap = SwapDisplayWdg.get_triangle_wdg() content_id = '%s_%s' %(sobject.get_search_key(), child_pipeline.get_id()) content_id = my.generate_unique_id(content_id) content = DivWdg(id=content_id) SwapDisplayWdg.create_swap_title(title, swap, content) dyn_load = AjaxLoader(display_id=content_id) args_dict = {'search_type': sobject.get_search_type()} args_dict['search_id'] = sobject.get_id() args_dict['pipeline_skey'] = child_pipeline.get_search_key() dyn_load.set_load_method('_get_child_wdg') dyn_load.set_load_class('pyasm.widget.ParallelStatusWdg', load_args=args_dict) dyn_load.add_element_name('cal_sub_task') on_script = dyn_load.get_on_script(load_once=True) swap.add_action_script(on_script, "set_display_off('%s')" %content_id) script = "if ($(%s).getStyle('display')=='none') {%s}" \ %(swap.swap1_id, on_script) title.add_event('onclick', script) span.add(swap) span.add(title) span.add(HtmlElement.br()) span.add(HtmlElement.br()) span.add(content) else: span.add(name) if my.task_per_process_dict.get(process) == 0: span.add_class('unused') if label_format == 'small' or label_format == 'abbr': span.add_class('smaller') if not label_format == "none": table.add_cell(span) return top
def preprocess(self): # protect against the case where there is a single sobject that # is an insert (often seen in "insert") if self.is_preprocessed == True: return skip = False if len(self.sobjects) == 1: if not self.sobjects[0].has_value("search_type"): skip = True if not skip: search_types = SObject.get_values(self.sobjects, 'search_type', unique=True) try: search_codes = SObject.get_values(self.sobjects, 'search_code', unique=True) search_ids = None except Exception as e: print "WARNING: ", e search_ids = SObject.get_values(self.sobjects, 'search_id', unique=True) search_codes = None else: search_types = [] search_codes = [] # if there is more than one search_type, then go get each parent # individually # NOTE: this is very slow!!!! ref_sobjs = [] if len(search_types) > 1: ref_sobjs = [] for tmp_sobj in self.sobjects: try: ref_sobj = tmp_sobj.get_parent() if ref_sobj: ref_sobjs.append(ref_sobj) else: warning = "Dangling reference: %s" % tmp_sobj.get_search_key() Environment.add_warning(warning, warning) except SearchException as e: # skips unknown search_type/project print e.__str__() continue elif len(search_types) == 1: search_type = self.sobjects[0].get_value("search_type") try: if search_codes != None: ref_sobjs = Search.get_by_code(search_type, search_codes) else: ref_sobjs = Search.get_by_id(search_type, search_ids) except SearchException as e: # skips unknown search_type/project print e.__str__() pass # TODO: None defaults to search_key, should be empty self.ref_sobj_dict = SObject.get_dict(ref_sobjs, None) # when drawn as part of a TbodyWdg, we want to disable the calculation # of most things so that it will not try to display a prev row if self.get_option('disable') == 'true': self.ref_sobj_dict = None self.empty = True self.is_preprocessed = True
# if there is more than one search_type, then go get each parent # individually # NOTE: this is very slow!!!! ref_sobjs = [] if len(search_types) > 1: ref_sobjs = [] for tmp_sobj in my.sobjects: try: ref_sobj = tmp_sobj.get_parent() if ref_sobj: ref_sobjs.append(ref_sobj) else: warning = "Dangling reference: %s" % tmp_sobj.get_search_key( ) Environment.add_warning(warning, warning) except SearchException, e: # skips unknown search_type/project print e.__str__() continue elif len(search_types) == 1: search_type = my.sobjects[0].get_value("search_type") try: if search_codes != None: ref_sobjs = Search.get_by_code(search_type, search_codes) else: ref_sobjs = Search.get_by_id(search_type, search_ids) except SearchException, e: # skips unknown search_type/project print e.__str__()