# -*- coding: utf-8 -*- # # Copyright 2017 Google LLC. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Library for ignoring files for upload. This library very closely mimics the semantics of Git's gitignore file: https://git-scm.com/docs/gitignore See `gcloud topic gcloudignore` for details. A typical use would be: file_chooser = gcloudignore.GetFileChooserForDir(upload_directory) for f in file_chooser.GetIncludedFiles('some/path'): print 'uploading {}'.format(f) # actually do the upload, too """ from __future__ import absolute_import from __future__ import division from __future__ import unicode_literals import os import enum from googlecloudsdk.command_lib.util import glob from googlecloudsdk.core import exceptions from googlecloudsdk.core import log from googlecloudsdk.core import properties from googlecloudsdk.core.util import encoding from googlecloudsdk.core.util import files import six from six.moves import map # pylint: disable=redefined-builtin IGNORE_FILE_NAME = '.gcloudignore' GIT_FILES = ['.git', '.gitignore'] DEFAULT_IGNORE_FILE = """\ # This file specifies files that are *not* uploaded to Google Cloud # using gcloud. It follows the same syntax as .gitignore, with the addition of # "#!include" directives (which insert the entries of the given .gitignore-style # file at that point). # # For more information, run: # $ gcloud topic gcloudignore # .gcloudignore # If you would like to upload your .git directory, .gitignore file or files # from your .gitignore file, remove the corresponding line # below: .git .gitignore """ _GCLOUDIGNORE_PATH_SEP = '/' _ENDS_IN_ODD_NUMBER_SLASHES_RE = r'(?