mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 11:20:09 +00:00 
			
		
		
		
	some refactoring on the python side of things...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									9f291331b0
								
							
						
					
					
						commit
						a10097daa1
					
				| @ -1,7 +1,7 @@ | |||||||
| #======================================================================= | #======================================================================= | ||||||
| 
 | 
 | ||||||
| __version__ = '''0.0.01''' | __version__ = '''0.0.01''' | ||||||
| __sub_version__ = '''20130410190410''' | __sub_version__ = '''20130521225013''' | ||||||
| __copyright__ = '''(c) Alex A. Naanou 2012''' | __copyright__ = '''(c) Alex A. Naanou 2012''' | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -15,6 +15,8 @@ import urllib2 | |||||||
| 
 | 
 | ||||||
| from pli.logictypes import OR | from pli.logictypes import OR | ||||||
| 
 | 
 | ||||||
|  | import gid | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| #----------------------------------------------------------------------- | #----------------------------------------------------------------------- | ||||||
| # XXX fanatically cleanup and normalise paths... | # XXX fanatically cleanup and normalise paths... | ||||||
| @ -33,6 +35,8 @@ from pli.logictypes import OR | |||||||
| #----------------------------------------------------------------------- | #----------------------------------------------------------------------- | ||||||
| 
 | 
 | ||||||
| config = { | config = { | ||||||
|  | 	'format-version': '2.0', | ||||||
|  | 
 | ||||||
| 	'cache-structure': { | 	'cache-structure': { | ||||||
| 		# XXX make these as close to standard as possible and keep | 		# XXX make these as close to standard as possible and keep | ||||||
| 		# 	  sane distances... | 		# 	  sane distances... | ||||||
| @ -42,7 +46,15 @@ config = { | |||||||
| 		'1080px': '.ImageGridCache/1080px/', | 		'1080px': '.ImageGridCache/1080px/', | ||||||
| 		'1920px': '.ImageGridCache/1920px/', | 		'1920px': '.ImageGridCache/1920px/', | ||||||
| 	}, | 	}, | ||||||
|  | 
 | ||||||
|  | 	# gen1 format... | ||||||
| 	'json': '.ImageGridCache/all.json', | 	'json': '.ImageGridCache/all.json', | ||||||
|  | 
 | ||||||
|  | 	# gen3 format... | ||||||
|  | 	'images': '.ImageGridCache/images.json', | ||||||
|  | 	'data': '.ImageGridCache/data.json', | ||||||
|  | 	'marked': '.ImageGridCache/marked.json', | ||||||
|  | 
 | ||||||
| 	'error': '.ImageGridCache/error.log', | 	'error': '.ImageGridCache/error.log', | ||||||
| 	'sizes': { | 	'sizes': { | ||||||
| 		'150px': 150, | 		'150px': 150, | ||||||
| @ -106,7 +118,6 @@ def log_err(path, e, source_file, target_file): | |||||||
| def get_image_guid(path, force=False): | def get_image_guid(path, force=False): | ||||||
| 	''' | 	''' | ||||||
| 	''' | 	''' | ||||||
| 	##!!! check cache and date... |  | ||||||
| 	im = Image.open(path) | 	im = Image.open(path) | ||||||
| 	return sha.sha(im.tostring()).hexdigest() | 	return sha.sha(im.tostring()).hexdigest() | ||||||
| ##	return sha.sha(open(path, 'r').read()) | ##	return sha.sha(open(path, 'r').read()) | ||||||
| @ -182,7 +193,7 @@ def build_index(path, images=None, count=None): | |||||||
| 
 | 
 | ||||||
| # XXX this will not overwrite existing files... | # XXX this will not overwrite existing files... | ||||||
| # XXX make this destingwish absolute and relative paths... | # XXX make this destingwish absolute and relative paths... | ||||||
| def make_cache_images(path, config=config): | def make_cache_images(path, images, config=config): | ||||||
| 	''' | 	''' | ||||||
| 	''' | 	''' | ||||||
| 	dirs = config['cache-structure'] | 	dirs = config['cache-structure'] | ||||||
| @ -206,6 +217,7 @@ def make_cache_images(path, config=config): | |||||||
| 		} | 		} | ||||||
| 		img = Image.open(source_path, 'r') | 		img = Image.open(source_path, 'r') | ||||||
| 		try: | 		try: | ||||||
|  | 			##!!! use a real gid -- gid.image_gid(path, ...) | ||||||
| 			iid = sha.sha(img.tostring()).hexdigest() | 			iid = sha.sha(img.tostring()).hexdigest() | ||||||
| 		except IOError, e: | 		except IOError, e: | ||||||
| 			print 'x', | 			print 'x', | ||||||
| @ -261,7 +273,7 @@ def build_local_cache(path): | |||||||
| 
 | 
 | ||||||
| 	build_cache_dirs(path) | 	build_cache_dirs(path) | ||||||
| 
 | 
 | ||||||
| 	n = make_cache_images(path) | 	n = make_cache_images(path, images) | ||||||
| 
 | 
 | ||||||
| 	t1 = time.time() | 	t1 = time.time() | ||||||
| 
 | 
 | ||||||
							
								
								
									
										168
									
								
								buildcache2.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										168
									
								
								buildcache2.py
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,168 @@ | |||||||
|  | #======================================================================= | ||||||
|  | 
 | ||||||
|  | __version__ = '''0.0.01''' | ||||||
|  | __sub_version__ = '''20130521232425''' | ||||||
|  | __copyright__ = '''(c) Alex A. Naanou 2011''' | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | #----------------------------------------------------------------------- | ||||||
|  | 
 | ||||||
|  | import os | ||||||
|  | import Image | ||||||
|  | import json | ||||||
|  | import sha | ||||||
|  | import urllib2 | ||||||
|  | 
 | ||||||
|  | from pli.logictypes import OR | ||||||
|  | 
 | ||||||
|  | import gid | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | #----------------------------------------------------------------------- | ||||||
|  | 
 | ||||||
|  | config = { | ||||||
|  | 	'absolute-path': False, | ||||||
|  | 
 | ||||||
|  | 	'cache-image-name': '%(guid)s - %(name)s', | ||||||
|  | 
 | ||||||
|  | 	'images': '.ImageGridCache/images.json', | ||||||
|  | 	'data': '.ImageGridCache/data.json', | ||||||
|  | 	'marked': '.ImageGridCache/marked.json', | ||||||
|  | 
 | ||||||
|  | 	'error': '.ImageGridCache/error.log', | ||||||
|  | 
 | ||||||
|  | 	'cache-structure': { | ||||||
|  | 		# make these as close to standard as possible and keep sane  | ||||||
|  | 		# distances... | ||||||
|  | 		'150px': '.ImageGridCache/150px/', | ||||||
|  | 		'350px': '.ImageGridCache/350px/', | ||||||
|  | 		'900px': '.ImageGridCache/900px/', | ||||||
|  | 		'1080px': '.ImageGridCache/1080px/', | ||||||
|  | 		'1920px': '.ImageGridCache/1920px/', | ||||||
|  | 	}, | ||||||
|  | 	'sizes': { | ||||||
|  | 		'150px': 150, | ||||||
|  | 		'350px': 350, | ||||||
|  | 		'900px': 900, | ||||||
|  | 		'1080px': 1080, | ||||||
|  | 		'1920px': 1920, | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | data = { | ||||||
|  | 	'version': '2.0', | ||||||
|  | 	'current': None, | ||||||
|  | 	'ribbons': [], | ||||||
|  | 	'order': [], | ||||||
|  | 	'image_file': 'images.json', | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | IMAGE_EXT = OR(*( | ||||||
|  | 		'.jpg', '.jpeg', '.JPG', '.JPEG', | ||||||
|  | )) | ||||||
|  | 
 | ||||||
|  | ERR_LOG = '''\ | ||||||
|  | ERROR: %(error)s | ||||||
|  | SOURCE: %(source-file)s | ||||||
|  | TARGET: %(target-file)s | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | ''' | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | #----------------------------------------------------------------------- | ||||||
|  | 
 | ||||||
|  | def pathjoin(*p): | ||||||
|  | 	''' | ||||||
|  | 	''' | ||||||
|  | 	return ('/'.join(p)).replace('//', '/') | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def log_err(path, e, source_file, target_file): | ||||||
|  | 	''' | ||||||
|  | 	''' | ||||||
|  | 	err_file = pathjoin(path, config['error']) | ||||||
|  | 	if not os.path.exists(err_file): | ||||||
|  | 		err = open(err_file, 'w') | ||||||
|  | 	else: | ||||||
|  | 		err = open(err_file, 'a') | ||||||
|  | 	with err: | ||||||
|  | 		err.write(ERR_LOG % { | ||||||
|  | 				'source-file': source_file, | ||||||
|  | 				'target-file': target_file, | ||||||
|  | 				'error': e, | ||||||
|  | 		}) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def hash_gid(img, force=False): | ||||||
|  | 	''' | ||||||
|  | 	Generate gid based on preview file content. | ||||||
|  | 
 | ||||||
|  | 	NOTE: img can be either a path or an Image. | ||||||
|  | 	''' | ||||||
|  | 	if type(img) in (str, unicode): | ||||||
|  | 		img = Image.open(img) | ||||||
|  | 	return sha.sha(img.tostring()).hexdigest() | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def build_cache_dirs(path, config=config): | ||||||
|  | 	''' | ||||||
|  | 	Build cache directory tree. | ||||||
|  | 	''' | ||||||
|  | 	dirs = config['cache-structure'] | ||||||
|  | 	for _, k in dirs.items(): | ||||||
|  | 		p = pathjoin(path, k) | ||||||
|  | 		if not os.path.exists(p): | ||||||
|  | 			os.makedirs(p) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def build_images(path, config=config, gid_generator=hash_gid): | ||||||
|  | 	''' | ||||||
|  | 	Build image structures update images.json in cache. | ||||||
|  | 	''' | ||||||
|  | 	absolute_path = config['absolute-path'] | ||||||
|  | 
 | ||||||
|  | 	for name in os.listdir(path): | ||||||
|  | 		iid, ext = os.path.splitext(name) | ||||||
|  | 
 | ||||||
|  | 		if ext != IMAGE_EXT: | ||||||
|  | 			continue | ||||||
|  | 
 | ||||||
|  | 		source_path = pathjoin(path, name) | ||||||
|  | 
 | ||||||
|  | 		img =  { | ||||||
|  | 			'id': gid_generator(source_path), | ||||||
|  | 			'type': 'image', | ||||||
|  | 			'state': 'single', | ||||||
|  | 			'path': None, | ||||||
|  | 			'ctime': os.path.getctime(source_path), | ||||||
|  | 			'preview': {}, | ||||||
|  | 		} | ||||||
|  | 		if absolute_path == True: | ||||||
|  | 			img['path'] = 'file:///' + urllib2.quote(pathjoin(path, name), safe='/:') | ||||||
|  | 		else: | ||||||
|  | 			img['path'] = urllib2.quote(name) | ||||||
|  | 
 | ||||||
|  | 		yield img | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def build_previews(image): | ||||||
|  | 	''' | ||||||
|  | 	''' | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | #----------------------------------------------------------------------- | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | #----------------------------------------------------------------------- | ||||||
|  | if __name__ == '__main__': | ||||||
|  | 	pass | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | #======================================================================= | ||||||
|  | #                                            vim:set ts=4 sw=4 nowrap : | ||||||
							
								
								
									
										15
									
								
								ui/data.js
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								ui/data.js
									
									
									
									
									
								
							| @ -724,6 +724,21 @@ function openImage(){ | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | function loadDir(path){ | ||||||
|  | 	// CEF
 | ||||||
|  | 	if(window.CEF_loadDir != null){ | ||||||
|  | 		var dir = CEF_loadDir(path) | ||||||
|  | 		IMAGES = dir.images | ||||||
|  | 		DATA = dir.data | ||||||
|  | 		MARKED = dir.marked | ||||||
|  | 		loadData() | ||||||
|  | 
 | ||||||
|  | 	// PhoneGap
 | ||||||
|  | 	} else if(false) { | ||||||
|  | 		// XXX
 | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| /********************************************************************** | /********************************************************************** | ||||||
| * Image caching... | * Image caching... | ||||||
|  | |||||||
| @ -568,6 +568,16 @@ String.prototype.capitalize = function(){ | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | // XXX not sure if this has to be a utility or a method...
 | ||||||
|  | Object.get = function(obj, name, dfl){ | ||||||
|  | 	var val = obj[name] | ||||||
|  | 	if(val === undefined && dfl != null){ | ||||||
|  | 		return dfl | ||||||
|  | 	} | ||||||
|  | 	return val | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| var getAnimationFrame = (window.requestAnimationFrame | var getAnimationFrame = (window.requestAnimationFrame | ||||||
| 		|| window.webkitRequestAnimationFrame  | 		|| window.webkitRequestAnimationFrame  | ||||||
| 		|| window.mozRequestAnimationFrame | 		|| window.mozRequestAnimationFrame | ||||||
| @ -577,6 +587,7 @@ var getAnimationFrame = (window.requestAnimationFrame | |||||||
| 			setTimeout(callback, 1000/60)  | 			setTimeout(callback, 1000/60)  | ||||||
| 		}) | 		}) | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| var cancelAnimationFrame = (window.cancelRequestAnimationFrame  | var cancelAnimationFrame = (window.cancelRequestAnimationFrame  | ||||||
| 		|| window.webkitCancelAnimationFrame  | 		|| window.webkitCancelAnimationFrame  | ||||||
| 		|| window.webkitCancelRequestAnimationFrame  | 		|| window.webkitCancelRequestAnimationFrame  | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user