parameters: (self)
docstring: Disallows the update command if files not in the gsutil distro are found.
  
      This prevents users from losing data if they are in the habit of running
      gsutil from the gsutil directory and leaving data in that directory.
  
      This will also detect someone attempting to run gsutil update from a git
      repo, since the top-level directory will contain git files and dirs (like
      .git) that are not distributed with gsutil.
  
      Raises:
        CommandException: if files other than those distributed with gsutil found.
docstring_summary: Disallows the update command if files not in the gsutil distro are found.
docstring_tokens: Disallows the update command if files not in the gsutil distro are found .
function: def _DisallowUpdataIfDataInGsutilDir(self):
      """Disallows the update command if files not in the gsutil distro are found.
  
      This prevents users from losing data if they are in the habit of running
      gsutil from the gsutil directory and leaving data in that directory.
  
      This will also detect someone attempting to run gsutil update from a git
      repo, since the top-level directory will contain git files and dirs (like
      .git) that are not distributed with gsutil.
  
      Raises:
        CommandException: if files other than those distributed with gsutil found.
      """
      # Manifest includes recursive-includes of gslib. Directly add
      # those to the list here so we will skip them in os.listdir() loop without
      # having to build deeper handling of the MANIFEST file here. Also include
      # 'third_party', which isn't present in manifest but gets added to the
      # gsutil distro by the gsutil submodule configuration; and the MANIFEST.in
      # and CHANGES.md files.
      manifest_lines = ['gslib', 'third_party', 'MANIFEST.in', 'CHANGES.md']
  
      try:
        with open(os.path.join(gslib.GSUTIL_DIR, 'MANIFEST.in'), 'r') as fp:
          for line in fp:
            if line.startswith('include '):
              manifest_lines.append(line.split()[-1])
      except IOError:
        self.logger.warn('MANIFEST.in not found in %s.\nSkipping user data '
                         'check.\n', gslib.GSUTIL_DIR)
        return
  
      # Look just at top-level directory. We don't try to catch data dropped into
      # subdirs (like gslib) because that would require deeper parsing of
      # MANFFEST.in, and most users who drop data into gsutil dir do so at the top
      # level directory.
      for filename in os.listdir(gslib.GSUTIL_DIR):
        if filename.endswith('.pyc'):
          # Ignore compiled code.
          continue
        if filename not in manifest_lines:
          raise CommandException('\n'.join(textwrap.wrap(
              'A file (%s) that is not distributed with gsutil was found in '
              'the gsutil directory. The update command cannot run with user '
              'data in the gsutil directory.' %
              os.path.join(gslib.GSUTIL_DIR, filename))))
function_tokens: def _DisallowUpdataIfDataInGsutilDir ( self ) : # Manifest includes recursive-includes of gslib. Directly add # those to the list here so we will skip them in os.listdir() loop without # having to build deeper handling of the MANIFEST file here. Also include # 'third_party', which isn't present in manifest but gets added to the # gsutil distro by the gsutil submodule configuration; and the MANIFEST.in # and CHANGES.md files. manifest_lines = [ 'gslib' , 'third_party' , 'MANIFEST.in' , 'CHANGES.md' ] try : with open ( os . path . join ( gslib . GSUTIL_DIR , 'MANIFEST.in' ) , 'r' ) as fp : for line in fp : if line . startswith ( 'include ' ) : manifest_lines . append ( line . split ( ) [ - 1 ] ) except IOError : self . logger . warn ( 'MANIFEST.in not found in %s.\nSkipping user data ' 'check.\n' , gslib . GSUTIL_DIR ) return # Look just at top-level directory. We don't try to catch data dropped into # subdirs (like gslib) because that would require deeper parsing of # MANFFEST.in, and most users who drop data into gsutil dir do so at the top # level directory. for filename in os . listdir ( gslib . GSUTIL_DIR ) : if filename . endswith ( '.pyc' ) : # Ignore compiled code. continue if filename not in manifest_lines : raise CommandException ( '\n' . join ( textwrap . wrap ( 'A file (%s) that is not distributed with gsutil was found in ' 'the gsutil directory. The update command cannot run with user ' 'data in the gsutil directory.' % os . path . join ( gslib . GSUTIL_DIR , filename ) ) ) )