"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "create_shadertext.py" between
pymol-v2.1.0.tar.bz2 and pymol-open-source-2.2.0.tar.gz

About: PyMOL is a Python-enhanced molecular graphics tool. It excels at 3D visualization of proteins, small molecules, density, surfaces, and trajectories. It also includes molecular editing, ray tracing, and movies. Open Source version.

create_shadertext.py  (pymol-v2.1.0.tar.bz2):create_shadertext.py  (pymol-open-source-2.2.0)
from __future__ import print_function from __future__ import print_function
try: try:
import cStringIO import cStringIO
except ImportError: except ImportError:
import io as cStringIO import io as cStringIO
import sys, os import sys, os
import time import time
import re import re
import glob
from collections import defaultdict
from os.path import dirname from os.path import dirname
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from distutils import dir_util from distutils import dir_util
def create_all(generated_dir, pymoldir="."): def create_all(generated_dir, pymoldir="."):
''' '''
Generate various stuff Generate various stuff
''' '''
create_shadertext( create_shadertext(
os.path.join(pymoldir, "data", "shaders"), os.path.join(pymoldir, "data", "shaders"),
generated_dir, generated_dir,
os.path.join(generated_dir, "ShaderText.h"), os.path.join(generated_dir, "ShaderText.h"),
os.path.join(generated_dir, "ShaderText.c")) os.path.join(generated_dir, "ShaderText.cpp"))
create_buildinfo(generated_dir, pymoldir) create_buildinfo(generated_dir, pymoldir)
class openw(object): class openw(object):
""" """
File-like object for writing files. File is actually only File-like object for writing files. File is actually only
written if the content changed. written if the content changed.
""" """
def __init__(self, filename): def __init__(self, filename):
if os.path.exists(filename): if os.path.exists(filename):
self.out = cStringIO.StringIO() self.out = cStringIO.StringIO()
skipping to change at line 59 skipping to change at line 60
self.out.close() self.out.close()
def __getattr__(self, name): def __getattr__(self, name):
return getattr(self.out, name) return getattr(self.out, name)
def __enter__(self): def __enter__(self):
return self return self
def __exit__(self, *a, **k): def __exit__(self, *a, **k):
self.close() self.close()
def __del__(self): def __del__(self):
self.close() self.close()
def create_shadertext(shaderdir, shaderdir2, inputfile, outputheader, outputfile ): def create_shadertext(shaderdir, shaderdir2, outputheader, outputfile):
outputheader = openw(outputheader) outputheader = openw(outputheader)
outputfile = openw(outputfile) outputfile = openw(outputfile)
with open(os.path.join(shaderdir, inputfile)) as f: include_deps = defaultdict(set)
for l in f: ifdef_deps = defaultdict(set)
lspl = l.split()
if len(lspl)==0: # get all *.gs *.vs *.fs *.shared from the two input directories
continue shaderfiles = set()
if lspl[0] == "read": for sdir in [shaderdir, shaderdir2]:
if len(lspl)!=3: for ext in ['gs', 'vs', 'fs', 'shared']:
outputfile.write("/* WARNING: read doesn't have variable nam shaderfiles.update(map(os.path.basename,
e and file name argument lspl=%s */\n" % lspl) glob.glob(os.path.join(sdir, '*.' + ext))))
varname = lspl[1] varname = '_shader_cache_raw'
filename = lspl[2] outputheader.write('extern const char * %s[];\n' % varname)
outputheader.write("extern const char* %s;\n" % varname) outputfile.write('const char * %s[] = {\n' % varname)
outputfile.write("const char* %s =\n" % varname)
sd = shaderdir for filename in shaderfiles:
if not os.path.exists(os.path.join(shaderdir, filename)): shaderfile = os.path.join(shaderdir, filename)
sd = shaderdir2 if not os.path.exists(shaderfile):
with open(os.path.join(sd, filename)) as f2: shaderfile = os.path.join(shaderdir2, filename)
for l2 in f2:
st = l2.strip("\n") with open(shaderfile, 'rU') as handle:
if len(st)>0: contents = handle.read()
#if st[0] != '#':
outputfile.write("\"%s\\n\"\n" % st.replace('"', if True:
r'\"')) outputfile.write('"%s", ""\n' % (filename))
outputfile.write(";\n") # end of variable definition
else: for line in contents.splitlines():
outputheader.write("%s\n" % l.strip()) line = line.strip()
outputfile.write("%s\n" % l.strip())
# skip blank lines and obvious comments
if not line or line.startswith('//') and not '*/' in line:
# write line, quoted, escaped and with a line feed
outputfile.write("\"%s\\n\"\n" % line.replace('\\', '\\\\').repl
ace('"', r'\"'))
# include and ifdef dependencies
if line.startswith('#include'):
elif line.startswith('#ifdef') or line.startswith('#ifndef'):
# include and ifdef dependencies
for varname, deps in [
('_include_deps', include_deps),
('_ifdef_deps', ifdef_deps)]:
outputheader.write('extern const char * %s[];\n' % varname)
outputfile.write('const char * %s[] = {\n' % varname)
for name, itemdeps in deps.items():
outputfile.write('"%s", "%s", 0,\n' % (name, '", "'.join(sorted(item
outputheader.close() outputheader.close()
outputfile.close() outputfile.close()
def create_buildinfo(outputdir, pymoldir='.'): def create_buildinfo(outputdir, pymoldir='.'):
try: try:
sha = Popen(['git', 'rev-parse', 'HEAD'], cwd=pymoldir, sha = Popen(['git', 'rev-parse', 'HEAD'], cwd=pymoldir,
stdout=PIPE).stdout.read().strip().decode() stdout=PIPE).stdout.read().strip().decode()
except OSError: except OSError:
 End of changes. 5 change blocks. 
31 lines changed or deleted 60 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)