def Main(argv): currentDir = os.path.dirname(os.path.abspath(__file__)) os.chdir(currentDir) config = None with open('config.json') as configJson: config = json.load(configJson) rootDir = os.path.abspath('..') for htmlFileName in ['index.html', 'embed.html', 'embed_selfhost.html']: htmlFilePath = os.path.join(rootDir, 'website', htmlFileName) replacer = Tools.TokenReplacer(htmlFilePath, True) libFiles = Tools.CreateFileList(config['lib_files'], 'libs/', '../libs/') importerFiles = Tools.CreateFileList(config['importer_files'], 'source/', '../source/') websiteFiles = Tools.CreateFileList(config['website_files'], 'website/', '') replacer.ReplaceTokenFileLinks('<!-- libs start -->', '<!-- libs end -->', libFiles, None) replacer.ReplaceTokenFileLinks('<!-- importer start -->', '<!-- importer end -->', importerFiles, None) replacer.ReplaceTokenFileLinks('<!-- website start -->', '<!-- website end -->', websiteFiles, None) replacer.WriteToFile(htmlFilePath) return 0
def CreateDestinationDir(config, rootDir, websiteDir, version, testBuild): if not os.path.exists(websiteDir): os.makedirs(websiteDir) webSourcesDir = os.path.join(websiteDir, 'o3dv') if not os.path.exists(webSourcesDir): os.makedirs(webSourcesDir) shutil.copy2(os.path.join(rootDir, 'website', 'index.html'), websiteDir) shutil.copy2(os.path.join(rootDir, 'website', 'embed.html'), websiteDir) shutil.copy2(os.path.join(rootDir, 'website', 'robots.txt'), websiteDir) shutil.copy2(os.path.join(rootDir, 'website', 'o3dv', 'website.css'), os.path.join(webSourcesDir, 'o3dv.website.css')) shutil.copytree(os.path.join(rootDir, 'libs'), os.path.join(websiteDir, 'libs')) shutil.copytree(os.path.join(rootDir, 'website', 'assets'), os.path.join(websiteDir, 'assets')) shutil.copytree(os.path.join(rootDir, 'website', 'info'), os.path.join(websiteDir, 'info')) libFiles = config['lib_files'] importerFiles = ['o3dv/o3dv.min.js'] websiteFiles = ['o3dv/o3dv.website.css', 'o3dv/o3dv.website.min.js'] htmlFileNames = [ 'index.html', 'embed.html', os.path.join('info', 'index.html'), os.path.join('info', 'cookies.html') ] for htmlFileName in htmlFileNames: htmlFilePath = os.path.join(websiteDir, htmlFileName) replacer = Tools.TokenReplacer(htmlFilePath, False) replacer.ReplaceTokenFileLinks('<!-- libs start -->', '<!-- libs end -->', libFiles, None) replacer.ReplaceTokenFileLinks('<!-- importer start -->', '<!-- importer end -->', importerFiles, version) replacer.ReplaceTokenFileLinks('<!-- website start -->', '<!-- website end -->', websiteFiles, version) metaFile = os.path.join(rootDir, 'tools', 'website_meta_data.txt') if os.path.exists(metaFile): metaContent = Tools.GetFileContent(metaFile) replacer.ReplaceTokenContent('<!-- meta start -->', '<!-- meta end -->', metaContent) analyticsFile = os.path.join(rootDir, 'tools', 'website_analytics_data.txt') if os.path.exists(analyticsFile) and not testBuild: analyticsContent = Tools.GetFileContent(analyticsFile) replacer.ReplaceTokenContent('<!-- analytics start -->', '<!-- analytics end -->', analyticsContent) scriptFile = os.path.join(rootDir, 'tools', 'website_script_data.txt') if os.path.exists(scriptFile): scriptContent = Tools.GetFileContent(scriptFile) replacer.ReplaceTokenContent('<!-- script start -->', '<!-- script end -->', scriptContent) replacer.WriteToFile(htmlFilePath)