def _test_groupcheckin(self): # FIXME: can't find maya_render.####.iff return file_path = "./maya_render.####.iff" range = FileRange(1, 12) # create new test files expanded_paths = FileGroup.expand_paths(file_path, range) for expanded_path in expanded_paths: file = open(expanded_path, 'w') file.write("file: %s" % expanded_path) file.close() # checkin the frames file_types = ["main"] file_paths = [file_path] checkin = FileGroupCheckin(self.person, file_paths, file_types, range, \ column="frames") checkin.execute() # delete the test files for expanded_path in expanded_paths: os.unlink(expanded_path)
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_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 _test_preallocation_checkin(self): snapshot_type = "file" context = "preallocation" file_name = 'whatever.jpg' file_type = 'jpg' # create an empty snapshot snapshot = Snapshot.create(self.person, snapshot_type=snapshot_type, context=context) # preallocate with no name or type path = snapshot.get_preallocated_path() server = Config.get_value("install", "server") if server: expected = "%s_preallocation_%s_v001" % (self.person.get_code(), server) else: expected = "%s_preallocation_v001" % (self.person.get_code()) self.assertEquals(True, path.endswith(expected)) # preallocate with a file name and file type # since it's meant for FileAppendCheckin, the checkin_type should be 'strict' path = snapshot.get_preallocated_path(file_type, file_name, checkin_type='strict') if server: self.assertEquals( True, None != re.search( 'unittest/person/\w+/preallocation/whatever_preallocation_\w+_v001.jpg$', path)) else: self.assertEquals( True, None != re.search( 'unittest/person/\w+/preallocation/whatever_preallocation_v001.jpg$', path)) # create a file directly in the path location and register in # transaction f = open(path, 'wb') f.write("wowow") f.close() # add this file to the snapshot and force the name snapshot_code = snapshot.get_code() checkin = FileAppendCheckin(snapshot_code, [path], [file_type], keep_file_name=True, mode='preallocate') checkin.execute() # check that it worked snapshot = checkin.get_snapshot() lib_dir = snapshot.get_lib_dir() file_name = snapshot.get_file_name_by_type(file_type) self.assertEquals(True, os.path.exists("%s/%s" % (lib_dir, file_name))) # test preallocation on a sequence file_name = "images_%0.4d.png" file_type = 'sequence' file_range = FileRange(1, 5) # should specify strict checkin_type for Append checkin after path = snapshot.get_preallocated_path(file_type=file_type, file_name=file_name, checkin_type='strict') # imitate a render by building files directly to the path for i in range(1, 6): cur_path = path % i f = open(cur_path, 'wb') f.write("wowow") f.close() # register these files snapshot_code = snapshot.get_code() # should specify strict checkin_type for Append checkin checkin = FileGroupAppendCheckin(snapshot_code, [path], [file_type], file_range, \ keep_file_name=True, mode='preallocate', checkin_type='strict') checkin.execute() snapshot = checkin.get_snapshot() # get the file paths file_names = snapshot.get_expanded_file_names(file_type) lib_dir = snapshot.get_lib_dir() for file_name in file_names: path = "%s/%s" % (lib_dir, file_name) self.assertEquals(True, os.path.exists(path))
def _handle_files(self, snapshot, widget, upstream, recursive=True): web_dir = snapshot.get_web_dir() xml = snapshot.get_xml_value("snapshot") # handle files files = xml.get_nodes("snapshot/file") for file in files: file_code = Xml.get_attribute(file, "file_code") file_type = Xml.get_attribute(file, "type") file_range = Xml.get_attribute(file, "file_range") #file_range = "1-4/1" dir = snapshot.get_client_lib_dir(file_type=file_type) lib_dir = snapshot.get_lib_dir(file_type=file_type) open_button = IconButtonWdg( "Explore: %s" % dir, IconWdg.LOAD, False) if dir == lib_dir: open_button.add_behavior({'type':'click_up', 'cbjs_action': '''var applet = spt.Applet.get(); spt.alert('You are not allowed to browse directories on a web server.'); '''}) else: open_button.add_behavior({'type':'click_up', 'dir' : dir, 'cbjs_action': ''' var applet = spt.Applet.get(); var dir = bvr.dir; applet.open_explorer(dir);'''}) open_button.add_class('small') open_button.add_style('float: left') widget.add(open_button) if file_range: file_name = Xml.get_attribute(file, "name") widget.add("%s [code = %s, type = %s]" % (file_name, file_code, file_type)) widget.add(HtmlElement.br(2)) # display all of the paths file_names = FileGroup.expand_paths( file_name, FileRange.get(file_range) ) for file_name in file_names: #link = HtmlElement.href(file_name, "%s/%s" % (web_dir, file_name), target="_blank" ) link = SpanWdg(file_name) link.add_color("color", "color") widget.add(link) widget.add(HtmlElement.br()) else: thumb = DependencyThumbWdg() thumb.set_show_filename(True) thumb.set_sobject(snapshot) thumb.set_icon_size(15) thumb.set_image_link_order([file_type]) thumb.set_option('detail', 'false') widget.add(SpanWdg(thumb, css='small')) widget.add("[code = %s, type = %s]" % ( file_code, file_type)) widget.add(HtmlElement.br()) block = DivWdg() block.add_style("margin-left: 30px") block.add_style("margin-top: 10px") nodes = xml.get_nodes("snapshot/file[@file_code='%s']/ref" % file_code) widget.add(HtmlElement.br(clear="all")) # handle sub refs for node in nodes: self._handle_ref_node(node, block, upstream, recursive) block.add(HtmlElement.br()) if nodes: widget.add(block) widget.add(HtmlElement.br()) files = xml.get_nodes("snapshot/unknown_ref") if files: widget.add(HtmlElement.b("Unknown ref.")) for file in files: block = DivWdg() block.add_style("margin-left: 30px") block.add_style("margin-top: 10px") block.add( IconWdg( "Unknown", IconWdg.UNKNOWN) ) path = Xml.get_attribute(file, "path") block.add(path) widget.add(block)