some cleanups on build.py - in preperation for not updating date/time in file versions when no other changes occur

This commit is contained in:
Jon Atkins 2013-11-13 02:24:40 +00:00
parent 91c561b8c5
commit 694325a39b

View File

@ -182,10 +182,16 @@ def doReplacements(script,updateUrl,downloadUrl,pluginName=None):
return script return script
def saveScriptAndMeta(script,fn,metafn): def saveScriptAndMeta(script,ourDir,filename,oldDir=None):
# TODO: if oldDir is set, compare files. if only data/time-based version strings are different
# copy from there instead of saving a new file
fn = os.path.join(outDir,filename)
with io.open(fn, 'w', encoding='utf8') as f: with io.open(fn, 'w', encoding='utf8') as f:
f.write(script) f.write(script)
metafn = fn.replace('.user.js', '.meta.js')
if metafn != fn:
with io.open(metafn, 'w', encoding='utf8') as f: with io.open(metafn, 'w', encoding='utf8') as f:
meta = extractUserScriptMeta(script) meta = extractUserScriptMeta(script)
f.write(meta) f.write(meta)
@ -196,9 +202,14 @@ outDir = os.path.join('build', buildName)
# create the build output # create the build output
# first, delete any existing build # first, delete any existing build - but keep it in a temporary folder for now
oldDir = None
if os.path.exists(outDir): if os.path.exists(outDir):
shutil.rmtree(outDir) oldDir = outDir+'~';
if os.path.exists(oldDir):
shutil.rmtree(oldDir)
os.rename(outDir, oldDir)
# copy the 'dist' folder, if it exists # copy the 'dist' folder, if it exists
if os.path.exists('dist'): if os.path.exists('dist'):
@ -222,7 +233,7 @@ downloadUrl = distUrlBase and distUrlBase + '/total-conversion-build.user.js' or
updateUrl = distUrlBase and distUrlBase + '/total-conversion-build.meta.js' or 'none' updateUrl = distUrlBase and distUrlBase + '/total-conversion-build.meta.js' or 'none'
main = doReplacements(main,downloadUrl=downloadUrl,updateUrl=updateUrl) main = doReplacements(main,downloadUrl=downloadUrl,updateUrl=updateUrl)
saveScriptAndMeta(main, os.path.join(outDir,'total-conversion-build.user.js'), os.path.join(outDir,'total-conversion-build.meta.js')) saveScriptAndMeta(main, outDir, 'total-conversion-build.user.js', oldDir)
# for each plugin, load, parse, and save output # for each plugin, load, parse, and save output
@ -236,8 +247,7 @@ for fn in glob.glob("plugins/*.user.js"):
pluginName = os.path.splitext(os.path.splitext(os.path.basename(fn))[0])[0] pluginName = os.path.splitext(os.path.splitext(os.path.basename(fn))[0])[0]
script = doReplacements(script, downloadUrl=downloadUrl, updateUrl=updateUrl, pluginName=pluginName) script = doReplacements(script, downloadUrl=downloadUrl, updateUrl=updateUrl, pluginName=pluginName)
metafn = fn.replace('.user.js', '.meta.js') saveScriptAndMeta(script, outDir, fn, oldDir)
saveScriptAndMeta(script, os.path.join(outDir,fn), os.path.join(outDir,metafn))
# if we're building mobile too # if we're building mobile too
if buildMobile: if buildMobile:
@ -251,8 +261,7 @@ if buildMobile:
updateUrl = distUrlBase and downloadUrl.replace('.user.js', '.meta.js') or 'none' updateUrl = distUrlBase and downloadUrl.replace('.user.js', '.meta.js') or 'none'
script = doReplacements(script, downloadUrl=downloadUrl, updateUrl=updateUrl, pluginName='user-location') script = doReplacements(script, downloadUrl=downloadUrl, updateUrl=updateUrl, pluginName='user-location')
metafn = fn.replace('.user.js', '.meta.js') saveScriptAndMeta(script, outDir, fn)
saveScriptAndMeta(script, os.path.join(outDir,fn), os.path.join(outDir,metafn))
# copy the IITC script into the mobile folder. create the folder if needed # copy the IITC script into the mobile folder. create the folder if needed
try: try: