コード例 #1
0
def buildDeb(dest=None):
    global package_name
    global package_version
    global package_replaces
    global package_explicit
    global hgpath
    global files_to_chmod_executable

    if os.geteuid() != 0:
        print "WARNING: You are not root. You should be running this script with root permissions!"

    if dest is None:
        dest = os.getenv('makehuman_dest', 0)

        if dest == 0:
            print "You must explicitly set the makehuman_dest environment variable to point at a work directory, or specify it as argument. I will violently destroy and mutilate the contents of this directory."
            exit(1)

    destdir = os.path.normpath(
        os.path.realpath(dest))  # Folder to build deb package to
    if os.path.exists(destdir):
        # Ensure dest dir is empty
        shutil.rmtree(destdir)
    os.mkdir(destdir)

    debdir = os.path.dirname(
        os.path.abspath(__file__))  # / deb build script root path

    print "Destination directory: " + destdir

    hgrootdir = os.path.normpath(
        os.path.realpath(os.path.join(debdir, '..', '..')))

    print "HG root directory: " + hgrootdir
    if not os.path.isdir(os.path.join(hgrootdir, '.hg')):
        print "Error, the hg root folder %s does not contain .hg folder!" % hgrootdir
        exit(1)

    # Parse build.conf (in buildscripts folder)
    configure(os.path.join(hgrootdir, 'buildscripts', 'build.conf'))

    # Folder where hg contents are exported and prepared for packaging (scripts are run)
    exportdir = os.path.normpath(
        os.path.realpath(
            os.path.join(hgrootdir, '..', package_name + '-export-deb')))
    print "Source export directory: " + exportdir

    print "\nABOUT TO PERFORM BUILD EXPORT\n"
    print "to: %s" % os.path.normpath(os.path.realpath(exportdir))

    # Export source to export folder and run scripts
    sys.path = [os.path.join(debdir, '..')] + sys.path
    try:
        import build_prepare
    except:
        print "Failed to import build_prepare, expected to find it at %s. Make sure to run this script from hgroot/buildscripts/deb/" % os.path.normpath(
            os.path.realpath(os.path.join(debdir, '..')))
        exit(1)
    if os.path.exists(exportdir):
        shutil.rmtree(exportdir)
    exportInfo = build_prepare.export(sourcePath=hgrootdir,
                                      exportFolder=exportdir)

    scriptdir = os.path.abspath(os.path.join(
        exportdir,
        'makehuman'))  # .. Folder containing makehuman.py (source to package)
    print "Makehuman directory: " + scriptdir

    if not exportInfo.isRelease and not package_explicit:
        package_name = package_name + 'hg'

    target = os.path.join(
        destdir,
        "debroot")  # /dest/debroot    contents of deb archive (= target)
    if not os.path.exists(target):
        os.mkdir(target)

    controldir = os.path.join(
        target, "DEBIAN")  # /dest/debroot/DEBIAN   deb control files
    if not os.path.exists(controldir):
        os.mkdir(controldir)

    print "Control directory: " + controldir

    srccontrol = os.path.join(debdir, "debian")
    # /debian   source of DEBIAN control templates

    if not os.path.exists(srccontrol):
        print "The debian directory does not exist in the source deb folder. Something is likely horribly wrong. Eeeeek! Giving up and hiding..."
        exit(1)

    bindir = os.path.join(target, "usr", "bin")
    if not os.path.exists(bindir):
        os.makedirs(bindir)

    print "Bin directory: " + bindir

    srcbin = os.path.join(debdir, "bin")
    # /bin    src executable file

    if not os.path.exists(srcbin):
        print "The bin directory does not exist in the source deb folder. Something is likely horribly wrong. Eeeeek! Giving up and hiding..."
        exit(1)

    docdir = os.path.join(target, "usr", "share", "doc", package_name)
    if not os.path.exists(docdir):
        os.makedirs(docdir)

    print "Doc dir: " + docdir  # /dest/share/doc/makehuman   docs export folder

    applications = os.path.join(
        target, "usr", "share", "applications"
    )  # /dest/share/applications   app shortcut export folder
    if not os.path.exists(applications):
        os.mkdir(applications)

    print "Desktop shortcut dir: " + applications

    programdir = os.path.join(
        target, "usr", "share", "makehuman"
    )  # /dest/share/makehuman   export folder of mh app and data
    if os.path.exists(programdir):
        shutil.rmtree(programdir)  # Cannot exist because copytree requires it

    print "Program directory: " + programdir

    print "\nABOUT TO COPY CONTENTS TO DEB DEST\n"

    shutil.copytree(
        scriptdir, programdir)  # Copy exported makehuman/ folder to programdir

    # Copy icon file from hg to export folder
    svgIcon = os.path.join(hgrootdir, 'makehuman/icons/makehuman.svg')
    shutil.copy(svgIcon, os.path.join(programdir, "makehuman.svg"))

    # Copy files in src bin dir to dest bin dir
    _cp_files(srcbin, bindir)

    # Make a copy of hg revision in docs folder
    try:
        shutil.copy(os.path.join(programdir, 'data', 'VERSION'),
                    os.path.join(docdir, "HGREV.txt"))
    except:
        print "ERROR did not find data/VERSION file (%s)! Your build is incomplete!! Verify your build_prepare settings." % os.path.join(
            programdir, 'data', 'VERSION')
        exit(1)

    # Copy files in src bin dir to dest bin dir (copy bash wrapper executable)
    _cp_files(srccontrol, controldir)

    hgrev = exportInfo.revision

    # Calculate package size
    # du -cks $target | cut -f 1 | uniq
    du_p = subprocess.Popen(['du', '-cks', target], stdout=subprocess.PIPE)
    cut_p = subprocess.Popen(['cut', '-f', '1'],
                             stdin=du_p.stdout,
                             stdout=subprocess.PIPE)
    uniq_p = subprocess.Popen(['uniq'],
                              stdin=cut_p.stdout,
                              stdout=subprocess.PIPE)
    # Allow producer processes to receive SIGPIPE if consumer process exits
    du_p.stdout.close()
    cut_p.stdout.close()
    # Retrieve output
    size = uniq_p.communicate()[0].strip().strip('\n')
    print "\nPackage size: %s\n" % size

    if package_version is None:
        if exportInfo.isRelease:
            # Conform to: http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version
            ver = "1:" + exportInfo.version.replace(' ', '.').lower()
        else:
            ver = hgrev
    else:
        ver = package_version

    print "DEB PACKAGE VERSION: %s\n" % ver

    # Replace fields in control file template
    controlFile = os.path.join(controldir, 'control')
    _sed_replace(controlFile, 'VERSION', ver)
    _sed_replace(controlFile, 'PKGNAME', package_name)
    _sed_replace(controlFile, 'REPLACES', package_replaces)
    _sed_replace(controlFile, 'SIZE', size)

    if exportInfo.isRelease:
        ver = exportInfo.version
    else:
        ver = hgrev
    # Create desktop shortcut
    shortcut = os.path.join(applications, "MakeHuman.desktop")
    shutil.move(os.path.join(controldir, "MakeHuman.desktop"), shortcut)
    _sed_replace(shortcut, 'VERSION', ver)

    # Generate changelog
    os.chdir(hgrootdir)
    changelog = os.path.join(docdir, "changelog")
    import glob
    for logfile in glob.glob(changelog + '*'):
        if os.path.isfile(logfile):
            os.remove(logfile)
    branch_p = subprocess.Popen([hgpath, 'branch'], stdout=subprocess.PIPE)
    branch = branch_p.communicate()[0].strip().strip('\n')
    print "\nUsing HG branch: %s\n" % branch

    changelog_f = open(changelog, 'wb')
    subprocess.check_call([hgpath, 'log', '-b', branch], stdout=changelog_f)
    changelog_f.close()
    subprocess.check_call(['gzip', '-9v', changelog])

    os.chdir(target)

    # Move copyright file in place
    copysrc = os.path.join(controldir, "copyright")
    copydest = os.path.join(docdir, "copyright")
    shutil.move(copysrc, copydest)

    # Move license file in place
    lsrc = os.path.join(programdir, "license.txt")
    ldst = os.path.join(docdir, "LICENSE.txt")
    shutil.move(lsrc, ldst)

    try:
        subprocess.check_call(["chown", "-R", "0:0", target])
    except:
        print "Failed to chown to root. Operation not permitted?"
    try:
        subprocess.check_call(["chmod", "-R", "644", target])
        for path, dirs, files in os.walk(target):
            for d in dirs:
                dpath = os.path.join(target, path, d)
                try:
                    subprocess.check_call(["chmod", "755", dpath])
                except:
                    print "Failed to chmod 755 folder %s" % dpath
        subprocess.check_call(["chmod", "755", target])
    except:
        print "Failed to chmod."

    for x in files_to_chmod_executable:
        if os.path.exists(x):
            subprocess.check_call(["chmod", "755", x])

    outputdir = os.path.join(destdir, "output")

    if not os.path.exists(outputdir):
        os.mkdir(outputdir)

    os.chdir(outputdir)

    if package_version is None:
        if exportInfo.isRelease:
            ver = exportInfo.version.replace(' ', '.').lower()
        else:
            ver = hgrev
    else:
        ver = package_version
    debfile = os.path.join(outputdir, package_name + "-" + ver + "_all.deb")

    debcmd = [
        "dpkg-deb", "-Z", "bzip2", "-z", "9", "-b", "../debroot", debfile
    ]

    print debcmd
    subprocess.check_call(debcmd)

    print "\n\n\nPackage is now available in " + debfile + "\n"
    print "If you are building for release, you should now run:\n"
    print "  lintian " + debfile + "\n"
    print "... in order to check the deb file.\n"
コード例 #2
0
else:
    print("Could not find build.conf")
    exit(1)

exportDir = None
if len(sys.argv) > 1:
    exportDir = sys.argv[1]
if exportDir is None:
    exportDir = defaultworkdir

if not os.path.exists(exportDir):
    os.mkdir(exportDir)

shutil.rmtree(exportDir)

export(rootdir, exportDir, False, False)

if not os.path.exists(exportDir):
    print("Export dir %s does not exist" % exportDir)
    exit(1)

pynsistIn = os.path.join(build_scripts, 'win32', 'pynsist.cfg')
pynsistOut = os.path.join(exportDir, 'pynsist.cfg')

with open(pynsistIn, 'r') as f:
    pynsist = f.read()

title = "makehuman-community"
version = datetime.datetime.today().strftime('%Y%m%d')

if "pynsistTitle" in config["Win32"]:
コード例 #3
0
ファイル: buildDeb.py プロジェクト: kingomyths/mhx_os
def buildDeb(dest = None):
  global package_name
  global package_version
  global package_replaces
  global package_explicit
  global hgpath
  global files_to_chmod_executable

  if os.geteuid() != 0:
    print "WARNING: You are not root. You should be running this script with root permissions!"

  if dest is None:
    dest = os.getenv('makehuman_dest',0)

    if dest == 0:
      print "You must explicitly set the makehuman_dest environment variable to point at a work directory, or specify it as argument. I will violently destroy and mutilate the contents of this directory."
      exit(1)

  destdir = os.path.normpath(os.path.realpath(dest))          # Folder to build deb package to
  if os.path.exists(destdir):
    # Ensure dest dir is empty
    shutil.rmtree(destdir)
  os.mkdir(destdir)

  debdir = os.path.dirname(os.path.abspath(__file__))         # / deb build script root path

  print "Destination directory: " + destdir

  hgrootdir = os.path.normpath(os.path.realpath( os.path.join(debdir, '..', '..') ))

  print "HG root directory: " + hgrootdir
  if not os.path.isdir( os.path.join(hgrootdir, '.hg') ):
    print "Error, the hg root folder %s does not contain .hg folder!" % hgrootdir
    exit(1)


  # Parse build.conf (in buildscripts folder)
  configure(os.path.join(hgrootdir, 'buildscripts', 'build.conf'))


  # Folder where hg contents are exported and prepared for packaging (scripts are run)
  exportdir = os.path.normpath(os.path.realpath( os.path.join(hgrootdir, '..', package_name + '-export-deb') ))
  print "Source export directory: " + exportdir


  print "\nABOUT TO PERFORM BUILD EXPORT\n"
  print "to: %s" % os.path.normpath(os.path.realpath(exportdir))

  # Export source to export folder and run scripts
  sys.path = [os.path.join(debdir, '..')] + sys.path
  try:
    import build_prepare
  except:
    print "Failed to import build_prepare, expected to find it at %s. Make sure to run this script from hgroot/buildscripts/deb/" % os.path.normpath(os.path.realpath(os.path.join(debdir, '..')))
    exit(1)
  if os.path.exists(exportdir):
    shutil.rmtree(exportdir)
  exportInfo = build_prepare.export(sourcePath = hgrootdir, exportFolder = exportdir)

  os.remove(os.path.join(exportdir, 'makehuman', 'blendertools', 'copy2blender.bat'))

  scriptdir = os.path.abspath( os.path.join(exportdir, 'makehuman') )    # .. Folder containing makehuman.py (source to package)
  print "Makehuman directory: " + scriptdir

  if not exportInfo.isRelease and not package_explicit:
    package_name = package_name + 'hg'

  target = os.path.join(destdir,"debroot")                    # /dest/debroot    contents of deb archive (= target)
  if not os.path.exists(target):
    os.mkdir(target)

  controldir = os.path.join(target,"DEBIAN")                  # /dest/debroot/DEBIAN   deb control files
  if not os.path.exists(controldir):
    os.mkdir(controldir)

  print "Control directory: " + controldir

  srccontrol = os.path.join(debdir,"debian");                 # /debian   source of DEBIAN control templates

  if not os.path.exists(srccontrol):
    print "The debian directory does not exist in the source deb folder. Something is likely horribly wrong. Eeeeek! Giving up and hiding..."
    exit(1)

  bindir = os.path.join(target, "usr", "bin")
  if not os.path.exists(bindir):
    os.makedirs(bindir)

  print "Bin directory: " + bindir

  srcbin = os.path.join(debdir,"bin");                        # /bin    src executable file

  if not os.path.exists(srcbin):
    print "The bin directory does not exist in the source deb folder. Something is likely horribly wrong. Eeeeek! Giving up and hiding..."
    exit(1)

  docdir = os.path.join(target, "usr", "share", "doc", package_name)
  if not os.path.exists(docdir):
    os.makedirs(docdir)

  print "Doc dir: " + docdir                                # /dest/share/doc/makehuman   docs export folder

  applications = os.path.join(target, "usr", "share", "applications")  # /dest/share/applications   app shortcut export folder
  if not os.path.exists(applications):
    os.mkdir(applications)

  print "Desktop shortcut dir: " + applications

  programdir = os.path.join(target, "usr", "share", "makehuman")    # /dest/share/makehuman   export folder of mh app and data
  if os.path.exists(programdir):
    shutil.rmtree(programdir) # Cannot exist because copytree requires it

  print "Program directory: " + programdir

  print "\nABOUT TO COPY CONTENTS TO DEB DEST\n"

  shutil.copytree(scriptdir, programdir)  # Copy exported makehuman/ folder to programdir

  # Copy icon file from hg to export folder
  svgIcon = os.path.join(hgrootdir, 'makehuman/icons/makehuman.svg')
  shutil.copy(svgIcon, os.path.join(programdir,"makehuman.svg"))

  # Copy files in src bin dir to dest bin dir
  _cp_files(srcbin, bindir)

  # Make a copy of hg revision in docs folder
  try:
    shutil.copy(os.path.join(programdir, 'data', 'VERSION'), os.path.join(docdir,"HGREV.txt"))
  except:
    print "ERROR did not find data/VERSION file (%s)! Your build is incomplete!! Verify your build_prepare settings." % os.path.join(programdir, 'data', 'VERSION')
    exit(1)

  # Copy files in src bin dir to dest bin dir
  _cp_files(srccontrol, controldir)

  hgrev = exportInfo.revision

  # Calculate package size
  # du -cks $target | cut -f 1 | uniq
  du_p = subprocess.Popen(['du', '-cks', target], stdout=subprocess.PIPE)
  cut_p = subprocess.Popen(['cut', '-f', '1'], stdin=du_p.stdout, stdout=subprocess.PIPE)
  uniq_p = subprocess.Popen(['uniq'], stdin=cut_p.stdout, stdout=subprocess.PIPE)
  # Allow producer processes to receive SIGPIPE if consumer process exits
  du_p.stdout.close()
  cut_p.stdout.close()
  # Retrieve output
  size = uniq_p.communicate()[0].strip().strip('\n')
  print "\nPackage size: %s\n" % size

  if package_version is None:
    if exportInfo.isRelease:
        # Conform to: http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version
        ver = "1:"+exportInfo.version.replace(' ', '.').lower()
    else:
        ver = hgrev
  else:
    ver = package_version

  print "DEB PACKAGE VERSION: %s\n" % ver

  # Replace fields in control file template
  controlFile = os.path.join(controldir, 'control')
  _sed_replace(controlFile, 'VERSION', ver)
  _sed_replace(controlFile, 'PKGNAME', package_name)
  _sed_replace(controlFile, 'REPLACES', package_replaces)
  _sed_replace(controlFile, 'SIZE', size)

  if exportInfo.isRelease:
      ver = exportInfo.version
  else:
      ver = hgrev
  # Create desktop shortcut
  shortcut = os.path.join(applications, "MakeHuman.desktop")
  shutil.move(os.path.join(controldir, "MakeHuman.desktop"), shortcut)
  _sed_replace(shortcut, 'VERSION', ver)


  # Generate changelog
  os.chdir(hgrootdir)
  changelog = os.path.join(docdir,"changelog")
  import glob
  for logfile in glob.glob(changelog+'*'):
    if os.path.isfile(logfile):
      os.remove(logfile)
  branch_p = subprocess.Popen([hgpath,'branch'], stdout=subprocess.PIPE)
  branch = branch_p.communicate()[0].strip().strip('\n')
  print "\nUsing HG branch: %s\n" % branch

  changelog_f = open(changelog, 'wb')
  subprocess.check_call([hgpath,'log','-b',branch], stdout=changelog_f)
  changelog_f.close()
  subprocess.check_call(['gzip', '-9v', changelog])


  os.chdir(target)

  # Move copyright file in place
  copysrc = os.path.join(controldir,"copyright")
  copydest = os.path.join(docdir,"copyright")
  shutil.move(copysrc, copydest)

  # Move license file in place
  lsrc = os.path.join(programdir,"license.txt")
  ldst = os.path.join(docdir,"LICENSE.txt")
  shutil.move(lsrc, ldst)

  try:
    subprocess.check_call(["chown", "-R", "0:0", target])
  except:
    print "Failed to chown to root. Operation not permitted?"
  try:
    subprocess.check_call(["chmod", "-R", "644", target])
    for path, dirs, files in os.walk(target):
      for d in dirs:
        dpath = os.path.join(target, path, d)
        try:
          subprocess.check_call(["chmod", "755", dpath])
        except:
          print "Failed to chmod 755 folder %s" % dpath
    subprocess.check_call(["chmod", "755", target])
  except:
    print "Failed to chmod."

  for x in files_to_chmod_executable:
    if os.path.exists(x):
      subprocess.check_call(["chmod", "755", x])

  outputdir = os.path.join(destdir,"output")

  if not os.path.exists(outputdir):
    os.mkdir(outputdir)

  os.chdir(outputdir)

  if package_version is None:
    if exportInfo.isRelease:
        ver = exportInfo.version.replace(' ', '.').lower()
    else:
        ver = hgrev
  else:
    ver = package_version
  debfile = os.path.join(outputdir,package_name + "-" + ver + "_all.deb")

  debcmd = ["dpkg-deb", "-Z", "bzip2", "-z", "9", "-b", "../debroot", debfile]

  print debcmd
  subprocess.check_call(debcmd)

  print "\n\n\nPackage is now available in " + debfile + "\n"
  print "If you are building for release, you should now run:\n"
  print "  lintian " + debfile + "\n"
  print "... in order to check the deb file.\n"
コード例 #4
0
def buildSourceTree(dest=None):
    if os.geteuid() != 0:
        print "WARNING: You are not root. You should be running this script with root permissions!"

    if dest is None:
        dest = os.getenv('makehuman_dest', 0)

        if dest == 0:
            print "You must explicitly set the makehuman_dest environment variable to point at a work directory, or specify it as argument. I will violently destroy and mutilate the contents of this directory."
            exit(1)

    settings["build_root"] = os.path.normpath(
        os.path.realpath(dest))  # Folder to build deb package to
    if os.path.exists(settings["build_root"]):
        # Ensure dest dir is empty
        shutil.rmtree(settings["build_root"])
    os.mkdir(settings["build_root"])

    configurePaths()

    print "\nABOUT TO PERFORM BUILD EXPORT\n"
    print "to: %s" % os.path.normpath(
        os.path.realpath(settings["build_prepare_destination"]))

    # Export source to export folder and run scripts
    sys.path = [os.path.join(settings["location_of_script"], '..')] + sys.path
    try:
        import build_prepare
    except:
        print "Failed to import build_prepare, expected to find it at %s. Make sure to run this script from hgroot/buildscripts/deb/" % os.path.normpath(
            os.path.realpath(os.path.join(settings["location_of_script"],
                                          '..')))
        exit(1)
    if os.path.exists(settings["build_prepare_destination"]):
        shutil.rmtree(settings["build_prepare_destination"])
    exportInfo = build_prepare.export(
        sourcePath=settings["source_root"],
        exportFolder=settings["build_prepare_destination"])

    #os.remove(os.path.join(settings["build_prepare_destination"], 'makehuman', 'blendertools'ender.bat'))

    print "\nABOUT TO COPY CONTENTS\n"

    try:
        subprocess.check_call(
            ["chown", "-R", "0:0", settings["build_prepare_destination"]])
    except:
        print "Failed to chown to root. Operation not permitted?"
    try:
        subprocess.check_call(
            ["chmod", "-R", "644", settings["build_prepare_destination"]])
        for path, dirs, files in os.walk(
                settings["build_prepare_destination"]):
            for d in dirs:
                dpath = os.path.join(settings["build_prepare_destination"],
                                     path, d)
                try:
                    subprocess.check_call(["chmod", "755", dpath])
                except:
                    print "Failed to chmod 755 folder %s" % dpath
        subprocess.check_call(
            ["chmod", "755", settings["build_prepare_destination"]])
    except Exception as e:
        print "Failed to chmod " + settings["build_prepare_destination"]
        print e

    for x in files_to_chmod_executable:
        if os.path.exists(x):
            subprocess.check_call(["chmod", "755", x])

    shutil.copytree(settings["extras_location"],
                    settings["extras_destination"])

    print "\nCOPYING RAW TARGETS FOR -dev\n"
    _cp_pattern(settings["makehuman_source_root"],
                settings["manual_export_location"], ".target")

    print "\nCOPYING RAW OBJS FOR -dev\n"
    _cp_pattern(settings["makehuman_source_root"],
                settings["manual_export_location"], ".obj")

    print "\nCOPYING RAW MHCLO FOR -dev\n"
    _cp_pattern(settings["makehuman_source_root"],
                settings["manual_export_location"], ".mhclo")

    print "\nCOPYING RAW PROXIES FOR -dev\n"
    _cp_pattern(settings["makehuman_source_root"],
                settings["manual_export_location"], ".proxy")

    dummy = os.path.join(settings["manual_export_location"], "dummy.txt")

    with open(dummy, "w") as text_file:
        text_file.write(
            "This is only because moronic debuild cannot handle tarballs which doesn't have a non-dir entry in the root"
        )

    try:
        subprocess.check_call(
            ["chown", "-R", "0:0", settings["manual_export_location"]])
    except:
        print "Failed to chown to root. Operation not permitted?"
    try:
        subprocess.check_call(
            ["chmod", "-R", "644", settings["manual_export_location"]])
        for path, dirs, files in os.walk(settings["manual_export_location"]):
            for d in dirs:
                dpath = os.path.join(settings["manual_export_location"], path,
                                     d)
                try:
                    subprocess.check_call(["chmod", "755", dpath])
                except:
                    print "Failed to chmod 755 folder %s" % dpath
        subprocess.check_call(
            ["chmod", "755", settings["manual_export_location"]])
    except Exception as e:
        print "Failed to chmod " + settings["manual_export_location"]
        print e
コード例 #5
0
def buildRpm():
    global package_name
    global package_version

    if os.geteuid() == 0:
        print(
            "You are not allowed to run this script as root. You must run it as a normal user."
        )
        exit(1)

    rpmdir = os.path.dirname(
        os.path.abspath(__file__))  # / rpm build script root path

    hgrootdir = os.path.normpath(
        os.path.realpath(os.path.join(rpmdir, '..', '..')))

    print("HG root directory: " + hgrootdir)
    if not os.path.isdir(os.path.join(hgrootdir, '.hg')):
        print(
            "Error, the hg root folder %s does not contain .hg folder! Make sure you are running this script from buildscripts/rpm in the hg repository."
            % hgrootdir)
        exit(1)

    # Parse build.conf (in buildscripts folder)
    configure(os.path.join(hgrootdir, 'buildscripts', 'build.conf'))

    # Folder where hg contents are exported and prepared for packaging (scripts are run)
    exportdir = os.path.normpath(
        os.path.realpath(os.path.join(hgrootdir, '..', 'mh-export-rpm')))
    print("Source export directory: " + exportdir)

    homedir = os.getenv('HOME', None)
    if not homedir:
        print("ERROR: cannot get HOME directory from $HOME environment var.")
        exit(1)

    # Export source to export folder and run scripts
    sys.path = [os.path.join(rpmdir, '..')] + sys.path
    try:
        import build_prepare
    except:
        print(
            "Failed to import build_prepare, expected to find it at %s. Make sure to run this script from hgroot/buildscripts/rpm/"
            % os.path.normpath(os.path.realpath(os.path.join(rpmdir, '..'))))
        exit(1)
    if os.path.exists(exportdir):
        shutil.rmtree(exportdir)

    exportInfo = build_prepare.export(sourcePath=hgrootdir,
                                      exportFolder=exportdir)

    # Copy extra files
    svgIco = os.path.join(hgrootdir, 'makehuman', 'icons', 'makehuman.svg')
    shutil.copy(svgIco, os.path.join(exportdir, 'makehuman', 'makehuman.svg'))

    desktopFile = os.path.join(hgrootdir, 'buildscripts', 'deb', 'debian',
                               'MakeHuman.desktop')
    desktopDest = os.path.join(exportdir, 'makehuman', 'MakeHuman.desktop')
    shutil.copy(desktopFile, desktopDest)
    subprocess.check_call(
        ['sed', '-i', '-e',
         's/VERSION/%s/' % exportInfo.version, desktopDest])

    execFile = os.path.join(hgrootdir, 'buildscripts', 'rpm', 'makehuman')
    execDest = os.path.join(exportdir, 'makehuman', 'makehuman')
    if os.path.isfile(execDest):
        os.remove(execDest)
    shutil.copy(execFile, execDest)

    os.remove(
        os.path.join(exportdir, 'makehuman', 'blendertools',
                     'copy2blender.bat'))

    # Setup RPM environment
    for d in [
            'SRPMS', 'BUILD', 'SPECS', 'SOURCES', 'lib', 'RPMS/i386',
            'RPMS/noarch'
    ]:
        if not os.path.isdir(os.path.join(homedir, 'rpms', d)):
            os.makedirs(os.path.join(homedir, 'rpms', d))

    subprocess.check_call(
        ['rpm', '--initdb', '--dbpath',
         os.path.join(homedir, 'rpms', 'lib')])

    f = open(os.path.join(homedir, '.rpmmacros'), 'wb')
    f.write("%_topdir %(echo $HOME)/rpms")
    f.close()

    # Execute build
    if exportInfo.isRelease:
        os.environ["MH_PKG_NAME"] = package_name
    else:
        os.environ["MH_PKG_NAME"] = package_name + 'hg'
    if package_version is None:
        version = exportInfo.version.replace(" ", ".")
    else:
        version = package_version
    print("RPM PACKAGE VERSION: %s\n" % version)
    os.environ["MH_VERSION"] = version
    os.environ["MH_EXPORT_PATH"] = exportdir
    print('\n\nBuilding RPM package "%s" of version "%s"\n\n' %
          (os.environ["MH_PKG_NAME"], version))
    subprocess.check_call(['bash', 'make_rpm.bash'])
コード例 #6
0
ファイル: buildRpm.py プロジェクト: TeoTwawki/makehuman
def buildRpm():
  global package_name
  global package_version

  if os.geteuid() == 0:
    print "You are not allowed to run this script as root. You must run it as a normal user."
    exit(1)

  rpmdir = os.path.dirname(os.path.abspath(__file__))         # / rpm build script root path

  hgrootdir = os.path.normpath(os.path.realpath( os.path.join(rpmdir, '..', '..') ))

  print "HG root directory: " + hgrootdir
  if not os.path.isdir( os.path.join(hgrootdir, '.hg') ):
    print "Error, the hg root folder %s does not contain .hg folder! Make sure you are running this script from buildscripts/rpm in the hg repository." % hgrootdir
    exit(1)


  # Parse build.conf (in buildscripts folder)
  configure(os.path.join(hgrootdir, 'buildscripts', 'build.conf'))


  # Folder where hg contents are exported and prepared for packaging (scripts are run)
  exportdir = os.path.normpath(os.path.realpath( os.path.join(hgrootdir, '..', 'mh-export-rpm') ))
  print "Source export directory: " + exportdir

  homedir = os.getenv('HOME', None)
  if not homedir:
    print "ERROR: cannot get HOME directory from $HOME environment var."
    exit(1)


  # Export source to export folder and run scripts
  sys.path = [os.path.join(rpmdir, '..')] + sys.path
  try:
    import build_prepare
  except:
    print "Failed to import build_prepare, expected to find it at %s. Make sure to run this script from hgroot/buildscripts/rpm/" % os.path.normpath(os.path.realpath(os.path.join(rpmdir, '..')))
    exit(1)
  if os.path.exists(exportdir):
    shutil.rmtree(exportdir)

  exportInfo = build_prepare.export(sourcePath = hgrootdir, exportFolder = exportdir)


  # Copy extra files
  svgIco = os.path.join(hgrootdir, 'makehuman', 'icons', 'makehuman.svg')
  shutil.copy(svgIco, os.path.join(exportdir, 'makehuman', 'makehuman.svg'))

  desktopFile = os.path.join(hgrootdir, 'buildscripts', 'deb', 'debian', 'MakeHuman.desktop')
  desktopDest = os.path.join(exportdir, 'makehuman', 'MakeHuman.desktop')
  shutil.copy(desktopFile, desktopDest)
  subprocess.check_call(['sed', '-i', '-e', 's/VERSION/%s/' % exportInfo.version, desktopDest])
  
  execFile = os.path.join(hgrootdir, 'buildscripts', 'rpm', 'makehuman')
  execDest = os.path.join(exportdir, 'makehuman', 'makehuman')
  if os.path.isfile(execDest):
    os.remove(execDest)
  shutil.copy(execFile, execDest)

  os.remove(os.path.join(exportdir, 'makehuman', 'blendertools', 'copy2blender.bat'))


  # Setup RPM environment
  for d in ['SRPMS', 'BUILD', 'SPECS', 'SOURCES', 'lib', 'RPMS/i386', 'RPMS/noarch']:
    if not os.path.isdir( os.path.join(homedir, 'rpms', d) ):
      os.makedirs( os.path.join(homedir, 'rpms', d) )

  subprocess.check_call(['rpm', '--initdb', '--dbpath', os.path.join(homedir, 'rpms', 'lib')])

  f = open(os.path.join(homedir, '.rpmmacros'), 'wb')
  f.write("%_topdir %(echo $HOME)/rpms")
  f.close()


  # Execute build
  if exportInfo.isRelease:
    os.environ["MH_PKG_NAME"] = package_name
  else:
    os.environ["MH_PKG_NAME"] = package_name + 'hg'
  if package_version is None:
    version = exportInfo.version.replace(" ", ".")
  else:
    version = package_version
  print "RPM PACKAGE VERSION: %s\n" % version
  os.environ["MH_VERSION"] = version
  os.environ["MH_EXPORT_PATH"] = exportdir
  print '\n\nBuilding RPM package "%s" of version "%s"\n\n' % (os.environ["MH_PKG_NAME"], version)
  subprocess.check_call(['bash', 'make_rpm.bash'])