예제 #1
0
파일: decorator.py 프로젝트: flynx/pli
def bind(event, HOOK_DEBUG=False):
	'''
	this will bind the decorated object to event.

	NOTE: multiple binds are allowed.
	'''
	return curry(evt.bind, event, HOOK_DEBUG=HOOK_DEBUG)
예제 #2
0
파일: misc.py 프로젝트: flynx/pli
	def __getattr__(self, name):
		'''
		'''
		# deligate the call to the original store object
		# constructors...
		##!! revise !!##
		cls = store.StaticStoreClient.__getattr__(self, name)
		if issubclass(cls, OwnedStoredObjectWithAttrs):
			return curry(cls, owner=self.__owner__)	
		return cls
예제 #3
0
파일: constructor.py 프로젝트: flynx/pli
def likevalue(obj, method_writable=False):
    """
	this will create an interface property dict that describes the argument.

	NOTE: this is usefull as it will create a predicate that will check 
	      function/method signature.
	"""
    res = {}
    # type or predicate...
    if callable(obj):
        # function signature...
        res["predicate"] = func.curry(callablescompatible, obj, method_aware=True)
        if not method_writable:
            res["writable"] = False
    else:
        res["type"] = type(obj)
        # doc...
    if hasattr(obj, "__doc__"):
        res["doc"] = obj.__doc__
    return res
예제 #4
0
파일: xmpgen.py 프로젝트: flynx/XMPGen
def run():
	'''
	prepare configuration data and run.
	'''
	# setup config data...
	config, runtime_options = load_commandline(load_config_file(DEFAULT_CFG))

	# cache some names...
	output = config['OUTPUT_DIR']
	root = config['ROOT_DIR']
	input = config['INPUT_DIR']
	traverse_dir = config['TRAVERSE_DIR']
	threshold = config['THRESHOLD']
	raw_ext = config['RAW_EXTENSION']
	rate_top_level = config['RATE_TOP_LEVEL']
	search_input = config['SEARCH_INPUT']
	search_output = config['SEARCH_OUTPUT']
	verbosity = config['VERBOSITY']
	skip = config['SKIP']
	use_labels = config['USE_LABELS']
	overflow_strategy = config['OVERFLOW_STRATEGY']
	in_ext = OR(*config['INPUT_EXT'])

	# runtime options...
	dry_run = runtime_options.dry_run

	ratings = (config['LABELS'] if use_labels else []) + config['RATINGS']

	# prepare to count created files...
	files_written = [0]
	def action_count(*p, **n):
		files_written[0] += 1
		return True
	
	# do the actaual dance...
	res = generate(
		rate(
			index(
				# chose weather we need to skip the last element...
					collect(os.path.join(root, input), traverse_dir, rate_top_level, in_ext) 
						if not search_input 
						# locate correct preview dirs...
						else (reduce(list.__add__, l) 
									for l 
									in izip_longest(
											fillvalue=[], 
											*(collect(d, traverse_dir, rate_top_level, in_ext) 
										for d 
										in getdirpaths(
												root, 
												input, 
												builddircache(root, input)))))), 
			ratings=ratings,
			threshold=threshold,
			overflow_strategy=overflow_strategy), 
		output, 
		# find a location for each output file...
		##!!! we do not need to do this if collect returned no results...
		getpath=(curry(getfilepath, cache=buildfilecache(output, raw_ext, skip_dirs=skip)) 
					if search_output 
					# just write to ROOT...
					else join),
		# actions to perform per XMP file...
		actions=(
			action_logger,
			action_break if dry_run else action_dummy,
			action_filewriter,
			action_count,
		),
		template=config['XMP_TEMPLATE'],
		skip_not_found=config['SKIP_UNKNOWN_DESTINATIONS'],
		config=config)

	if verbosity >= 0:
		if verbosity == 1:
			print
		print 'Written %s files.' % files_written[0]

	return res
예제 #5
0
파일: aspect.py 프로젝트: flynx/pli
	def __get__(self, obj, type=None):
		'''
		'''
		return curry(self.run, obj)
예제 #6
0
파일: pli_functional.py 프로젝트: flynx/pli
# here we will basicly create a list of callables and call each element
# in a function one-liner :)
#
#----------------------------------------------------------------func---
# the function we are going to call...
def func(*arg):
	print ' '.join(arg)


#-----------------------------------------------------------------------
# generate the list of functions...
number_of_funcs = 6
# this can be done quite a bit simpler in pythonic syntax.... (but...
# I could not help myself :)))) )
list_of_funcs = map(
					curry(rcurry, func), 
					map(
						lambda i: '#' + str(i), 
						range(number_of_funcs)
				))

# if you had not yet guessed what the above "line" does here is the
# pythonic version:
##list_of_funcs = [ rcurry(func, '#' + str(i)) for i in range(number_of_funcs) ]
# and this will add the word pythonic to the beginning of the line :)
##list_of_funcs = [ curry(rcurry(func, '#' + str(i)), 'pythonic:') for i in range(number_of_funcs) ]
# though I must admit that this does not look much simpler...


#-----------------------------------------------------------------------
# The Loop:
예제 #7
0
파일: gid.py 프로젝트: flynx/pli
		res = ''
		for i, c in enumerate(s):
			res += chars[(ord(c)+i)%len(chars)]
		return pattern % res
	return getgid(gids, func.rcurry(fmt_str, chars))



#-----------------------------------------------------------------------
if __name__ == '__main__':
	def gidtuple2str(gid, gids):
		return "id_%s" % gid.get_hex()

	OIDS = set()

	ngetgid = func.curry(getgid, OIDS, gidtuple2str)

	print ngetgid()
	print ngetgid()
	print ngetgid()
	print ngetgid()
	print ngetgid()
	print ngetgid()

	print getstrgid(OIDS)
	print getstrgid(OIDS)
	print getstrgid(OIDS)
	print getstrgid(OIDS)
	print getstrgid(OIDS)
	print getstrgid(OIDS)