fix pylint warnings
BUG=
Review URL: https://chromiumcodereview.appspot.com/10910101
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@155820 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/native_client_sdk/PRESUBMIT.py b/native_client_sdk/PRESUBMIT.py
index 1b711b9d..dc0b66c1 100644
--- a/native_client_sdk/PRESUBMIT.py
+++ b/native_client_sdk/PRESUBMIT.py
@@ -12,26 +12,15 @@
def CommonChecks(input_api, output_api):
output = []
disabled_warnings = [
+ 'F0401', # Unable to import module
'R0401', # Cyclic import
'W0613', # Unused argument
'E1103', # subprocess.communicate() generates these :(
+ 'R0201', # method could be function (doesn't reference self)
]
- black_list = [r'src/site_scons/.*',
- r'.*/decode_dump.py',
- r'src/build_tools/build_sdk.py',
- r'src/build_tools/buildbot_common.py',
- r'src/build_tools/buildbot_run.py',
- r'src/build_tools/build_utils.py',
- r'src/build_tools/build_updater.py',
- r'src/build_tools/manifest_util.py',
- r'src/build_tools/nacl*',
- r'src/build_tools/generate_make.py',
- r'src/build_tools/sdk_tools/sdk_update_main.py',
- r'src/build_tools/sdk_tools/sdk_update.py',
- r'src/project_templates',
- r'.*/update_manifest.py',
- r'.*/update_nacl_manifest.py',
- r'src/build_tools/tests/.*']
+ black_list = [r'src/build_tools/tests/.*',
+ r'src/site_scons/.*',
+ ]
canned = input_api.canned_checks
output.extend(canned.RunPylint(input_api, output_api, black_list=black_list,
disabled_warnings=disabled_warnings))
diff --git a/native_client_sdk/src/build_tools/build_sdk.py b/native_client_sdk/src/build_tools/build_sdk.py
index 4dff2cda..a9d9d0a 100755
--- a/native_client_sdk/src/build_tools/build_sdk.py
+++ b/native_client_sdk/src/build_tools/build_sdk.py
@@ -15,6 +15,7 @@
and whether it should upload an SDK to file storage (GSTORE)
"""
+# pylint: disable=W0621
# std python includes
import copy
diff --git a/native_client_sdk/src/build_tools/build_updater.py b/native_client_sdk/src/build_tools/build_updater.py
index efe610a..8283790 100755
--- a/native_client_sdk/src/build_tools/build_updater.py
+++ b/native_client_sdk/src/build_tools/build_updater.py
@@ -11,10 +11,8 @@
import buildbot_common
import build_utils
-import cStringIO
import optparse
import os
-import re
import sys
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -111,9 +109,9 @@
SDK_UPDATE_MAIN = os.path.join(out_dir,
'nacl_sdk/sdk_tools/sdk_update_main.py')
- file = open(SDK_UPDATE_MAIN, 'r').read().replace(
+ contents = open(SDK_UPDATE_MAIN, 'r').read().replace(
'{REVISION}', str(revision_number))
- open(SDK_UPDATE_MAIN, 'w').write(file)
+ open(SDK_UPDATE_MAIN, 'w').write(contents)
def BuildUpdater(out_dir, revision_number=None):
@@ -131,7 +129,7 @@
buildbot_common.RemoveDir(os.path.join(out_dir, 'nacl_sdk'))
updater_files = MakeUpdaterFilesAbsolute(out_dir)
- out_files = [out_file for in_file, out_file in updater_files]
+ out_files = [out_file for _, out_file in updater_files]
CopyFiles(updater_files)
UpdateRevisionNumber(out_dir, revision_number)
diff --git a/native_client_sdk/src/build_tools/build_utils.py b/native_client_sdk/src/build_tools/build_utils.py
index c0707ed6..b43b393 100644
--- a/native_client_sdk/src/build_tools/build_utils.py
+++ b/native_client_sdk/src/build_tools/build_utils.py
@@ -16,6 +16,7 @@
import subprocess
import sys
+# pylint: disable=E0602
# Reuse last change utility code.
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -83,18 +84,18 @@
# If there are permission problems, they will be caught by the exception
# handler around the os.makedirs call.
os.remove(abs_path)
- except:
+ except OSError:
pass
try:
os.makedirs(abs_path, mode)
- except OSError, (os_errno, os_strerr):
+ except OSError, e:
# If the error is anything but EEXIST (file already exists), then print an
# informative message and re-raise. It is not and error if the directory
# already exists.
+ (os_errno, os_strerr) = e
if os_errno != errno.EEXIST:
print 'ForceMakeDirs(%s, 0%o) FAILED: %s' % (abs_path, mode, os_strerr)
raise
- pass
# patch version 2.6 doesn't work. Most of our Linux distros use patch 2.6.
@@ -289,17 +290,17 @@
.replace('${REVISION}', str(SVNRevision()))
.replace('${DATE}', str(datetime.date.today())))
-def CleanDirectory(dir):
+def CleanDirectory(dirname):
'''Cleans all the contents of a given directory.
This works even when there are Windows Junctions in the directory
Args:
- dir: The directory to clean
+ dirname: The directory to clean
'''
if sys.platform != 'win32':
- shutil.rmtree(dir, ignore_errors=True)
+ shutil.rmtree(dirname, ignore_errors=True)
else:
# Intentionally ignore return value since a directory might be in use.
- subprocess.call(['rmdir', '/Q', '/S', dir],
+ subprocess.call(['rmdir', '/Q', '/S', dirname],
env=os.environ.copy(),
shell=True)
diff --git a/native_client_sdk/src/build_tools/buildbot_common.py b/native_client_sdk/src/build_tools/buildbot_common.py
index 636db8f..cef170fd7 100644
--- a/native_client_sdk/src/build_tools/buildbot_common.py
+++ b/native_client_sdk/src/build_tools/buildbot_common.py
@@ -62,7 +62,7 @@
sys.stderr.flush()
-def CopyDir(src, dst, excludes=['.svn', '*/.svn']):
+def CopyDir(src, dst, excludes=('.svn', '*/.svn')):
"""Recursively copy a directory using."""
args = ['-r', src, dst]
for exc in excludes:
diff --git a/native_client_sdk/src/build_tools/generate_make.py b/native_client_sdk/src/build_tools/generate_make.py
index 906df36..4db616b 100755
--- a/native_client_sdk/src/build_tools/generate_make.py
+++ b/native_client_sdk/src/build_tools/generate_make.py
@@ -4,11 +4,9 @@
# found in the LICENSE file.
import buildbot_common
-import make_rules
import optparse
import os
import sys
-
from make_rules import MakeRules, SetVar, GenerateCleanRules, GenerateNMFRules
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -85,7 +83,7 @@
return platforms
-def GenerateToolDefaults(desc, tools):
+def GenerateToolDefaults(tools):
defaults = ''
for tool in tools:
defaults += MakeRules(tool).BuildDefaults()
@@ -94,11 +92,10 @@
def GenerateSettings(desc, tools):
settings = SetVar('VALID_TOOLCHAINS', tools)
- settings+= 'TOOLCHAIN?=%s\n\n' % tools[0]
+ settings += 'TOOLCHAIN?=%s\n\n' % tools[0]
for target in desc['TARGETS']:
project = target['NAME']
macro = project.upper()
- srcs = GetSourcesDict(target['SOURCES'])
c_flags = target.get('CCFLAGS')
cc_flags = target.get('CXXFLAGS')
@@ -114,12 +111,10 @@
def GenerateRules(desc, tools):
- all_targets = []
- clean = []
rules = '#\n# Per target object lists\n#\n'
#Determine which projects are in the NMF files.
- main = None
+ executable = None
dlls = []
project_list = []
glibc_rename = []
@@ -130,7 +125,7 @@
project_list.append(project)
srcs = GetSourcesDict(target['SOURCES'])
if ptype == 'MAIN':
- main = project
+ executable = project
if ptype == 'SO':
dlls.append(project)
for arch in ['x86_32', 'x86_64']:
@@ -152,15 +147,12 @@
project = target['NAME']
ptype = target['TYPE']
srcs = GetSourcesDict(target['SOURCES'])
- objs = GetProjectObjects(srcs)
defs = target.get('DEFINES', [])
incs = target.get('INCLUDES', [])
libs = target.get('LIBS', [])
- lpaths = target.get('LIBPATHS', [])
- ipaths = target.get('INCPATHS', [])
makeobj.SetProject(project, ptype, defs=defs, incs=incs, libs=libs)
- if ptype == 'main':
- rules += makeobj.GetPepperPlugin()
+ if ptype == 'main':
+ rules += makeobj.GetPepperPlugin()
for arch in arches:
makeobj.SetArch(arch)
for src in srcs.get('.c', []):
@@ -170,8 +162,8 @@
rules += '\n'
rules += makeobj.BuildObjectList()
rules += makeobj.BuildLinkRule()
- if main:
- rules += GenerateNMFRules(tc, main, dlls, cfg, arches)
+ if executable:
+ rules += GenerateNMFRules(tc, executable, dlls, cfg, arches)
rules += GenerateCleanRules(tools, configs)
rules += '\nall: $(ALL_TARGETS)\n'
@@ -182,11 +174,9 @@
def GenerateReplacements(desc, tools):
# Generate target settings
- plats = GetPlatforms(desc['TOOLS'], tools)
-
settings = GenerateSettings(desc, tools)
- tool_def = GenerateToolDefaults(desc, tools)
- all_targets, rules = GenerateRules(desc, tools)
+ tool_def = GenerateToolDefaults(tools)
+ _, rules = GenerateRules(desc, tools)
prelaunch = desc.get('LAUNCH', '')
prerun = desc.get('PRE', '')
@@ -241,12 +231,12 @@
sys.stderr.write(text + '\n')
-def ValidateFormat(src, format, ErrorMsg=ErrorMsgFunc):
+def ValidateFormat(src, dsc_format, ErrorMsg=ErrorMsgFunc):
failed = False
# Verify all required keys are there
- for key in format:
- (exp_type, exp_value, required) = format[key]
+ for key in dsc_format:
+ (exp_type, exp_value, required) = dsc_format[key]
if required and key not in src:
ErrorMsg('Missing required key %s.' % key)
failed = True
@@ -254,12 +244,12 @@
# For each provided key, verify it's valid
for key in src:
# Verify the key is known
- if key not in format:
+ if key not in dsc_format:
ErrorMsg('Unexpected key %s.' % key)
failed = True
continue
- exp_type, exp_value, required = format[key]
+ exp_type, exp_value, required = dsc_format[key]
value = src[key]
# Verify the key is of the expected type
@@ -443,9 +433,9 @@
FindAndCopyFiles(headers, srcroot, srcdirs, header_out_dir)
if IsNexe(desc):
- template=os.path.join(SCRIPT_DIR, 'template.mk')
+ template = os.path.join(SCRIPT_DIR, 'template.mk')
else:
- template=os.path.join(SCRIPT_DIR, 'library.mk')
+ template = os.path.join(SCRIPT_DIR, 'library.mk')
tools = []
for tool in desc['TOOLS']:
diff --git a/native_client_sdk/src/build_tools/manifest_util.py b/native_client_sdk/src/build_tools/manifest_util.py
index 57cab4f..4a479d8 100644
--- a/native_client_sdk/src/build_tools/manifest_util.py
+++ b/native_client_sdk/src/build_tools/manifest_util.py
@@ -106,6 +106,7 @@
def __init__(self, host_os_name):
""" Create a new archive for the given host-os name. """
+ super(Archive, self).__init__()
self['host_os'] = host_os_name
def CopyFrom(self, src):
@@ -141,7 +142,7 @@
elif not len(checksum):
raise Error('Archive "%s" has an empty checksum dict' % host_os)
# Verify that all key names are valid.
- for key, val in self.iteritems():
+ for key in self:
if key not in VALID_ARCHIVE_KEYS:
raise Error('Archive "%s" has invalid attribute "%s"' % (host_os, key))
@@ -177,9 +178,9 @@
return
return self.__setitem__(name, value)
- def GetChecksum(self, type='sha1'):
+ def GetChecksum(self, hash_type='sha1'):
"""Returns a given cryptographic checksum of the archive"""
- return self['checksum'][type]
+ return self['checksum'][hash_type]
class Bundle(dict):
@@ -227,13 +228,13 @@
"""
self.CopyFrom(json.loads(json_string))
- def CopyFrom(self, dict):
+ def CopyFrom(self, source):
"""Update the content of the bundle by copying values from the given
dictionary.
Args:
- dict: The dictionary whose values must be copied to the bundle."""
- for key, value in dict.items():
+ source: The dictionary whose values must be copied to the bundle."""
+ for key, value in source.items():
if key == ARCHIVES_KEY:
archives = []
for a in value:
@@ -270,7 +271,7 @@
'Bundle "%s" has invalid recommended field: "%s"' %
(self[NAME_KEY], self['recommended']))
# Verify that all key names are valid.
- for key, val in self.iteritems():
+ for key in self:
if key not in VALID_BUNDLES_KEYS:
raise Error('Bundle "%s" has invalid attribute "%s"' %
(self[NAME_KEY], key))
@@ -393,7 +394,7 @@
raise Error("Manifest version too high: %s" %
self._manifest_data["manifest_version"])
# Verify that all key names are valid.
- for key, val in self._manifest_data.iteritems():
+ for key in self._manifest_data:
if key not in VALID_MANIFEST_KEYS:
raise Error('Manifest has invalid attribute "%s"' % key)
# Validate each bundle
@@ -412,7 +413,8 @@
bundles = [bundle for bundle in self._manifest_data[BUNDLES_KEY]
if bundle[NAME_KEY] == name]
if len(bundles) > 1:
- WarningPrint("More than one bundle with name '%s' exists." % name)
+ sys.stderr.write("WARNING: More than one bundle with name"
+ "'%s' exists.\n" % name)
return bundles[0] if len(bundles) > 0 else None
def GetBundles(self):
diff --git a/native_client_sdk/src/build_tools/sdk_tools/sdk_update.py b/native_client_sdk/src/build_tools/sdk_tools/sdk_update.py
index ac423a5e..45c72f4a 100755
--- a/native_client_sdk/src/build_tools/sdk_tools/sdk_update.py
+++ b/native_client_sdk/src/build_tools/sdk_tools/sdk_update.py
@@ -15,7 +15,7 @@
import os
import subprocess
-from sdk_update_common import *
+from sdk_update_common import RenameDir, RemoveDir, Error
import sys
import tempfile
@@ -83,7 +83,7 @@
# Failed for some reason, move the old dir back.
try:
RenameDir(temp_sdktools, SDK_TOOLS_DIR)
- except:
+ except Error:
# Not much to do here. sdk_tools won't exist, but sdk_tools_update
# should. Hopefully running the batch script again will move
# sdk_tools_update -> sdk_tools and it will work this time...
@@ -104,7 +104,7 @@
return subprocess.call([NACLSDK_SHELL_SCRIPT] + args)
else:
return subprocess.call(MakeSdkUpdateMainCmd(args))
-
+
if __name__ == '__main__':
sys.exit(main())
diff --git a/native_client_sdk/src/build_tools/sdk_tools/sdk_update_main.py b/native_client_sdk/src/build_tools/sdk_tools/sdk_update_main.py
index 8b18794..0a6bf61 100755
--- a/native_client_sdk/src/build_tools/sdk_tools/sdk_update_main.py
+++ b/native_client_sdk/src/build_tools/sdk_tools/sdk_update_main.py
@@ -11,15 +11,18 @@
import manifest_util
import optparse
import os
-from sdk_update_common import *
+from sdk_update_common import RenameDir, RemoveDir, Error
import shutil
import subprocess
import sys
import tempfile
+# when pylint runs the third_party module is the one from depot_tools
+# pylint: disable=E0611
from third_party import fancy_urllib
import urllib2
import urlparse
+# pylint: disable=C0301
#------------------------------------------------------------------------------
# Constants
@@ -300,7 +303,7 @@
WarningPrint('source \''+string+'\' already exists in config.')
return
try:
- url_stream = UrlOpen(string)
+ UrlOpen(string)
except urllib2.URLError:
WarningPrint('Unable to fetch manifest URL \'%s\'. Exiting...' % string)
return
@@ -371,7 +374,7 @@
DebugPrint("Running List command with: %s, %s" %(options, argv))
parser = optparse.OptionParser(usage=Info.__doc__)
- (info_options, args) = parser.parse_args(argv)
+ (_, args) = parser.parse_args(argv)
if not args:
parser.print_help()
@@ -436,7 +439,7 @@
'-r', '--revision', dest='revision',
default=False, action='store_true',
help='display revision numbers')
- (list_options, args) = parser.parse_args(argv)
+ (list_options, _) = parser.parse_args(argv)
manifest = LoadManifestFromURLs([options.manifest_url] + config.GetSources())
manifest_path = os.path.join(options.user_data_dir, options.manifest_filename)
@@ -447,7 +450,6 @@
InfoPrint(' I: installed\n *: update available\n')
for bundle in manifest.GetBundles():
local_bundle = local_manifest.GetBundle(bundle.name)
- installed = local_bundle is not None
needs_update = local_bundle and local_manifest.BundleNeedsUpdate(bundle)
if needs_update:
any_bundles_need_update = True
diff --git a/native_client_sdk/src/build_tools/sdk_tools/update_manifest.py b/native_client_sdk/src/build_tools/sdk_tools/update_manifest.py
deleted file mode 100755
index f0af47d..0000000
--- a/native_client_sdk/src/build_tools/sdk_tools/update_manifest.py
+++ /dev/null
@@ -1,463 +0,0 @@
-#!/usr/bin/env python
-# Copyright (c) 2012 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-'''Utility to update the SDK manifest file in the build_tools directory'''
-
-
-import optparse
-import os
-import re
-import string
-import subprocess
-import sys
-import urllib2
-
-# Create the various paths of interest
-SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
-SDK_SRC_DIR = os.path.dirname(os.path.dirname(SCRIPT_DIR))
-SRC_DIR = os.path.dirname(os.path.dirname(SDK_SRC_DIR))
-NACL_DIR = os.path.join(SRC_DIR, 'native_client')
-
-sys.path.append(os.path.join(SDK_SRC_DIR, 'tools'))
-sys.path.append(os.path.join(NACL_DIR, 'build'))
-
-import sdk_update
-
-HELP = '''"Usage: %prog [-b bundle] [options]"
-
-Actions for particular bundles:
- sdk_tools: Upload the most recently built nacl_sdk.zip and sdk_tools.tgz
- files to the server and update the manifest file
- pepper_??: Download the latest pepper builds off the appropriate branch,
- upload these files to the appropriate location on the server, and
- update the manifest file.
- <others>: Only update manifest file -- you'll need to upload the file yourself
-'''
-
-# Map option keys to manifest attribute key. Option keys are used to retrieve
-# option values from cmd-line options. Manifest attribute keys label the
-# corresponding value in the manifest object.
-OPTION_KEY_MAP = {
- # option key manifest attribute key
- 'bundle_desc_url': 'desc_url',
- 'bundle_revision': sdk_update.REVISION_KEY,
- 'bundle_version': sdk_update.VERSION_KEY,
- 'desc': 'description',
- 'recommended': 'recommended',
- 'stability': 'stability',
- }
-# Map options keys to platform key, as stored in the bundle.
-OPTION_KEY_TO_PLATFORM_MAP = {
- 'mac_arch_url': 'mac',
- 'win_arch_url': 'win',
- 'linux_arch_url': 'linux',
- 'all_arch_url': 'all',
- }
-
-NACL_SDK_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(
- os.path.abspath(__file__))))
-
-BUILD_TOOLS_OUT = os.path.join(NACL_SDK_ROOT, 'scons-out', 'build', 'obj',
- 'build_tools')
-
-BUNDLE_SDK_TOOLS = 'sdk_tools'
-BUNDLE_PEPPER_MATCHER = re.compile('^pepper_([0-9]+)$')
-IGNORE_OPTIONS = set([
- 'archive_id', 'gsutil', 'manifest_file', 'upload', 'root_url'])
-
-
-class Error(Exception):
- '''Generic error/exception for update_manifest module'''
- pass
-
-
-def UpdateBundle(bundle, options):
- ''' Update the bundle per content of the options.
-
- Args:
- options: options data. Attributes that are used are also deleted from
- options.'''
- # Check, set and consume individual bundle options.
- for option_key, attribute_key in OPTION_KEY_MAP.iteritems():
- option_val = getattr(options, option_key, None)
- if option_val is not None:
- bundle[attribute_key] = option_val
- delattr(options, option_key)
- # Validate what we have so far; we may just avoid going through a lengthy
- # download, just to realize that some other trivial stuff is missing.
- bundle.Validate()
- # Check and consume archive-url options.
- for option_key, host_os in OPTION_KEY_TO_PLATFORM_MAP.iteritems():
- platform_url = getattr(options, option_key, None)
- if platform_url is not None:
- bundle.UpdateArchive(host_os, platform_url)
- delattr(options, option_key)
-
-
-class UpdateSDKManifest(sdk_update.SDKManifest):
- '''Adds functions to SDKManifest that are only used in update_manifest'''
-
- def _ValidateBundleName(self, name):
- ''' Verify that name is a valid bundle.
-
- Args:
- name: the proposed name for the bundle.
-
- Return:
- True if the name is valid for a bundle, False otherwise.'''
- valid_char_set = '()-_.%s%s' % (string.ascii_letters, string.digits)
- name_len = len(name)
- return (name_len > 0 and all(c in valid_char_set for c in name))
-
- def _UpdateManifestVersion(self, options):
- ''' Update the manifest version number from the options
-
- Args:
- options: options data containing an attribute self.manifest_version '''
- version_num = int(options.manifest_version)
- self._manifest_data['manifest_version'] = version_num
- del options.manifest_version
-
- def _UpdateBundle(self, options):
- ''' Update or setup a bundle from the options.
-
- Args:
- options: options data containing at least a valid bundle_name
- attribute. Other relevant bundle attributes will also be
- used (and consumed) by this function. '''
- # Get and validate the bundle name
- if not self._ValidateBundleName(options.bundle_name):
- raise Error('Invalid bundle name: "%s"' % options.bundle_name)
- bundle_name = options.bundle_name
- del options.bundle_name
- # Get the corresponding bundle, or create it.
- bundle = self.GetBundle(bundle_name)
- if not bundle:
- bundle = sdk_update.Bundle(bundle_name)
- self.SetBundle(bundle)
- UpdateBundle(bundle, options)
-
- def _VerifyAllOptionsConsumed(self, options, bundle_name):
- ''' Verify that all the options have been used. Raise an exception if
- any valid option has not been used. Returns True if all options have
- been consumed.
-
- Args:
- options: the object containing the remaining unused options attributes.
- bundle_name: The name of the bundle, or None if it's missing.'''
- # Any option left in the list should have value = None
- for key, val in options.__dict__.items():
- if val != None and key not in IGNORE_OPTIONS:
- if bundle_name:
- raise Error('Unused option "%s" for bundle "%s"' % (key, bundle_name))
- else:
- raise Error('No bundle name specified')
- return True
-
- def UpdateManifest(self, options):
- ''' Update the manifest object with values from the command-line options
-
- Args:
- options: options object containing attribute for the command-line options.
- Note that all the non-trivial options are consumed.
- '''
- # Go over all the options and update the manifest data accordingly.
- # Valid options are consumed as they are used. This gives us a way to
- # verify that all the options are used.
- if options.manifest_version is not None:
- self._UpdateManifestVersion(options)
- # Keep a copy of bundle_name, which will be consumed by UpdateBundle, for
- # use in _VerifyAllOptionsConsumed below.
- bundle_name = options.bundle_name
- if bundle_name is not None:
- self._UpdateBundle(options)
- self._VerifyAllOptionsConsumed(options, bundle_name)
- self._ValidateManifest()
-
- def ValidateManifestLinks(self):
- '''Validates all the links in the manifest file and throws if one is bad'''
- valid = True
- for bundle in self._manifest_data[sdk_update.BUNDLES_KEY]:
- for archive in bundle.GetArchives():
- stream = None
- try:
- print "Checking size of data at link: %s" % archive.GetUrl()
- stream = urllib2.urlopen(archive.GetUrl())
- server_size = int(stream.info()[sdk_update.HTTP_CONTENT_LENGTH])
- if server_size != archive.GetSize():
- sys.stderr.write('Size mismatch for %s. Expected %s but got %s\n' %
- (archive.GetUrl(), archive.GetSize(), server_size))
- sys.stderr.flush()
- valid = False
- finally:
- if stream:
- stream.close()
- if not valid:
- raise Error('Files on server do not match the manifest file')
-
-
-class GsUtil(object):
- def __init__(self, gsutil):
- '''gsutil is the path to the gsutil executable'''
- self.gsutil = gsutil
- self.root = 'gs://nativeclient-mirror/nacl/nacl_sdk'
-
- def GetURI(self, path):
- '''Return the full gs:// URI for a given relative path'''
- return '/'.join([self.root, path])
-
- def Run(self, command):
- '''Runs gsutil with a given argument list and returns exit status'''
- args = [self.gsutil] + command
- print 'GSUtil.Run(%s)' % args
- sys.stdout.flush()
- return subprocess.call(args)
-
- def CheckIfExists(self, path):
- '''Check whether a given path exists on commondatastorage
-
- Args:
- path: path relative to SDK root directory on the server
-
- Returns: True if it exists, False if it does not'''
- # todo(mball): Be a little more intelligent about this check and compare
- # the output strings against expected values
- return self.Run(['ls', self.GetURI(path)]) == 0
-
- def Copy(self, source, destination):
- '''Copies a given source file to a destination path and makes it readable
-
- Args:
- source: path to source file on local filesystem
- destination: path to destination, relative to root directory'''
- args = ['cp', '-a', 'public-read', source, self.GetURI(destination)]
- if self.Run(args) != 0:
- raise Error('Unable to copy %s to %s' % (source, destination))
-
-
-class UpdateSDKManifestFile(sdk_update.SDKManifestFile):
- '''Adds functions to SDKManifestFile that are only used in update_manifest'''
-
- def __init__(self, options):
- '''Create a new SDKManifest object with default contents.
-
- If |json_filepath| is specified, and it exists, its contents are loaded and
- used to initialize the internal manifest.
-
- Args:
- json_filepath: path to json file to read/write, or None to write a new
- manifest file to stdout.
- '''
- # Strip-off all the I/O-based options that do not relate to bundles
- self._json_filepath = options.manifest_file
- self.gsutil = GsUtil(options.gsutil)
- self.options = options
- self._manifest = UpdateSDKManifest()
- if self._json_filepath:
- self._LoadFile()
-
- def _HandleSDKTools(self):
- '''Handles the sdk_tools bundle'''
- # General sanity checking of parameters
- SDK_TOOLS_FILES = ['sdk_tools.tgz', 'nacl_sdk.zip']
- options = self.options
- if options.bundle_version is None:
- options.bundle_version = sdk_update.MAJOR_REV
- if options.bundle_version != sdk_update.MAJOR_REV:
- raise Error('Specified version (%s) does not match MAJOR_REV (%s)' %
- (options.bundle_version, sdk_update.MAJOR_REV))
- if options.bundle_revision is None:
- options.bundle_revision = sdk_update.MINOR_REV
- if options.bundle_revision != sdk_update.MINOR_REV:
- raise Error('Specified revision (%s) does not match MINOR_REV (%s)' %
- (options.bundle_revision, sdk_update.MINOR_REV))
- version = '%s.%s' % (options.bundle_version, options.bundle_revision)
- # Update the remaining options
- if options.desc is None:
- options.desc = ('Native Client SDK Tools, revision %s.%s' %
- (options.bundle_version, options.bundle_revision))
- options.recommended = options.recommended or 'yes'
- options.stability = options.stability or 'stable'
- if options.upload:
- # Check whether the tools already exist
- for name in SDK_TOOLS_FILES:
- path = '/'.join([version, name])
- if self.gsutil.CheckIfExists(path):
- raise Error('File already exists at %s' % path)
- # Upload the tools files to the server
- for name in SDK_TOOLS_FILES:
- source = os.path.join(BUILD_TOOLS_OUT, name)
- destination = '/'.join([version, name])
- self.gsutil.Copy(source, destination)
- url = '/'.join([options.root_url, version, 'sdk_tools.tgz'])
- options.mac_arch_url = options.mac_arch_url or url
- options.linux_arch_url = options.linux_arch_url or url
- options.win_arch_url = options.win_arch_url or url
-
- def _HandlePepper(self):
- '''Handles the pepper bundles'''
- options = self.options
- match = BUNDLE_PEPPER_MATCHER.match(options.bundle_name)
- if match is not None:
- options.bundle_version = int(match.group(1))
- if options.bundle_version is None:
- raise Error('Need to specify a bundle version')
- if options.bundle_revision is None:
- raise Error('Need to specify a bundle revision')
- if options.bundle_name == 'pepper':
- self.options.bundle_name = 'pepper_%s' % options.bundle_version
- if options.desc is None:
- options.desc = ('Chrome %s bundle, revision %s' %
- (options.bundle_version, options.bundle_revision))
- root_url = options.root_url
- if options.archive_id:
- # Support archive names like trunk.113440 or 17.0.963.3, which is how
- # the Chrome builders archive things.
- root_url = '/'.join([root_url, options.archive_id])
- else:
- # This is the old archive naming scheme
- root_url = '%s/pepper_%s_%s' % (root_url, options.bundle_version,
- options.bundle_revision)
- options.mac_arch_url = '/'.join([root_url, 'naclsdk_mac.bz2'])
- options.linux_arch_url = '/'.join([root_url, 'naclsdk_linux.bz2'])
- options.win_arch_url = '/'.join([root_url, 'naclsdk_win.bz2'])
-
- def HandleBundles(self):
- '''Handles known bundles by automatically uploading files'''
- bundle_name = self.options.bundle_name
- print 'bundle_name=' + bundle_name
- if bundle_name == BUNDLE_SDK_TOOLS:
- self._HandleSDKTools()
- elif bundle_name.startswith('pepper'):
- self._HandlePepper()
-
- def UpdateWithOptions(self):
- ''' Update the manifest file with the given options. Create the manifest
- if it doesn't already exists. Raises an Error if the manifest doesn't
- validate after updating.
-
- Args:
- options: option data'''
- # UpdateManifest does not know how to deal with file-related options
- self._manifest.UpdateManifest(self.options)
- self.WriteFile()
-
-
-def CommandPush(options, args, manifest_file):
- '''Check the manifest file and push it to the server if it's okay'''
- print 'Running Push with options=%s and args=%s' % (options, args)
- manifest = manifest_file._manifest
- manifest.UpdateManifest(options)
- print 'Validating links within manifest file'
- manifest.ValidateManifestLinks()
- print 'Copying manifest file to server'
- manifest_file.gsutil.Copy(options.manifest_file, 'naclsdk_manifest.json')
-
-
-def main(argv):
- '''Main entry for update_manifest.py'''
-
- buildtools_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
- parser = optparse.OptionParser(usage=HELP)
-
- # Setup options
- parser.add_option(
- '-a', '--archive-id', dest='archive_id',
- default=None,
- help='Archive identifier, produced by the Chromium builders; string '
- 'like "trunk.113440" or "17.0.963.3". Used with --root-url to '
- 'build the full archive URL. If not set the archive id defaults to '
- '"pepper_<version>_<revision>"')
- parser.add_option(
- '-b', '--bundle-version', dest='bundle_version',
- type='int',
- default=None,
- help='Required: Version number for the bundle.')
- parser.add_option(
- '-B', '--bundle-revision', dest='bundle_revision',
- type='int',
- default=None,
- help='Required: Revision number for the bundle.')
- parser.add_option(
- '-d', '--description', dest='desc',
- default=None,
- help='Required: Description for this bundle.')
- parser.add_option(
- '-f', '--manifest-file', dest='manifest_file',
- default=os.path.join(buildtools_dir, 'json',
- sdk_update.MANIFEST_FILENAME),
- help='location of manifest file to read and update')
- parser.add_option(
- '-g', '--gsutil', dest='gsutil',
- default='gsutil', help='location of gsutil tool for uploading bundles')
- parser.add_option(
- '-L', '--linux-archive', dest='linux_arch_url',
- default=None,
- help='URL for the Linux archive.')
- parser.add_option(
- '-M', '--mac-archive', dest='mac_arch_url',
- default=None,
- help='URL for the Mac archive.')
- parser.add_option(
- '-n', '--bundle-name', dest='bundle_name',
- default=None,
- help='Required: Name of the bundle.')
- parser.add_option(
- '-r', '--recommended', dest='recommended',
- choices=sdk_update.YES_NO_LITERALS,
- default=None,
- help='Required: whether this bundle is recommended. One of "yes" or "no"')
- parser.add_option(
- '-R', '--root-url', dest='root_url',
- default='http://commondatastorage.googleapis.com/nativeclient-mirror/'
- 'nacl/nacl_sdk',
- help='Root url for uploading')
- parser.add_option(
- '-s', '--stability', dest='stability',
- choices=sdk_update.STABILITY_LITERALS,
- default=None,
- help='Required: Stability for this bundle; one of. '
- '"obsolete", "post_stable", "stable", "beta", "dev", "canary".')
- parser.add_option(
- '-u', '--desc-url', dest='bundle_desc_url',
- default=None,
- help='Optional: URL to follow to read additional bundle info.')
- parser.add_option(
- '-U', '--upload', dest='upload', default=False, action='store_true',
- help='Indicates whether to upload bundle to server')
- parser.add_option(
- '-v', '--manifest-version', dest='manifest_version',
- type='int',
- default=None,
- help='Required for new manifest files: '
- 'Version number for the manifest.')
- parser.add_option(
- '-W', '--win-archive', dest='win_arch_url',
- default=None,
- help='URL for the Windows archive.')
-
- # Parse options and arguments and check.
- (options, args) = parser.parse_args(argv)
- manifest_file = UpdateSDKManifestFile(options)
- if len(args) == 0:
- manifest_file.HandleBundles()
- manifest_file.UpdateWithOptions()
- return 0
-
- COMMANDS = {
- 'push': CommandPush
- }
- def CommandUnknown(options, args, manifest_file):
- raise Error("Unknown command %s" % args[0])
- try:
- COMMANDS.get(args[0], CommandUnknown)(options, args, manifest_file)
- except Error as error:
- print "Error: %s" % error
- return 1
- return 0
-
-
-if __name__ == '__main__':
- sys.exit(main(sys.argv[1:]))
diff --git a/native_client_sdk/src/build_tools/tests/test_all.py b/native_client_sdk/src/build_tools/tests/test_all.py
index 10fce62..945f02bb 100755
--- a/native_client_sdk/src/build_tools/tests/test_all.py
+++ b/native_client_sdk/src/build_tools/tests/test_all.py
@@ -8,7 +8,7 @@
TEST_MODULES = [
'test_auto_update_sdktools',
- 'test_update_manifest'
+ 'test_update_nacl_manifest'
]
def main():
diff --git a/native_client_sdk/src/build_tools/tests/test_update_manifest.py b/native_client_sdk/src/build_tools/tests/test_update_nacl_manifest.py
similarity index 100%
rename from native_client_sdk/src/build_tools/tests/test_update_manifest.py
rename to native_client_sdk/src/build_tools/tests/test_update_nacl_manifest.py
diff --git a/native_client_sdk/src/build_tools/update_nacl_manifest.py b/native_client_sdk/src/build_tools/update_nacl_manifest.py
index 73638342..9f2a09a 100755
--- a/native_client_sdk/src/build_tools/update_nacl_manifest.py
+++ b/native_client_sdk/src/build_tools/update_nacl_manifest.py
@@ -7,6 +7,9 @@
in manifest.
"""
+# pylint is convinced the email module is missing attributes
+# pylint: disable=E1101
+
import buildbot_common
import csv
import cStringIO
@@ -92,6 +95,7 @@
class Delegate(object):
"""Delegate all external access; reading/writing to filesystem, gsutil etc."""
+
def GetRepoManifest(self):
"""Read the manifest file from the NaCl SDK repository.
@@ -157,7 +161,6 @@
effect is that text in stdin is copied to |dest|."""
raise NotImplementedError()
-
def Print(self, *args):
"""Print a message."""
raise NotImplementedError()
@@ -165,6 +168,7 @@
class RealDelegate(Delegate):
def __init__(self, dryrun=False, gsutil=None):
+ super(RealDelegate, self).__init__()
self.dryrun = dryrun
if gsutil:
self.gsutil = gsutil
@@ -313,6 +317,7 @@
'canary'). |archives| is a list of archive URLs."""
version = None
skipped_versions = []
+ channel = ''
while True:
try:
version, channel = shared_version_generator.next()
diff --git a/native_client_sdk/src/project_templates/init_project.py b/native_client_sdk/src/project_templates/init_project.py
index 12dd3c7..0201fa7 100755
--- a/native_client_sdk/src/project_templates/init_project.py
+++ b/native_client_sdk/src/project_templates/init_project.py
@@ -279,6 +279,7 @@
self.__is_c_project = is_c_project
self.__is_vs_project = is_vs_project
self.__project_files = []
+ self.__project_dir = None
self.__project_name = project_name
self.__project_location = project_location
self.__nacl_platform = nacl_platform
diff --git a/native_client_sdk/src/project_templates/init_project_test.py b/native_client_sdk/src/project_templates/init_project_test.py
index 1fa2e09..ae1d0b2 100755
--- a/native_client_sdk/src/project_templates/init_project_test.py
+++ b/native_client_sdk/src/project_templates/init_project_test.py
@@ -87,6 +87,13 @@
class TestProjectInitializer(unittest.TestCase):
"""Class for test cases to cover public interface of ProjectInitializer."""
+ def __init__(self):
+ unittest.TestCase.__init__(self)
+ self.os_mock = None
+ self.fileinput_mock = None
+ self.sys_mock = None
+ self.shutil_mock = None
+
def setUp(self):
self.script_dir = os.path.abspath(os.path.dirname(__file__))
self.nacl_src_dir = os.getenv('NACL_SDK_ROOT', None)