Exemple #1
0
    def __setup_logging(self):
        logging.root.setLevel(logging.WARNING)
        formatter = logging.Formatter(
            '%(levelname)-8s %(asctime)s [%(module)s:%(funcName)s:%(lineno)s] '
            '%(message)s')
        try:
            location_type = QStandardPaths.AppLocalDataLocation
        except AttributeError:
            # AppLocalDataLocation was only added in Qt 5.4. DataLocation
            # returns the same value as AppLocalDataLocation but is deprecated
            # in newer Qt versions.
            # https://doc.qt.io/qt-5/qstandardpaths.html#StandardLocation-enum
            location_type = QStandardPaths.DataLocation
        data_dir = QStandardPaths.standardLocations(location_type)[0]

        console_handler = logging.StreamHandler(sys.stdout)
        console_handler.setFormatter(formatter)
        logging.root.addHandler(console_handler)

        isdir = util.makedirs(data_dir)
        if isdir:
            log_file = os.path.join(
                data_dir, '{}.log'.format(self.__application_name.lower()))
            file_handler = logging.FileHandler(log_file)
            file_handler.setFormatter(formatter)
            logging.root.addHandler(file_handler)
Exemple #2
0
 def test_create_error(self):
     parent = tempfile.mkdtemp()
     os.chmod(parent, 0000)
     path = os.path.join(parent, 'testdir')
     isdir = util.makedirs(path)
     self.assertEqual(isdir, False)
     os.rmdir(parent)
Exemple #3
0
 def test_create(self):
     tempdir = tempfile.gettempdir()
     parent = os.tempnam(tempdir)
     path = os.path.join(parent, 'testdir')
     isdir = util.makedirs(path)
     self.assertEqual(isdir, True)
     self.assertEqual(os.path.isdir(path), True)
     shutil.rmtree(parent)
Exemple #4
0
    def __create_autostart_entry(self, autostart_dir, file_path):
        isdir = util.makedirs(autostart_dir)
        if not isdir:
            return False

        try:
            with open(file_path, 'w') as f:
                f.write(dedent(self.__desktop_file_entry))
        except:
            logging.warning('Cannot create autostart file.', exc_info=True)
            return False

        return True
Exemple #5
0
 def test_existing_nondir(self):
     _, path = tempfile.mkstemp()
     isdir = util.makedirs(path)
     self.assertEqual(isdir, False)
     os.unlink(path)
Exemple #6
0
 def test_existing(self):
     path = tempfile.mkdtemp()
     isdir = util.makedirs(path)
     self.assertEqual(isdir, True)
     os.rmdir(path)