def _test_naming_util(my): #my.clear_naming() naming_util = NamingUtil() # these should evaluate to be the same file_naming_expr1 = ['{$PROJECT}__{context[0]}__hi_{$BASEFILE}.{$EXT}','{project.code}__{context[0]}__hi_{basefile}.{ext}'] dir_naming_expr2 = ['{$PROJECT}/{context[1]}/somedir/{@GET(.name_first)}','{project.code}/{snapshot.context[1]}/somedir/{sobject.name_first}'] process= 'light' context = 'light/special' type = 'ma' version = 2 virtual_snapshot = Snapshot.create_new() virtual_snapshot_xml = '<snapshot process=\'%s\'><file type=\'%s\'/></snapshot>' % (process, type) virtual_snapshot.set_value("snapshot", virtual_snapshot_xml) virtual_snapshot.set_value("process", process) virtual_snapshot.set_value("context", context) virtual_snapshot.set_value("snapshot_type", 'file') virtual_snapshot.set_sobject(my.person) virtual_snapshot.set_value("version", version) file_name = "abc.txt" file_obj = File(File.SEARCH_TYPE) file_obj.set_value("file_name", file_name) for naming_expr in file_naming_expr1: file_name = naming_util.naming_to_file(naming_expr, my.person, virtual_snapshot, file=file_obj, file_type="main") my.assertEquals(file_name,'unittest__light__hi_abc.txt') for naming_expr in dir_naming_expr2: dir_name = naming_util.naming_to_dir(naming_expr, my.person, virtual_snapshot, file=file_obj, file_type="main") my.assertEquals(dir_name,'unittest/special/somedir/Philip')
def get_from_expression(my, naming_expr): naming_util = NamingUtil() file_type = my.get_file_type() return naming_util.naming_to_file(naming_expr, my.sobject, my.snapshot, my.file_object, ext=my.get_ext(), file_type=file_type)
def get_from_expression(my, naming_expr): naming_util = NamingUtil() file_type = my.get_file_type() # build the dir name return naming_util.naming_to_dir(naming_expr, my.sobject, my.snapshot, file=my._file_object, file_type=file_type)
def get_from_expression(self, naming_expr): naming_util = NamingUtil() file_type = self.get_file_type() return naming_util.naming_to_file(naming_expr, self.sobject, self.snapshot, self.file_object, ext=self.get_ext(), file_type=file_type)
def get_from_db_naming(my, search_type): project_code = Project.get_project_code() if project_code in ["admin", "sthpw"]: return "" file_type = my.get_file_type() filename = my.file_object.get_full_file_name() naming = Naming.get(my.sobject, my.snapshot, file_path=filename) if not naming: return None if naming and my.checkin_type: checkin_type = naming.get_value('checkin_type') if checkin_type and my.checkin_type != checkin_type: print "mismatched checkin_type!" naming = None return None naming_util = NamingUtil() # Provide a mechanism for a custom class naming_class = naming.get_value("class_name", no_exception=True) if naming_class: kwargs = { 'sobject': my.sobject, 'snapshot': my.snapshot, 'file_object': my.file_object, 'ext': my.get_ext(), 'mode': 'file' } naming = Common.create_from_class_path(naming_class, kwargs) filename = naming.get_file() if filename: return filename # provide a mechanism for a custom client side script script_path = naming.get_value("script_path", no_exception=True) if script_path: project_code = my.sobject.get_project_code() input = { 'sobject': my.sobject, 'snapshot': my.snapshot, 'file_object': my.file_object, 'ext': my.get_ext(), 'mode': 'file', 'project': project_code } from tactic.command import PythonCmd cmd = PythonCmd(script_path=script_path, input=input) results = cmd.execute() if results: return results naming_value = naming.get_value("file_naming") if not naming_value: is_versionless = naming.get_value("latest_versionless") or naming.get_value("current_versionless") if not is_versionless: return "" # FIXME: # if this is a versionless naming, then empty uses a default # This is put here because the check-in type is determined by the # naming here. Normally, this is passed through with "naming_expr" # but in snapshot.py, it is not yet known that this is an "auto" # checkin_type because it is defined in the naming and not the # process server = Config.get_value("install", "server") if server: naming_value= "{basefile}_{snapshot.process}_%s.{ext}" % server else: naming_value = "{basefile}_{snapshot.process}.{ext}" # check for manual_version manual_version = naming.get_value('manual_version') if manual_version == True: # if the file version is not the same as the snapshot version # then check to see if the snapshot already exists filename = my.file_object.get_full_file_name() version = my.get_version_from_file_name(filename) context = my.snapshot.get_context() if version > 0 and version != my.snapshot.get_value("version"): existing_snap = Snapshot.get_snapshot(\ my.snapshot.get_value("search_type"),\ my.snapshot.get_value("search_id"), context=context, \ version=version, show_retired=True) if existing_snap: raise TacticException('You have chosen manual version in Naming for this SObject. A snapshot with context "%s" and version "%s" already exists.' % (context, version) ) my.snapshot.set_value("version", version) my.snapshot.commit() file_type = my.get_file_type() return naming_util.naming_to_file(naming_value, my.sobject,my.snapshot,my.file_object,ext=my.get_ext(),file_type=file_type)
def get_from_expression(my, naming_expr): naming_util = NamingUtil() file_type = my.get_file_type() return naming_util.naming_to_file(naming_expr, my.sobject,my.snapshot,my.file_object,ext=my.get_ext(),file_type=file_type)
def get_from_db_naming(my, search_type): project_code = Project.get_project_code() if project_code in ["admin", "sthpw"]: return "" file_type = my.get_file_type() filename = my.file_object.get_full_file_name() naming = Naming.get(my.sobject, my.snapshot, file_path=filename) if not naming: return None if naming and my.checkin_type: checkin_type = naming.get_value('checkin_type') if checkin_type and my.checkin_type != checkin_type: print "mismatched checkin_type!" naming = None return None naming_util = NamingUtil() # Provide a mechanism for a custom class naming_class = naming.get_value("class_name", no_exception=True) if naming_class: kwargs = { 'sobject': my.sobject, 'snapshot': my.snapshot, 'file_object': my.file_object, 'ext': my.get_ext(), 'mode': 'file' } naming = Common.create_from_class_path(naming_class, kwargs) filename = naming.get_file() if filename: return filename # provide a mechanism for a custom client side script script_path = naming.get_value("script_path", no_exception=True) if script_path: project_code = my.sobject.get_project_code() input = { 'sobject': my.sobject, 'snapshot': my.snapshot, 'file_object': my.file_object, 'ext': my.get_ext(), 'mode': 'file', 'project': project_code } from tactic.command import PythonCmd cmd = PythonCmd(script_path=script_path, input=input) results = cmd.execute() if results: return results naming_value = naming.get_value("file_naming") if not naming_value: is_versionless = naming.get_value( "latest_versionless") or naming.get_value( "current_versionless") if not is_versionless: return "" # FIXME: # if this is a versionless naming, then empty uses a default # This is put here because the check-in type is determined by the # naming here. Normally, this is passed through with "naming_expr" # but in snapshot.py, it is not yet known that this is an "auto" # checkin_type because it is defined in the naming and not the # process server = Config.get_value("install", "server") if server: naming_value = "{basefile}_{snapshot.process}_%s.{ext}" % server else: naming_value = "{basefile}_{snapshot.process}.{ext}" # check for manual_version manual_version = naming.get_value('manual_version') if manual_version == True: # if the file version is not the same as the snapshot version # then check to see if the snapshot already exists filename = my.file_object.get_full_file_name() version = my.get_version_from_file_name(filename) context = my.snapshot.get_context() if version > 0 and version != my.snapshot.get_value("version"): existing_snap = Snapshot.get_snapshot(\ my.snapshot.get_value("search_type"),\ my.snapshot.get_value("search_id"), context=context, \ version=version, show_retired=True) if existing_snap: raise TacticException( 'You have chosen manual version in Naming for this SObject. A snapshot with context "%s" and version "%s" already exists.' % (context, version)) my.snapshot.set_value("version", version) my.snapshot.commit() file_type = my.get_file_type() return naming_util.naming_to_file(naming_value, my.sobject, my.snapshot, my.file_object, ext=my.get_ext(), file_type=file_type)
def get_from_db_naming(my, protocol): project_code = Project.get_project_code() if project_code in ["admin", "sthpw"]: return None # get the naming object naming = Naming.get(my.sobject, my.snapshot) if not naming: return None if protocol == 'sandbox': mode = 'sandbox_dir' else: mode = 'dir' # Provide a mechanism for a custom class naming_class = naming.get_value("class_name", no_exception=True) #naming_class = "pyasm.biz.TestFileNaming" if naming_class: kwargs = { 'sobject': my.sobject, 'snapshot': my.snapshot, 'file_object': my._file_object, #'ext': my.get_ext(), 'file_type': my.file_type, 'mode': mode } naming = Common.create_from_class_path(naming_class, [], kwargs) dirname = naming.get_dir() if dirname: return dirname # provide a mechanism for a custom client side script script_path = naming.get_value("script_path", no_exception=True) if script_path: project_code = my.sobject.get_project_code() input = { 'sobject': my.sobject, 'snapshot': my.snapshot, 'file_object': my._file_object, #'ext': my.get_ext(), 'file_type': my.file_type, 'mode': mode, 'project': project_code } from tactic.command import PythonCmd cmd = PythonCmd(script_path=script_path, input=input) results = cmd.execute() if results: return results naming_util = NamingUtil() naming_expr = '' if protocol == 'sandbox': naming_expr = naming.get_value("sandbox_dir_naming") if not naming_expr: naming_expr = naming.get_value("dir_naming") # so it can take the default if not naming_expr: return None file_type = my.get_file_type() # build the dir name dir_name = naming_util.naming_to_dir(naming_expr, my.sobject, my.snapshot, file=my._file_object, file_type=file_type) return dir_name
def get_from_db_naming(self, protocol): project_code = Project.get_project_code() if project_code in ["admin", "sthpw"]: return None # get the naming object naming = Naming.get(self.sobject, self.snapshot) if not naming: return None if not self.verify_checkin_type(naming): return None if protocol == 'sandbox': mode = 'sandbox_dir' else: mode = 'dir' # Provide a mechanism for a custom class naming_class = naming.get_value("class_name", no_exception=True) #naming_class = "pyasm.biz.TestFileNaming" if naming_class: kwargs = { 'sobject': self.sobject, 'snapshot': self.snapshot, 'file_object': self._file_object, #'ext': self.get_ext(), 'file_type': self.file_type, 'mode': mode } naming = Common.create_from_class_path(naming_class, [], kwargs) dirname = naming.get_dir() if dirname: return dirname # provide a mechanism for a custom client side script script_path = naming.get_value("script_path", no_exception=True) if script_path: project_code = self.sobject.get_project_code() input = { 'sobject': self.sobject, 'snapshot': self.snapshot, 'file_object': self._file_object, #'ext': self.get_ext(), 'file_type': self.file_type, 'mode': mode, 'project': project_code } from tactic.command import PythonCmd cmd = PythonCmd(script_path=script_path, input=input) results = cmd.execute() if results: return results naming_util = NamingUtil() naming_expr = '' if protocol == 'sandbox': naming_expr = naming.get_value("sandbox_dir_naming") if not naming_expr: naming_expr = naming.get_value("dir_naming") # so it can take the default if not naming_expr: return None file_type = self.get_file_type() alias = naming.get_value("base_dir_alias", no_exception=True) # build the dir name dir_name = naming_util.naming_to_dir(naming_expr, self.sobject, self.snapshot, file=self._file_object, file_type=file_type) return dir_name
def get_from_expression(self, naming_expr): naming_util = NamingUtil() file_type = self.get_file_type() return naming_util.naming_to_file(naming_expr, self.sobject,self.snapshot,self.file_object,ext=self.get_ext(),file_type=file_type)