dir.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #! /usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. import os
  17. import os.path as osp
  18. def gen_user_home():
  19. if "PADDLE_HOME" in os.environ:
  20. home_path = os.environ["PADDLE_HOME"]
  21. if os.path.exists(home_path) and os.path.isdir(home_path):
  22. return home_path
  23. return os.path.expanduser('~')
  24. def gen_paddlex_home():
  25. path = osp.join(gen_user_home(), ".paddlex_server")
  26. if not osp.exists(path):
  27. os.makedirs(path)
  28. return path
  29. USER_HOME = gen_user_home()
  30. PADDLEX_HOME = gen_paddlex_home()
  31. WORKSPACE_HOME = osp.join(USER_HOME, "paddlex_workspace")
  32. LOG_HOME = osp.join(PADDLEX_HOME, "logs")
  33. SINGLE_LOCK_HOME = osp.join(PADDLEX_HOME, "single_lock")
  34. CACHE_HOME = osp.join(PADDLEX_HOME, "cache")
  35. for home in [WORKSPACE_HOME, LOG_HOME, SINGLE_LOCK_HOME, CACHE_HOME]:
  36. if not osp.exists(home):
  37. os.makedirs(home)