Update git submodules
[LibreOffice.git] / bin / update / path.py
blobd91e9e7fba55bc070a7b6dc29d652587ecb1e2d4
1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 import os
11 import errno
12 import subprocess
13 from sys import platform
15 def mkdir_p(path):
16 try:
17 os.makedirs(path)
18 except OSError as exc: # Python >2.5
19 if exc.errno == errno.EEXIST and os.path.isdir(path):
20 pass
21 else:
22 raise
24 def convert_to_unix(path):
25 if platform == "cygwin":
26 return subprocess.check_output(["cygpath", "-u", path]).decode("utf-8", "strict").rstrip()
27 else:
28 return path
31 def convert_to_native(path):
32 if platform == "cygwin":
33 return subprocess.check_output(["cygpath", "-m", path]).decode("utf-8", "strict").rstrip()
34 else:
35 return path
38 class UpdaterPath(object):
40 def __init__(self, workdir):
41 self._workdir = convert_to_unix(workdir)
43 def get_workdir(self):
44 return self._workdir
46 def get_update_dir(self):
47 return os.path.join(self._workdir, "update-info")
49 def get_current_build_dir(self):
50 return os.path.join(self._workdir, "mar", "current-build")
52 def get_mar_dir(self):
53 return os.path.join(self._workdir, "mar")
55 def get_previous_build_dir(self):
56 return os.path.join(self._workdir, "mar", "previous-build")
58 def get_language_dir(self):
59 return os.path.join(self.get_mar_dir(), "language")
61 def ensure_dir_exist(self):
62 os.makedirs(self.get_update_dir(), exist_ok=True)
63 os.makedirs(self.get_current_build_dir(), exist_ok=True)
64 os.makedirs(self.get_mar_dir(), exist_ok=True)
65 os.makedirs(self.get_previous_build_dir(), exist_ok=True)
66 os.makedirs(self.get_language_dir(), exist_ok=True)
68 # vim: set shiftwidth=4 softtabstop=4 expandtab: