Exemplo n.º 1
0
def Create(root_directory):
  """Create a workspace at the provided root directory and return it.

  Args:
    root_directory: str, Where to root the new workspace.

  Returns:
    The Workspace.

  Raises:
    InvalidWorkspaceException: If the desired directory is already in an
        existing gcloud workspace.
    CannotCreateWorkspaceException: If the directory for the workspace does not
        exist.
  """

  containing_workspace = files.FindDirectoryContaining(
      root_directory, config.Paths.CLOUDSDK_WORKSPACE_CONFIG_DIR_NAME)
  if containing_workspace:
    raise InvalidWorkspaceException(root_directory, containing_workspace)

  if not os.path.exists(root_directory):
    raise CannotCreateWorkspaceException(root_directory)

  workspace_config_path = os.path.join(
      root_directory,
      config.Paths.CLOUDSDK_WORKSPACE_CONFIG_DIR_NAME)

  files.MakeDir(workspace_config_path)

  log.status.write('Initialized gcloud directory in [{path}].\n'.format(
      path=workspace_config_path))

  return Workspace(root_directory=root_directory)
Exemplo n.º 2
0
  def __init__(self):
    if platforms.OperatingSystem.Current() == platforms.OperatingSystem.WINDOWS:
      try:
        default_config_path = os.path.join(
            os.environ['APPDATA'], Paths._CLOUDSDK_WORKSPACE_CONFIG_WORD)
      except KeyError:
        # This should never happen unless someone is really messing with things.
        drive = os.environ.get('SystemDrive', 'C:')
        default_config_path = os.path.join(
            drive, '\\', Paths._CLOUDSDK_WORKSPACE_CONFIG_WORD)
    else:
      default_config_path = os.path.join(
          os.path.expanduser('~'), '.config',
          Paths._CLOUDSDK_WORKSPACE_CONFIG_WORD)
    self.global_config_dir = os.getenv(CLOUDSDK_CONFIG, default_config_path)

    try:
      # It is possible for some filesystems (like fakefs) to not report current
      # working directories.  In the event this happens, just don't try
      # searching for a workspace.
      cwd = os.getcwd()
    except OSError:
      cwd = None

    self.workspace_dir = None
    if cwd:
      self.workspace_dir = file_utils.FindDirectoryContaining(
          cwd, Paths.CLOUDSDK_WORKSPACE_CONFIG_DIR_NAME)

    self.workspace_config_dir = None
    if self.workspace_dir:
      self.workspace_config_dir = os.path.join(
          self.workspace_dir, Paths.CLOUDSDK_WORKSPACE_CONFIG_DIR_NAME)
Exemplo n.º 3
0
def GoogleCloudSDKPackageRoot():

    # pylint:disable=unreachable, would be nicer to have MOE insert this block.
    resource_dir = file_utils.FindDirectoryContaining(
        os.path.dirname(__file__), 'googlecloudsdk')
    if not resource_dir:
        raise GooglePackageRootNotFoundException()
    return os.path.join(resource_dir, 'googlecloudsdk')
Exemplo n.º 4
0
    def sdk_root(self):
        """Searches for the Cloud SDK root directory.

    Returns:
      str, The path to the root of the Cloud SDK or None if it could not be
      found.
    """
        return file_utils.FindDirectoryContaining(os.path.dirname(__file__),
                                                  Paths.CLOUDSDK_STATE_DIR)
Exemplo n.º 5
0
def LibraryRoot():
    """Acquire the lib root directory with all the libraries used by gcloud.

  Returns:
    str, An absolute path that points to the root of all packages used by
    gcloud.

  Raises:
    GooglePackageRootNotFoundException: If the root cannot be identified.
  """
    # pylint:disable=unreachable, would be nicer to have MOE insert this block.
    resource_dir = file_utils.FindDirectoryContaining(
        os.path.dirname(__file__), 'googlecloudsdk')
    if not resource_dir:
        raise GooglePackageRootNotFoundException()
    return resource_dir
Exemplo n.º 6
0
 def __init__(self):
   if platforms.OperatingSystem.Current() == platforms.OperatingSystem.WINDOWS:
     try:
       default_config_path = os.path.join(
           os.environ['APPDATA'], Paths._CLOUDSDK_WORKSPACE_CONFIG_WORD)
     except KeyError:
       # This should never happen unless someone is really messing with things.
       drive = os.environ.get('SystemDrive', 'C:')
       default_config_path = os.path.join(
           drive, '\\', Paths._CLOUDSDK_WORKSPACE_CONFIG_WORD)
   else:
     default_config_path = os.path.join(
         os.path.expanduser('~'), '.config',
         Paths._CLOUDSDK_WORKSPACE_CONFIG_WORD)
   self.global_config_dir = os.getenv(CLOUDSDK_CONFIG, default_config_path)
   self.workspace_dir = file_utils.FindDirectoryContaining(
       os.getcwd(), Paths.CLOUDSDK_WORKSPACE_CONFIG_DIR_NAME)
   self.workspace_config_dir = None
   if self.workspace_dir:
     self.workspace_config_dir = os.path.join(
         self.workspace_dir, Paths.CLOUDSDK_WORKSPACE_CONFIG_DIR_NAME)