コード例 #1
0
ファイル: build.py プロジェクト: bindscha/wnframework_old
def pack(target, sources, no_compress):
	from cStringIO import StringIO
	
	outtype, outtxt = target.split(".")[-1], ''
	jsm = JavascriptMinify()
		
	for f in sources:
		suffix = None
		if ':' in f: f, suffix = f.split(':')
		if not os.path.exists(f) or os.path.isdir(f): continue
		timestamps[f] = os.path.getmtime(f)
		try:
			with open(f, 'r') as sourcefile:			
				data = unicode(sourcefile.read(), 'utf-8', errors='ignore')
			
			if outtype=="js" and (not no_compress) and suffix!="concat" and (".min." not in f):
				tmpin, tmpout = StringIO(data.encode('utf-8')), StringIO()
				jsm.minify(tmpin, tmpout)
				outtxt += unicode(tmpout.getvalue() or '', 'utf-8').strip('\n') + ';'
			else:
				outtxt += ('\n/*\n *\t%s\n */' % f)
				outtxt += '\n' + data + '\n'
				
		except Exception, e:
			print "--Error in:" + f + "--"
			print webnotes.get_traceback()
コード例 #2
0
    def concat(self, filelist, outfile=None):
        """
			Concat css and js files into a bundle
		"""
        from cStringIO import StringIO

        out_type = outfile and outfile.split('.')[-1] or 'js'

        outtxt = ''
        for f in filelist:
            suffix = None
            if ':' in f:
                f, suffix = f.split(':')

            if not os.path.exists(f) or os.path.isdir(f):
                continue

            self.timestamps[f] = os.path.getmtime(f)

            # get datas
            with open(f, 'r') as infile:
                # get file type
                ftype = f.split('.')[-1]

                data = unicode(infile.read(), 'utf-8')

            outtxt += ('\n/*\n *\t%s\n */' % f)

            # append
            if suffix == 'concat' or out_type != 'js' or self.no_compress or (
                    '.min.' in f):
                outtxt += '\n' + data + '\n'
            else:
                jsm = JavascriptMinify()
                tmpin = StringIO(data.encode('utf-8'))
                tmpout = StringIO()
                jsm.minify(tmpin, tmpout)
                tmpmin = unicode(tmpout.getvalue() or '', 'utf-8')
                tmpmin.strip('\n')
                outtxt += tmpmin

        with open(outfile, 'w') as f:
            f.write(outtxt.encode("utf-8"))

        print "Wrote %s - %sk" % (outfile,
                                  str(int(os.path.getsize(outfile) / 1024)))
コード例 #3
0
    def concat(self, filelist, outfile=None):
        """
			Concat css and js files into a bundle
		"""
        from cStringIO import StringIO

        out_type = outfile and outfile.split('.')[-1] or 'js'

        outtxt = ''
        for f in filelist:
            suffix = None
            if ':' in f:
                f, suffix = f.split(':')

            if not os.path.exists(f) or os.path.isdir(f):
                continue

            self.timestamps[f] = os.path.getmtime(f)

            # get datas
            try:
                with open(f, 'r') as infile:
                    # get file type
                    ftype = f.split('.')[-1]

                    data = unicode(infile.read(), 'utf-8', errors='ignore')

                outtxt += ('\n/*\n *\t%s\n */' % f)

                # append
                if suffix == 'concat' or out_type != 'js' or self.no_compress or (
                        '.min.' in f):
                    outtxt += '\n' + data + '\n'
                else:
                    jsm = JavascriptMinify()
                    tmpin = StringIO(data.encode('utf-8'))
                    tmpout = StringIO()

                    jsm.minify(tmpin, tmpout)
                    tmpmin = unicode(tmpout.getvalue() or '', 'utf-8')
                    tmpmin.strip('\n')
                    outtxt += tmpmin
            except Exception, e:
                print "--Error in:" + f + "--"
                print webnotes.getTraceback()
コード例 #4
0
ファイル: build.py プロジェクト: rohitw1991/latestadbwnf
	def concat(self, filelist, outfile=None):	
		"""
			Concat css and js files into a bundle
		"""
		from cStringIO import StringIO
		
		out_type = outfile and outfile.split('.')[-1] or 'js'
		
		outtxt = ''
		for f in filelist:
			suffix = None
			if ':' in f:
				f, suffix = f.split(':')
			
			if not os.path.exists(f) or os.path.isdir(f):
				continue
			
			self.timestamps[f] = os.path.getmtime(f)
			
			# get datas
			try:
				with open(f, 'r') as infile:			
					# get file type
					ftype = f.split('.')[-1] 

					data = unicode(infile.read(), 'utf-8', errors='ignore')

				outtxt += ('\n/*\n *\t%s\n */' % f)
					
				# append
				if suffix=='concat' or out_type != 'js' or self.no_compress or ('.min.' in f):
					outtxt += '\n' + data + '\n'
				else:
					jsm = JavascriptMinify()
					tmpin = StringIO(data.encode('utf-8'))
					tmpout = StringIO()
					
					jsm.minify(tmpin, tmpout)
					tmpmin = unicode(tmpout.getvalue() or '', 'utf-8')
					tmpmin.strip('\n')
					outtxt += tmpmin
			except Exception, e:
				print "--Error in:" + f + "--"
				print webnotes.getTraceback()
コード例 #5
0
	def concat(self, filelist, outfile=None):	
		"""
			Concat css and js files into a bundle
		"""
		from cStringIO import StringIO
		
		out_type = outfile and outfile.split('.')[-1] or 'js'
		
		outtxt = ''
		for f in filelist:
			suffix = None
			if ':' in f:
				f, suffix = f.split(':')
			
			if not os.path.exists(f) or os.path.isdir(f):
				continue
			
			self.timestamps[f] = os.path.getmtime(f)
			
			# get datas
			with open(f, 'r') as infile:			
				# get file type
				ftype = f.split('.')[-1] 

				data = infile.read()

			outtxt += ('\n/*\n *\t%s\n */' % f)
					
			# append
			if suffix=='concat' or out_type != 'js' or self.no_compress or ('.min.' in f):
				outtxt += '\n' + data + '\n'
			else:
				jsm = JavascriptMinify()
				tmpin = StringIO(data)
				tmpout = StringIO()
				jsm.minify(tmpin, tmpout)
				tmpmin = tmpout.getvalue() or ''
				tmpmin.strip('\n')
				outtxt += tmpmin
						
		with open(outfile, 'w') as f:
			f.write(outtxt)
		
		print "Wrote %s - %sk" % (outfile, str(int(os.path.getsize(outfile)/1024)))