Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / bin / update / path.py
blob0fe0fd5eb04f4dcfa94b63a23cc8311ac14d6371
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
30 def convert_to_native(path):
31 if platform == "cygwin":
32 return subprocess.check_output(["cygpath", "-m", path]).decode("utf-8", "strict").rstrip()
33 else:
34 return path
36 class UpdaterPath(object):
38 def __init__(self, workdir):
39 self._workdir = convert_to_unix(workdir)
41 def get_workdir(self):
42 return self._workdir
44 def get_update_dir(self):
45 return os.path.join(self._workdir, "update-info")
47 def get_current_build_dir(self):
48 return os.path.join(self._workdir, "mar", "current-build")
50 def get_mar_dir(self):
51 return os.path.join(self._workdir, "mar")
53 def get_previous_build_dir(self):
54 return os.path.join(self._workdir, "mar", "previous-build")
56 def get_language_dir(self):
57 return os.path.join(self.get_mar_dir(), "language")
59 def get_workdir(self):
60 return self._workdir
62 def ensure_dir_exist(self):
63 mkdir_p(self.get_update_dir())
64 mkdir_p(self.get_current_build_dir())
65 mkdir_p(self.get_mar_dir())
66 mkdir_p(self.get_previous_build_dir())
67 mkdir_p(self.get_language_dir())
69 # vim: set shiftwidth=4 softtabstop=4 expandtab: