Пример #1
0
	def resize_string_keeping_height_ratio(string, width, output_format=None, resizemode=Image.ANTIALIAS):
		if not Strings.is_string(string):
			return string

		image = Images.get_image_from_string(string)
		if output_format is None:
			output_format = image.format

		image = Images.resize_image_keeping_height_ratio(image, width)
		return Images.get_string_from_image(image, output_format)
Пример #2
0
	def __init__(self, data, args=()):
		"""
		Receive the data to be converted and parameters.
		"""
		self.value = data

		if not data: 
			return

		self.value = Strings.capitalize(data)
Пример #3
0
	def sync(self, data):
	
		# make a query from a "to match template"
		query = SyncBC.get_match_query(self.sync_section, data)
		if query is None:
			return
		Info("\nIdentity query: %s" % query)

		# try get a entry for the match query
		# retrieve only attributes to be changed from "to update template"
		# (this is mandatory but current attributes will be removed)
		entry = self.conn.getSingleResult(query, self.update_template.keys())
		if not entry:
			Info("No entry found for query: %s" % query)
			return

		# set variables
		dn = entry.keys()[0]
		old_attributes = entry.values()[0]

		# process "to update template"
		new_attributes = self.update_template.copy()
		for key, value in new_attributes.items():
			# attributes to be removed from LDAP
			if value is None:
				del new_attributes[key]
				continue
		
			# process binary attributes
			if key.split(";")[0] in self.binary_attrs:
				value = data[self.__get_template_id(value, len(data))]
				if value:
					new_attributes[key] = [value]
				else:
					del new_attributes[key]
				continue

			# process string attributes
			new_attributes[key] = Strings.replace_from_array(new_attributes.get(key), data, SyncBC.get_acquire_connection_encoding(self.sync_section))
			if new_attributes[key].find("%") != -1:
				# keep old value or don't add to LDAP
				if old_attributes.has_key(key):
					new_attributes[key] = old_attributes[key]
				else:
					del new_attributes[key]
			else:
				new_attributes[key] = [new_attributes[key]]

		Info("DN for update: %s" % dn)
		Debug("Current attributes: %s" % old_attributes)
		Debug("Rules for update:   %s" % new_attributes)
		self.conn.modify(dn, old_attributes, new_attributes)
Пример #4
0
	def sync(self, data):
		return
		content = data[self.field_content]
		
		data[self.field_content] = ""
		data[0] = "%s" % data[0]
		print(data)

		#return

		# make the path from "to path template"
		path = Strings.replace_from_array(self.path_template, data)
		print("PATH: " + path)

		FileDAO.makedirs(path)
		FileDAO.writeToFile(path, content)
Пример #5
0
	def __init__(self, data, args=()):
		"""
		Receive the data to be converted and parameters.
		"""
		self.value = data

		if not data:
			return

		try:
			s_from = args[0]
			s_to = args[1]
			self.value = Strings.replace_string(data, s_from, s_to)
		except IndexError:
			print("Error: StringReplace takes exactly 2 arguments (%s given): %s" % (len(args), args) )
		except Exception, e:
			print(e)
Пример #6
0
	def get_match_query(sync_section, data):
		query = Strings.replace_from_array(SyncBC.get_match_template(sync_section), data, SyncBC.get_acquire_connection_encoding(sync_section))
		if query.find("%") != -1:
			print ("WARN: can not build a query to find a id for: %s" % data)
			return None
		return query