| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- #! /usr/bin/env python
- usageText = """
- This command will help you to distribute your Panda application,
- consisting of a .p3d package, into a standalone executable, graphical
- installer or an HTML webpage. It will attempt to create packages
- for every platform, if possible.
- Note that pdeploy requires an internet connection to run.
- Usage:
- %(prog)s [opts] app.p3d standalone|installer|html
- Modes:
- standalone
- A standalone executable will be created that embeds the given
- p3d file. The resulting executable will require an
- internet connection in order to run properly.
- installer
- In this mode, installable packages will be created for as many
- platforms as possible. To create Windows installers on
- non-Windows platforms, you need to have the "makensis" utility
- on your system PATH environment variable.
- html
- An HTML webpage will be generated that can be used to view
- the provided p3d file in a browser.
- Options:
- -n your_app
- Short, lowercase name of the application or game. May only
- contain alphanumeric characters, underscore or dash. This
- name will also define the output file(s) of the process.
- If omitted, the basename of the p3d file is used.
- -N "Your Application"
- Full name of the application or game. This value will
- be used to display to the end-user.
- If omitted, the short name is used.
- -v version_number
- This should define the version number of your application
- or game. In some deploy modes, this argument is required.
- This should only contain alphanumeric characters, dots and
- dashes, as otherwise the result of the deployment may be
- invalid on some platforms.
- -o output_dir
- Indicates the directory where the output will be stored.
- Within this directory, subdirectories will be created
- for every platform, unless -t is provided.
- If omitted, the current working directory is assumed.
- -t token=value
- Defines a web token or parameter to pass to the application.
- Use this to configure how the application will be run.
- You can pass as many -t options as you need. Examples of
- tokens are width, height, log_basename, auto_start, hidden.
- -P platform
- If this option is provided, it should specify a comma-
- separated list of platforms that the p3d package will be
- deployed for. If omitted, it will be built for all platforms.
- This option may be specified multiple times.
- Examples of valid platforms are win32, linux_amd64 and osx_ppc.
- -c
- If this option is provided, any -P options are ignored and
- the p3d package is only deployed for the current platform.
- Furthermore, no per-platform subdirectories will be created
- inside the output dirctory.
- -s
- This option only has effect in 'installer' mode. If it is
- provided, the resulting installers will be fully self-contained,
- will not require an internet connection to run, and start up
- much faster. Note that pdeploy will also take a very long time
- to finish when -s is provided.
- If it is omitted, pdeploy will finish much quicker, and the
- resulting installers will be smaller, but they will require
- an internet connection for the first run, and the load time
- will be considerably longer.
- -l "License Name"
- Specifies the name of the software license that the game
- or application is licensed under.
- Only relevant when generating a graphical installer.
- -L licensefile.txt
- This should point to a file that contains the full text
- describing the software license that the game or application
- is licensed under.
- Only relevant when generating a graphical installer.
- -a com.your_company
- Short identifier of the author of the application. The default
- is "org.panda3d", but you will most likely want to change
- it to your own name or that of your organization or company.
- -A "Your Company"
- Full name of the author of the application.
- -h
- Display this help
- """
- DEPLOY_MODES = ["standalone", "installer", "html"]
- import sys
- import os
- import getopt
- from direct.p3d.DeploymentTools import Standalone, Installer
- from pandac.PandaModules import Filename, PandaSystem
- def usage(code, msg = ''):
- print >> sys.stderr, usageText % {'prog' : os.path.split(sys.argv[0])[1]}
- print >> sys.stderr, msg
- sys.exit(code)
- shortname = ""
- fullname = ""
- version = ""
- outputDir = Filename("./")
- tokens = {}
- platforms = []
- currentPlatform = False
- licensename = ""
- licensefile = Filename()
- authorid = ""
- authorname = ""
- includeRequires = False
- try:
- opts, args = getopt.getopt(sys.argv[1:], 'n:N:v:o:t:P:csl:L:a:A:h')
- except getopt.error, msg:
- usage(1, msg)
- for opt, arg in opts:
- if opt == '-n':
- shortname = arg.strip()
- elif opt == '-N':
- fullname = arg.strip()
- elif opt == '-v':
- version = arg.strip()
- elif opt == '-o':
- outputDir = Filename.fromOsSpecific(arg)
- elif opt == '-t':
- token = arg.strip().split("=", 1)
- tokens[token[0]] = token[1]
- elif opt == '-P':
- platforms.append(arg)
- elif opt == '-c':
- currentPlatform = True
- elif opt == '-s':
- includeRequires = True
- elif opt == '-l':
- licensename = arg.strip()
- elif opt == '-L':
- licensefile = Filename.fromOsSpecific(arg)
- elif opt == '-a':
- authorid = arg.strip()
- elif opt == '-A':
- authorname = arg.strip()
-
- elif opt == '-h':
- usage(0)
- else:
- print 'illegal option: ' + flag
- sys.exit(1)
- if not args or len(args) != 2:
- usage(1)
- appFilename = Filename.fromOsSpecific(args[0])
- if appFilename.getExtension().lower() != 'p3d':
- print 'Application filename must end in ".p3d".'
- sys.exit(1)
- deploy_mode = args[1].lower()
- if not appFilename.exists():
- print 'Application filename does not exist!'
- sys.exit(1)
- if shortname.lower() != shortname or ' ' in shortname:
- print '\nProvided short name should be lowercase, and may not contain spaces!\n'
- if shortname == '':
- shortname = appFilename.getBasenameWoExtension()
- if fullname == '':
- fullname = shortname
- if version == '' and deploy_mode == 'installer':
- print '\nA version number is required in "installer" mode.\n'
- sys.exit(1)
- if not outputDir:
- print '\nYou must name the output directory with the -o parameter.\n'
- sys.exit(1)
- if deploy_mode == 'standalone':
- s = Standalone(appFilename, tokens)
- s.basename = shortname
-
- if currentPlatform:
- platform = PandaSystem.getPlatform()
- if platform.startswith("win"):
- s.build(Filename(outputDir, shortname + ".exe"), platform)
- else:
- s.build(Filename(outputDir, shortname), platform)
- elif len(platforms) == 0:
- s.buildAll(outputDir)
- else:
- for platform in platforms:
- if platform.startswith("win"):
- s.build(Filename(outputDir, platform + "/" + shortname + ".exe"), platform)
- else:
- s.build(Filename(outputDir, platform + "/" + shortname), platform)
- elif deploy_mode == 'installer':
- i = Installer(shortname, fullname, appFilename, version, tokens = tokens)
- i.licensename = licensename
- i.licensefile = licensefile
- i.authorid = authorid
- i.authorname = authorname
- i.includeRequires = includeRequires
-
- if currentPlatform:
- platform = PandaSystem.getPlatform()
- if platform.startswith("win"):
- i.build(outputDir, platform)
- else:
- i.build(outputDir, platform)
- elif len(platforms) == 0:
- i.buildAll(outputDir)
- else:
- for platform in platforms:
- output = Filename(outputDir, platform + "/")
- output.makeDir()
- i.build(output, platform)
- elif deploy_mode == 'html':
- print "Creating %s.html..." % shortname
- html = open(shortname + ".html", "w")
- html.write("<html>\n")
- html.write(" <head>\n")
- html.write(" <title>%s</title>\n" % fullname)
- html.write(" </head>\n")
- html.write(" <body>\n")
- html.write(" <object data=\"%s\" type=\"application/x-panda3d\"></object>\n" % appFilename.getBasename())
- html.write(" </body>\n")
- html.write("</html>\n")
- html.close()
- else:
- usage(1, 'Invalid deployment mode!')
- # An explicit call to exit() is required to exit the program, when
- # this module is packaged in a p3d file.
- sys.exit(0)
|