Esempio n. 1
0
def get_info(fname, key):
	"""
		get info from version or re-build
	"""
	from build.version import VersionControl

	vc = VersionControl()

	# from versions (same static)
	
	if vc.exists(fname):
		content = vc.get_file(fname)['content']
	else:
		content = globals().get('get_content_'+key)()
		import json
		content = json.dumps(content)

		# add in vcs
		vc.add(fname=fname, content=content)
		vc.commit()
	
	vc.close()
	
	webnotes.response['content'] = content
	return
Esempio n. 2
0
def clear_info(info_type=None):
	"""
		clear startup info and force a new version
		
		parameter: info_type = 'user' or 'common' or 'all'
	"""
	if not info_type:
		info_type = webnotes.form_dict.get('info_type')
		
	from build.version import VersionControl
	vc = VersionControl()

	flist = []

	if info_type=='common':
		flist = ['index.cgi?cmd=webnotes.startup.common_info']
	elif info_type=='user':
		flist = [f[0] for f in vc.repo.sql("""select fname from files where fname like ?""",\
		 	('index.cgi?cmd=webnotes.startup.user_info%',))]
	elif info_type=='all':
		flist = [f[0] for f in vc.repo.sql("""select fname from files where fname like ?""",\
		 	('index.cgi?cmd=webnotes.startup%',))]	
	else:
		webnotes.msgprint("info_type not found: %s" % info_type)
	
	for f in flist:
		print 'clearing %s' % f
		vc.remove(f)
		
	vc.commit()
	vc.close()
Esempio n. 3
0
	def build(self):
		"""
			Build all js files, index.html and template.html
		"""
		from build.version import VersionControl
		
		self.vc = VersionControl()
		self.vc.add_all()
		
		# index, template if framework is dirty
		if self.vc.repo.uncommitted():
			self.bundle.bundle(self.vc)
			self.render_templates()

			# again add all bundles
			self.vc.add_all()
			self.vc.repo.commit()
		
		self.vc.close()
Esempio n. 4
0
class Project:
	"""
		Build a project
		Make files::
			
			index.html
			assets/template.html
			assets/js/core.min.js
			assets/timestamps.json
	"""	
	def __init__(self):
		"""
			load libraries
		"""
		from build.bundle import Bundle
		from nav import Nav
		
		self.bundle = Bundle()
		self.nav = Nav()

	def boot(self):
		"""
			returns bootstrap js
		"""
		import json

		corejs = open('lib/js/core.min.js', 'r')
		v = int(self.vc.repo.get_value('last_version_number') or 0) + 1
		
		boot = ('window._version_number="%s"' % str(v)) + \
			'\n' + corejs.read()

		corejs.close()
		
		return boot

	def render_templates(self):
		"""
			Generate static files from templates
		"""

		# render templates
		import os
		from jinja2 import Environment, FileSystemLoader
		from build.markdown2_extn import Markdown2Extension

		env = Environment(loader=FileSystemLoader('templates'), extensions=[Markdown2Extension])

		# dynamic boot info
		env.globals['boot'] = self.boot()
		env.globals['nav'] = self.nav.html()
		page_info = self.nav.page_info()
		
		for wt in os.walk('templates'):
			for fname in wt[2]:
				if fname.split('.')[-1]=='html' and not fname.startswith('template'):
					fpath = os.path.relpath(os.path.join(wt[0], fname), 'templates')
					temp = env.get_template(fpath)
					
					env.globals.update(self.nav.page_info_template)
					env.globals.update(page_info.get(fpath, {}))
					
					# out file in parent folder of template
					f = open(fpath, 'w')
					f.write(temp.render())
					f.close()
					print "Rendered %s | %.2fkb" % (fpath, os.path.getsize(fpath) / 1024.0)
				

	def build(self):
		"""
			Build all js files, index.html and template.html
		"""
		from build.version import VersionControl
		
		self.vc = VersionControl()
		self.vc.add_all()
		
		# index, template if framework is dirty
		if self.vc.repo.uncommitted():
			self.bundle.bundle(self.vc)
			self.render_templates()

			# again add all bundles
			self.vc.add_all()
			self.vc.repo.commit()
		
		self.vc.close()
Esempio n. 5
0
def get_diff():
	v = webnotes.form_dict.get('version_number')
	from build.version import VersionControl
	webnotes.response['message'] = VersionControl().repo.diff(v)