X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/83acfa97bdd34983d284b199e0c67a411aa7580e..95d1231a25637c5ba0fd07b116876b17711ec201:/sdk/python/arvados/collection.py?ds=inline diff --git a/sdk/python/arvados/collection.py b/sdk/python/arvados/collection.py index f7d210d6cd..3a90d6d3b0 100644 --- a/sdk/python/arvados/collection.py +++ b/sdk/python/arvados/collection.py @@ -51,7 +51,7 @@ def normalize_stream(s, stream): fout = f.replace(' ', '\\040') for segment in stream[f]: segmentoffset = blocks[segment[arvados.LOCATOR]] + segment[arvados.OFFSET] - if current_span == None: + if current_span is None: current_span = [segmentoffset, segmentoffset + segment[arvados.SEGMENTSIZE]] else: if segmentoffset == current_span[1]: @@ -60,7 +60,7 @@ def normalize_stream(s, stream): stream_tokens.append("{0}:{1}:{2}".format(current_span[0], current_span[1] - current_span[0], fout)) current_span = [segmentoffset, segmentoffset + segment[arvados.SEGMENTSIZE]] - if current_span != None: + if current_span is not None: stream_tokens.append("{0}:{1}:{2}".format(current_span[0], current_span[1] - current_span[0], fout)) if not stream[f]: @@ -89,14 +89,17 @@ class CollectionBase(object): hints other than size hints) removed from the locators. """ raw = self.manifest_text() - clean = '' + clean = [] for line in raw.split("\n"): fields = line.split() if fields: - locators = [ (re.sub(r'\+[^\d][^\+]*', '', x) if re.match(util.keep_locator_pattern, x) else x) - for x in fields[1:-1] ] - clean += fields[0] + ' ' + ' '.join(locators) + ' ' + fields[-1] + "\n" - return clean + clean_fields = fields[:1] + [ + (re.sub(r'\+[^\d][^\+]*', '', x) + if re.match(util.keep_locator_pattern, x) + else x) + for x in fields[1:]] + clean += [' '.join(clean_fields), "\n"] + return ''.join(clean) class CollectionReader(CollectionBase): @@ -182,7 +185,7 @@ class CollectionReader(CollectionBase): error_via_keep = self._populate_from_keep() if not self._manifest_text: error_via_api = self._populate_from_api_server() - if error_via_api != None and not should_try_keep: + if error_via_api is not None and not should_try_keep: raise error_via_api if (not self._manifest_text and not error_via_keep and @@ -345,9 +348,8 @@ class CollectionWriter(CollectionBase): def _work_trees(self): path, stream_name, max_manifest_depth = self._queued_trees[0] - make_dirents = (util.listdir_recursive if (max_manifest_depth == 0) - else os.listdir) - d = make_dirents(path) + d = util.listdir_recursive( + path, max_depth = (None if max_manifest_depth == 0 else 0)) if d: self._queue_dirents(stream_name, d) else: @@ -415,7 +417,7 @@ class CollectionWriter(CollectionBase): return self._current_file_name def finish_current_file(self): - if self._current_file_name == None: + if self._current_file_name is None: if self._current_file_pos == self._current_stream_length: return raise errors.AssertionError( @@ -486,10 +488,7 @@ class CollectionWriter(CollectionBase): manifest += ' ' + ' '.join("%d:%d:%s" % (sfile[0], sfile[1], sfile[2].replace(' ', '\\040')) for sfile in stream[2]) manifest += "\n" - if manifest: - return manifest - else: - return "" + return manifest def data_locators(self): ret = []