Exemplo n.º 1
0
 def getAllPatternsId(self):
     """
     Gets all the patterns of the target section, creating a list with pattern instances
     :param id: Integer
     :return: List
     """
     c = con()
     for p in c.getAllPatternSection(self.id):
         #adicionando na lista um pattern novo
         self.patterns.append(pattern(p))
Exemplo n.º 2
0
 def set_pattern(self, type):
     if type <= 3:
         if self.w <= pattern.pattern(
                 type).w() and self.h <= pattern.pattern(type).h():
             self.w = pattern.pattern(type).w()
             self.h = pattern.pattern(type).h()
         elif self.w <= pattern.pattern(type).w():
             self.w = pattern.pattern(type).w()
         elif self.h <= pattern.pattern(type).h():
             self.h = pattern.pattern(type).h()
         posi = self.__position(self.w, self.h,
                                pattern.pattern(type).w(),
                                pattern.pattern(type).h())
         Map = []
         died_cell = [b] * self.w
         for i in range(1, posi['above'] + 1):
             Map.append(died_cell)
         element = []
         element = self.__pattern_manage(
             pattern.pattern(type).graph(),
             pattern.pattern(type).h(), posi['right'], posi['left'])
         for i in range(pattern.pattern(type).h()):
             Map.append(element[i])
         for i in range(posi['below']):
             Map.append(died_cell)
         self.pattern = Map
         return Map
     elif type >= 4 and type <= 100:
         self.pattern = pattern.pattern_maker(self.w, self.h, type,
                                              self.set_map(self.w, self.h))
         #print(self.pattern)
         return self.pattern
Exemplo n.º 3
0
def main ():
	sFktname = "main"
	
	# handle arguments
	try:
		opts, args = getopt.getopt(sys.argv[1:], "hcws:p:", ["help", "copy", "use-chemical-format", "search=", "pattern="])
	except:
		print_help ()
		sys.exit(2)

	# handle options
	for o, a in opts:
		if o in ("-h", "--help"):
			print_help()
			sys.exit(2)
		elif o in ("-c", "--copy"):
			settings.copymode = True
		elif o in ("-p", "--pattern"):
			settings.pattern_user = a
		elif o in ("-w", "--use-chemical-format"):
			settings.use_chemical_format = True
		elif o in ("-s", "--search"):
			settings.search_term = a
				
	# handle arguments
	if len(args) == 0:
		ePrint(1, sFktname, "No Files specified")
	
	# check, whether files have valid paths
	for fn in args:
		if path.exists(fn) == False:
			ePrint(1, sFktname, "Path not found: {}".format(fn))
			sys.exit(2)

	# if search_term is given search for it first
	# and if found append it to the cache
	if settings.search_term:
		rel = search_release(settings.search_term)
		if rel:
			cache.rels_found.append(rel)

	# enter main loop
	for fn in args:

		# fill pattern
		if settings.pattern_user:
			pat = pattern.pattern(settings.pattern_user)
		else:
			pat = pattern.pattern(settings.pattern_default)

		# try to get information from tags
		new_track = id3_to_track(fn)

		suffix = split_ld(fn)

		# we have flags in the pattern class to
		# determine wich keys are used

		res_t = None

		# currently we only can operate if we have some information
		if new_track.is_empty() == False: 
			# if artist field is set
			if pat.artist:
				if new_track.artist == "":
					res_t = search_clever(new_track)
					if res_t:
						new_track.artist = res_t.artist
					else:
						ePrint(1, sFktname, "Cant determine Artist Field for: {}".format(fn))
						continue
				pat.replace_artist(new_track.artist)

			# if title field is set
			if pat.title:
				if new_track.title == "":
					res_t = search_clever(new_track)
					if res_t:
						new_track.title = res_t.title
					else:
						ePrint(1, sFktname, "Cant determine title Field for: {}".format(fn))
						continue
				pat.replace_title(new_track.title)

			# if key field is set
			if pat.key:
				if new_track.key == "":
					res_t = search_clever(new_track)
					if res_t:
						# map key
						if (res_t.key in settings.quint_map) and settings.use_chemical_format == None:
							new_track.key = settings.quint_map[res_t.key]
						else:
							new_track.key = res_t.key
					else:
						ePrint(1, sFktname, "Cant determine key Field for: {}".format(fn))
						continue
				pat.replace_key(new_track.key)

			pat.replace_tn(new_track.tn)

			final_name = "{}.{}".format(pat.get_result(), suffix)
		else:
			final_name = fn

		ePrint(1, sFktname, "{} will be renamed to: {}".format(fn, final_name))

		# rename or copy
		if fn == final_name:
			continue
		else:
			if settings.copymode:
				shutil.copy(fn, final_name)
			else:
				rename(fn, final_name)
Exemplo n.º 4
0
import pattern

print pattern.pattern(1)
print pattern.pattern(2)
print pattern.pattern(5)
Exemplo n.º 5
0
import pbs_tools
import pattern

pt = pbs_tools.pbs_tools()
t = pt.table['job']
filter = {}
filter['queue'] = ['iworkq', 'testq']
filter['Job_Owner'] = ['pbsadmin@demo']

res_table = {}
pattern = pattern.pattern()

print pattern.enumerate_dict_pair(t)
for i in pattern.enumerate_dict(t):
    obj = t[i]
    res = pattern.__filter__(lambda x: pattern.dict_orvalue_filter(filter, x),
                             obj)
    res_table = pattern.dict_acc(res_table, i, res)

print res_table.keys()
#ncpus=0
#def get_ncpus(key,obj):
#	if obj.has_key('Resource_List.ncpus'):
#		return int(obj['Resource_List.ncpus'][0])
#	return 0

#for i in pattern.enumerate_dict(t):
#	obj=t[i];
#	res=pattern.__filter__(lambda x:pattern.dict_orvalue_filter(filter,x),obj)
#	ncpus=pattern.__acc__(ncpus,lambda x,y:x+y,get_ncpus,i,res);