def testUpdateManifestMain(self):
   ''' test the main function from update_manifest '''
   temp_filename = os.path.join(self._temp_dir, 'testUpdateManifestMain.json')
   try:
     argv = ['--bundle-version', '0',
             '--bundle-revision', '0',
             '--description', 'test bundle for update_manifest unit tests',
             '--bundle-name', 'test_bundle',
             '--stability', 'dev',
             '--recommended', 'no',
             '--manifest-file', temp_filename]
     update_manifest.main(argv)
   finally:
     RemoveFile(temp_filename)
示例#2
0
 def testUpdateManifestMain(self):
     ''' test the main function from update_manifest '''
     temp_filename = os.path.join(self._temp_dir,
                                  'testUpdateManifestMain.json')
     try:
         argv = [
             '--bundle-version', '0', '--bundle-revision', '0',
             '--description', 'test bundle for update_manifest unit tests',
             '--bundle-name', 'test_bundle', '--stability', 'dev',
             '--recommended', 'no', '--manifest-file', temp_filename
         ]
         update_manifest.main(argv)
     finally:
         RemoveFile(temp_filename)
示例#3
0
def MakeSdkTools(nacl_sdk_filename, sdk_tools_filename):
    '''Make the nacl_sdk and sdk_tools tarballs

  The nacl_sdk package contains these things:

  nacl_sdk/
    naclsdk(.bat)  - The main entry point for updating the SDK
    sdk_tools/
      sdk_update.py  - Performs the work in checking for updates
    python/
      python.exe  - (optional) python executable, shipped with Windows
      ... - other python files and directories
    sdk_cache/
      naclsdk_manifest.json  - manifest file with information about sdk_tools

  Args:
    nacl_sdk_filename: name of zipfile that the user directly downloads
    sdk_tools_filename: name of tarball that has the sdk_tools directory
  '''
    base_dir = os.path.abspath(os.path.dirname(__file__))
    base_dir_parent = os.path.dirname(base_dir)
    temp_dir = os.path.join(base_dir, NACL_SDK)
    if os.path.exists(temp_dir):
        shutil.rmtree(temp_dir)
    os.mkdir(temp_dir)
    for dir in ['sdk_tools', 'sdk_cache']:
        os.mkdir(os.path.join(temp_dir, dir))
    shutil.copy2(os.path.join(base_dir, 'naclsdk'), temp_dir)
    shutil.copy2(os.path.join(base_dir, 'naclsdk.bat'), temp_dir)
    with open(os.path.join(base_dir_parent, 'LICENSE'), "U") as source_file:
        text = source_file.read().replace("\n", "\r\n")
    with open(os.path.join(temp_dir, 'sdk_tools', 'LICENSE'),
              "wb") as dest_file:
        dest_file.write(text)

    tool_list = ['sdk_update.py', 'set_nacl_env.py']
    for tool in tool_list:
        shutil.copy2(os.path.join(base_dir, 'sdk_tools', tool),
                     os.path.join(temp_dir, 'sdk_tools'))
        py_compile.compile(os.path.join(temp_dir, 'sdk_tools', tool))

    update_manifest_options = [
        '--bundle-revision=%s' % sdk_update.MINOR_REV,
        '--bundle-version=%s' % sdk_update.MAJOR_REV,
        '--description=Native Client SDK Tools, revision %s.%s' %
        (sdk_update.MAJOR_REV, sdk_update.MINOR_REV),
        '--bundle-name=sdk_tools', '--recommended=yes', '--stability=stable',
        '--manifest-version=%s' % sdk_update.SDKManifest().MANIFEST_VERSION,
        '--manifest-file=%s' %
        os.path.join(temp_dir, 'sdk_cache', 'naclsdk_manifest.json')
    ]
    if 0 != update_manifest.main(update_manifest_options):
        raise Exception('update_manifest terminated abnormally.')
    ZipDirectory(temp_dir, nacl_sdk_filename)
    WriteTarFile(sdk_tools_filename, os.path.join(temp_dir, 'sdk_tools'), '')
    shutil.rmtree(temp_dir, ignore_errors=True)
示例#4
0
def MakeSdkTools(nacl_sdk_filename, sdk_tools_filename):
  '''Make the nacl_sdk and sdk_tools tarballs

  The nacl_sdk package contains these things:

  nacl_sdk/
    naclsdk(.bat)  - The main entry point for updating the SDK
    sdk_tools/
      sdk_update.py  - Performs the work in checking for updates
    python/
      python.exe  - (optional) python executable, shipped with Windows
      ... - other python files and directories
    sdk_cache/
      naclsdk_manifest.json  - manifest file with information about sdk_tools

  Args:
    nacl_sdk_filename: name of zipfile that the user directly downloads
    sdk_tools_filename: name of tarball that has the sdk_tools directory
  '''
  base_dir = os.path.abspath(os.path.dirname(__file__))
  base_dir_parent = os.path.dirname(base_dir)
  temp_dir = os.path.join(base_dir, NACL_SDK)
  if os.path.exists(temp_dir):
    shutil.rmtree(temp_dir)
  os.mkdir(temp_dir)
  for dir in ['sdk_tools', 'sdk_cache']:
    os.mkdir(os.path.join(temp_dir, dir))
  shutil.copy2(os.path.join(base_dir, 'naclsdk'), temp_dir)
  shutil.copy2(os.path.join(base_dir, 'naclsdk.bat'), temp_dir)
  with open(os.path.join(base_dir_parent, 'LICENSE'), "U") as source_file:
    text = source_file.read().replace("\n", "\r\n")
  with open(os.path.join(temp_dir, 'sdk_tools', 'LICENSE'), "wb") as dest_file:
    dest_file.write(text)

  tool_list = ['sdk_update.py', 'set_nacl_env.py']
  for tool in tool_list:
    shutil.copy2(os.path.join(base_dir, 'sdk_tools', tool),
                 os.path.join(temp_dir, 'sdk_tools'))
    py_compile.compile(os.path.join(temp_dir, 'sdk_tools', tool))

  update_manifest_options = [
       '--bundle-revision=%s' % sdk_update.MINOR_REV,
       '--bundle-version=%s' % sdk_update.MAJOR_REV,
       '--description=Native Client SDK Tools, revision %s.%s' % (
           sdk_update.MAJOR_REV, sdk_update.MINOR_REV),
       '--bundle-name=sdk_tools',
       '--recommended=yes',
       '--stability=stable',
       '--manifest-version=%s' % sdk_update.SDKManifest().MANIFEST_VERSION,
       '--manifest-file=%s' %
       os.path.join(temp_dir, 'sdk_cache', 'naclsdk_manifest.json')]
  if 0 != update_manifest.main(update_manifest_options):
    raise Exception('update_manifest terminated abnormally.')
  ZipDirectory(temp_dir, nacl_sdk_filename)
  WriteTarFile(sdk_tools_filename, os.path.join(temp_dir, 'sdk_tools'), '')
  shutil.rmtree(temp_dir, ignore_errors=True)
def ExtractInstaller(installer, outdir, bundle_name, nacl_sdk):
  '''Extract the SDK installer into a given directory

  If the outdir already exists, then this function deletes it

  Args:
    installer: full path of the SDK installer
    outdir: output directory where to extract the installer
    bundle_name: name of sdk bundle within outdir
    nacl_sdk: filename of nacl_sdk tarball

  Raises:
    OSError - if the outdir already exists
    CalledProcessError - if the extract operation fails
  '''

  annotator.Print('Extracting installer %s into %s' % (installer, outdir))

  if os.path.exists(outdir):
    RemoveDir(outdir)

  os.mkdir(outdir)

  if sys.platform == 'win32':
    zip_file = None
    try:
      zip_file = zipfile.ZipFile(nacl_sdk)
      zip_file.extractall(path=outdir)
    finally:
      if zip_file:
        zip_file.close()
  else:
    # Unfortunately, the zipfile module does not retain file permissions
    # when extracting executable scripts.  For now, just use the unzip
    # that comes with Linux and Mac.
    subprocess.check_call(['unzip', nacl_sdk], cwd=outdir)

  outdir = os.path.join(outdir, 'nacl_sdk')

  manifest_filename = os.path.join(outdir, 'test_manifest.json')
  update_manifest_options = [
       '--bundle-revision=1',
       '--bundle-version=2',
       '--description=installer_test bundle',
       '--%s-archive=file://%s' % (
           sdk_update.GetHostOS(),
           urllib.pathname2url(os.path.abspath(installer))),
       '--bundle-name=%s' % bundle_name,
       '--recommended=yes',
       '--stability=stable',
       '--manifest-version=1',
       '--manifest-file=%s' % manifest_filename]
  annotator.Print('Running update manifest with %s' % update_manifest_options)
  if 0 != update_manifest.main(update_manifest_options):
    raise Exception('update_manifest terminated abnormally.')

  naclsdk_options = [
       os.path.join(outdir,
                    'naclsdk.bat' if sys.platform == 'win32' else 'naclsdk'),
      '--manifest-url=file://%s' % urllib.pathname2url(manifest_filename),
      '--sdk-root-dir=%s' % outdir,
      '--user-data-dir=%s' % outdir,
      'update']
  annotator.Print('Running naclsdk with %s' % naclsdk_options)
  subprocess.check_call(naclsdk_options)
示例#6
0
def ExtractInstaller(installer, outdir, bundle_name, nacl_sdk):
    '''Extract the SDK installer into a given directory

  If the outdir already exists, then this function deletes it

  Args:
    installer: full path of the SDK installer
    outdir: output directory where to extract the installer
    bundle_name: name of sdk bundle within outdir
    nacl_sdk: filename of nacl_sdk tarball

  Raises:
    OSError - if the outdir already exists
    CalledProcessError - if the extract operation fails
  '''

    annotator.Print('Extracting installer %s into %s' % (installer, outdir))

    if os.path.exists(outdir):
        RemoveDir(outdir)

    os.mkdir(outdir)

    if sys.platform == 'win32':
        zip_file = None
        try:
            zip_file = zipfile.ZipFile(nacl_sdk)
            zip_file.extractall(path=outdir)
        finally:
            if zip_file:
                zip_file.close()
    else:
        # Unfortunately, the zipfile module does not retain file permissions
        # when extracting executable scripts.  For now, just use the unzip
        # that comes with Linux and Mac.
        subprocess.check_call(['unzip', nacl_sdk], cwd=outdir)

    outdir = os.path.join(outdir, 'nacl_sdk')

    manifest_filename = os.path.join(outdir, 'test_manifest.json')
    update_manifest_options = [
        '--bundle-revision=1', '--bundle-version=2',
        '--description=installer_test bundle',
        '--%s-archive=file://%s' %
        (sdk_update.GetHostOS(), urllib.pathname2url(
            os.path.abspath(installer))),
        '--bundle-name=%s' % bundle_name, '--recommended=yes',
        '--stability=stable', '--manifest-version=1',
        '--manifest-file=%s' % manifest_filename
    ]
    annotator.Print('Running update manifest with %s' %
                    update_manifest_options)
    if 0 != update_manifest.main(update_manifest_options):
        raise Exception('update_manifest terminated abnormally.')

    naclsdk_options = [
        os.path.join(outdir,
                     'naclsdk.bat' if sys.platform == 'win32' else 'naclsdk'),
        '--manifest-url=file://%s' % urllib.pathname2url(manifest_filename),
        '--sdk-root-dir=%s' % outdir,
        '--user-data-dir=%s' % outdir, 'update'
    ]
    annotator.Print('Running naclsdk with %s' % naclsdk_options)
    subprocess.check_call(naclsdk_options)
 def testPush(self):
   '''Test whether the push function does the right thing'''
   options = FakeOptions()
   argv = ['-g', options.gsutil, 'push']
   update_manifest.main(argv)
示例#8
0
 def testPush(self):
     '''Test whether the push function does the right thing'''
     options = FakeOptions()
     argv = ['-g', options.gsutil, 'push']
     update_manifest.main(argv)