1# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- 2# 3# This file is part of the LibreOffice project. 4# 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/. 8# 9 10import os 11import errno 12import subprocess 13from sys import platform 14 15def 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 23 24def 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 29 30def 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 35 36class UpdaterPath(object): 37 38 def __init__(self, workdir): 39 self._workdir = convert_to_unix(workdir) 40 41 def get_workdir(self): 42 return self._workdir 43 44 def get_update_dir(self): 45 return os.path.join(self._workdir, "update-info") 46 47 def get_current_build_dir(self): 48 return os.path.join(self._workdir, "mar", "current-build") 49 50 def get_mar_dir(self): 51 return os.path.join(self._workdir, "mar") 52 53 def get_previous_build_dir(self): 54 return os.path.join(self._workdir, "mar", "previous-build") 55 56 def get_language_dir(self): 57 return os.path.join(self.get_mar_dir(), "language") 58 59 def get_workdir(self): 60 return self._workdir 61 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()) 68 69# vim: set shiftwidth=4 softtabstop=4 expandtab: 70