<commit_before>#! /usr/bin/env python

import os
import sys
import shutil
import platform
import tempfile
import zipfile
from optparse import OptionParser
import subprocess

try:
    from hashlib import sha1 as sha
except ImportError:
    from sha import sha

usage = """
This command creates a graphical installer for the
Panda3D plugin and runtime environment.

  %prog [opts]"""

parser = OptionParser(usage = usage)
parser.add_option('-n', '--short', dest = 'short_name',
                  help = 'The product short name',
                  default = 'Panda3D')
parser.add_option('-N', '--long', dest = 'long_name',
                  help = 'The product long name',
                  default = 'Panda3D Game Engine')
parser.add_option('-v', '--version', dest = 'version',
                  help = 'The product version',
                  default = None)
parser.add_option('-p', '--publisher', dest = 'publisher',
                  help = 'The name of the publisher',
                  default = 'Carnegie Mellon Entertainment Technology Center')
parser.add_option('', '--install', dest = 'install_dir',
                  help = "The install directory on the user's machine (Windows only)",
                  default = '$PROGRAMFILES\\Panda3D')
parser.add_option('-l', '--license', dest = 'license',
                  help = 'A file containing the license or EULA text',
                  default = None)
parser.add_option('-w', '--website', dest = 'website',
                  help = 'The product website',
                  default = 'http://www.panda3d.org')
parser.add_option('', '--start', dest = 'start',
                  help = 'Specify this option to add a start menu',
                  action = 'store_false', default = False)
parser.add_option('', '--welcome_image', dest = 'welcome_image',
                  help = 'The image to display on the installer, 170x312 BMP',
                  default = None)
parser.add_option('', '--install_icon', dest = 'install_icon',
                  help = 'The icon to give to the installer',
                  default = None)
parser.add_option('', '--nsis', dest = 'nsis',
                  help = 'The path to the makensis executable',
                  default = None)
parser.add_option('', '--spc', dest = 'spc',
                  help = 'Generate an ActiveX CAB file, then sign it with the indicated spc file (Windows only).  You must also specify --pvk.',
                  default = None)
parser.add_option('', '--pvk', dest = 'pvk',
                  help = 'Specifies the private key to be used in conjuction with --spc to sign a CAB file (Windows only).',
                  default = None)
parser.add_option('', '--mssdk', dest = 'mssdk',
                  help = 'The path to the MS Platform SDK directory (Windows only).  mssdk/bin should contain cabarc.exe and signcode.exe.',
                  default = None)
parser.add_option('-i', '--plugin_root', dest = 'plugin_root',
                  help = 'The root of a directory hierarchy in which the Firefox plugins for various platforms can be found, to build a Firefox xpi file.  This is normally the same as the staging directory populated by the -i parameter to ppackage.  This directory should contain a directory called "plugin", which contains in turn a number of directories named for the platform, by the Panda plugin convention, e.g. linux_i386, osx_ppc, and so on.  Each platform directory should contain a Firefox plugin, e.g. nppanda3d.so.')
parser.add_option('', '--host_url', dest = 'host_url',
                  help = "The URL at which plugin_root will be hosted.  This is used to construct the update URL for the xpi file.  This is required if you specify --plugin_root.")

(options, args) = parser.parse_args()

this_dir = os.path.split(sys.argv[0])[0]

assert options.version, "A version number must be supplied!"

# A mapping of Panda's platform strings to Firefox's equivalent
# strings.

# I'm leaving out the Linux platforms for now.  I think there is too
# much variance between distro's for this to be reliable; we'll make
# each Linux user install their distro-specific plugin instead of
# going through this mechanism.
FirefoxPlatformMap = {
    'win32' : 'WINNT_x86-msvc',
    'win64' : 'WINNT_x86_64-msvc',
#    'linux_i386' : 'Linux_x86-gcc3',
#    'linux_amd64' : 'Linux_x86_64-gcc3',
#    'linux_ppc' : 'Linux_ppc-gcc3',
    'osx_i386' : 'Darwin_x86-gcc3',
    'osx_amd64' : 'Darwin_x86_64-gcc3',
    'osx_ppc' : 'Darwin_ppc-gcc3',
    'freebsd_i386' : 'FreeBSD_x86-gcc3',
    'freebsd_amd64' : 'FreeBSD_x86_64-gcc3',
    }

##############################################################################
#
# This install.rdf file is used when building a Firefox XPI file.
#
##############################################################################

install_rdf = """<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
  <Description about="urn:mozilla:install-manifest">
    <em:id>%(package_id)s</em:id>
    <em:name>Panda3D Game Engine Plug-In</em:name>
    <em:description>Runs 3-D games and interactive applets</em:description>
    <em:version>%(version)s</em:version>
    <em:targetApplication>
      <Description>
        <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
        <em:minVersion>3.0</em:minVersion>
        <em:maxVersion>*</em:maxVersion>
      </Description>
    </em:targetApplication>
    <em:homepageURL>http://www.panda3d.org/</em:homepageURL>
    <em:updateURL>%(host_url)s/plugin/firefox/update.rdf</em:updateURL>
  </Description>
</RDF>
"""

##############################################################################
#
# This update.rdf file is used when building a Firefox XPI file.
#
##############################################################################

update_rdf = """<?xml version="1.0"?>
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:em="http://www.mozilla.org/2004/em-rdf#">

  <RDF:Description about="urn:mozilla:item:%(package_id)s">
    <em:updates>
      <RDF:Seq>
        <RDF:li>
          <RDF:Description><commit_msg>plugin must be called an 'extension' rather than an 'item' for FF to recognize the update.rdf<commit_after>#! /usr/bin/env python

import os
import sys
import shutil
import platform
import tempfile
import zipfile
from optparse import OptionParser
import subprocess

try:
    from hashlib import sha1 as sha
except ImportError:
    from sha import sha

usage = """
This command creates a graphical installer for the
Panda3D plugin and runtime environment.

  %prog [opts]"""

parser = OptionParser(usage = usage)
parser.add_option('-n', '--short', dest = 'short_name',
                  help = 'The product short name',
                  default = 'Panda3D')
parser.add_option('-N', '--long', dest = 'long_name',
                  help = 'The product long name',
                  default = 'Panda3D Game Engine')
parser.add_option('-v', '--version', dest = 'version',
                  help = 'The product version',
                  default = None)
parser.add_option('-p', '--publisher', dest = 'publisher',
                  help = 'The name of the publisher',
                  default = 'Carnegie Mellon Entertainment Technology Center')
parser.add_option('', '--install', dest = 'install_dir',
                  help = "The install directory on the user's machine (Windows only)",
                  default = '$PROGRAMFILES\\Panda3D')
parser.add_option('-l', '--license', dest = 'license',
                  help = 'A file containing the license or EULA text',
                  default = None)
parser.add_option('-w', '--website', dest = 'website',
                  help = 'The product website',
                  default = 'http://www.panda3d.org')
parser.add_option('', '--start', dest = 'start',
                  help = 'Specify this option to add a start menu',
                  action = 'store_false', default = False)
parser.add_option('', '--welcome_image', dest = 'welcome_image',
                  help = 'The image to display on the installer, 170x312 BMP',
                  default = None)
parser.add_option('', '--install_icon', dest = 'install_icon',
                  help = 'The icon to give to the installer',
                  default = None)
parser.add_option('', '--nsis', dest = 'nsis',
                  help = 'The path to the makensis executable',
                  default = None)
parser.add_option('', '--spc', dest = 'spc',
                  help = 'Generate an ActiveX CAB file, then sign it with the indicated spc file (Windows only).  You must also specify --pvk.',
                  default = None)
parser.add_option('', '--pvk', dest = 'pvk',
                  help = 'Specifies the private key to be used in conjuction with --spc to sign a CAB file (Windows only).',
                  default = None)
parser.add_option('', '--mssdk', dest = 'mssdk',
                  help = 'The path to the MS Platform SDK directory (Windows only).  mssdk/bin should contain cabarc.exe and signcode.exe.',
                  default = None)
parser.add_option('-i', '--plugin_root', dest = 'plugin_root',
                  help = 'The root of a directory hierarchy in which the Firefox plugins for various platforms can be found, to build a Firefox xpi file.  This is normally the same as the staging directory populated by the -i parameter to ppackage.  This directory should contain a directory called "plugin", which contains in turn a number of directories named for the platform, by the Panda plugin convention, e.g. linux_i386, osx_ppc, and so on.  Each platform directory should contain a Firefox plugin, e.g. nppanda3d.so.')
parser.add_option('', '--host_url', dest = 'host_url',
                  help = "The URL at which plugin_root will be hosted.  This is used to construct the update URL for the xpi file.  This is required if you specify --plugin_root.")

(options, args) = parser.parse_args()

this_dir = os.path.split(sys.argv[0])[0]

assert options.version, "A version number must be supplied!"

# A mapping of Panda's platform strings to Firefox's equivalent
# strings.

# I'm leaving out the Linux platforms for now.  I think there is too
# much variance between distro's for this to be reliable; we'll make
# each Linux user install their distro-specific plugin instead of
# going through this mechanism.
FirefoxPlatformMap = {
    'win32' : 'WINNT_x86-msvc',
    'win64' : 'WINNT_x86_64-msvc',
#    'linux_i386' : 'Linux_x86-gcc3',
#    'linux_amd64' : 'Linux_x86_64-gcc3',
#    'linux_ppc' : 'Linux_ppc-gcc3',
    'osx_i386' : 'Darwin_x86-gcc3',
    'osx_amd64' : 'Darwin_x86_64-gcc3',
    'osx_ppc' : 'Darwin_ppc-gcc3',
    'freebsd_i386' : 'FreeBSD_x86-gcc3',
    'freebsd_amd64' : 'FreeBSD_x86_64-gcc3',
    }

##############################################################################
#
# This install.rdf file is used when building a Firefox XPI file.
#
##############################################################################

install_rdf = """<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
  <Description about="urn:mozilla:install-manifest">
    <em:id>%(package_id)s</em:id>
    <em:name>Panda3D Game Engine Plug-In</em:name>
    <em:description>Runs 3-D games and interactive applets</em:description>
    <em:version>%(version)s</em:version>
    <em:targetApplication>
      <Description>
        <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
        <em:minVersion>3.0</em:minVersion>
        <em:maxVersion>*</em:maxVersion>
      </Description>
    </em:targetApplication>
    <em:homepageURL>http://www.panda3d.org/</em:homepageURL>
    <em:updateURL>%(host_url)s/plugin/firefox/update.rdf</em:updateURL>
  </Description>
</RDF>
"""

##############################################################################
#
# This update.rdf file is used when building a Firefox XPI file.
#
##############################################################################

update_rdf = """<?xml version="1.0"?>
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:em="http://www.mozilla.org/2004/em-rdf#">

  <RDF:Description about="urn:mozilla:extension:%(package_id)s">
    <em:updates>
      <RDF:Seq>
        <RDF:li>
          <RDF:Description>
{'fraction_non_alphanumeric': 0.17576639974116315, 'fraction_numerical': 0.020221629054436627, 'mean_word_length': 3.005183025591189, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 4, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 12, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5704864', 'n_tokens_mistral': 4003, 'n_tokens_neox': 3651, 'n_words': 1098}