source: calamares/trunk/fuentes/src/modules/dummypython/main.py @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 3.8 KB
Line 
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3#
4# === This file is part of Calamares - <https://github.com/calamares> ===
5#
6#   Copyright 2014, Teo Mrnjavac <teo@kde.org>
7#   Copyright 2017, Alf Gaida <agaida@siduction.org>
8#   Copyright 2017, Adriaan de Groot <groot@kde.org>
9#
10#   Calamares is free software: you can redistribute it and/or modify
11#   it under the terms of the GNU General Public License as published by
12#   the Free Software Foundation, either version 3 of the License, or
13#   (at your option) any later version.
14#
15#   Calamares is distributed in the hope that it will be useful,
16#   but WITHOUT ANY WARRANTY; without even the implied warranty of
17#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18#   GNU General Public License for more details.
19#
20#   You should have received a copy of the GNU General Public License
21#   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
22
23"""
24=== Example Python jobmodule.
25
26A Python jobmodule is a Python program which imports libcalamares and
27has a function run() as entry point. run() must return None if everything
28went well, or a tuple (str,str) with an error message and description
29if something went wrong.
30"""
31
32import libcalamares
33import os
34from time import gmtime, strftime, sleep
35
36import gettext
37_ = gettext.translation("calamares-python",
38                        localedir=libcalamares.utils.gettext_path(),
39                        languages=libcalamares.utils.gettext_languages(),
40                        fallback=True).gettext
41
42
43def pretty_name():
44    return _("Dummy python job.")
45
46
47def run():
48    """Dummy python job."""
49    libcalamares.utils.debug("LocaleDir=" +
50                             str(libcalamares.utils.gettext_path()))
51    libcalamares.utils.debug("Languages=" +
52                             str(libcalamares.utils.gettext_languages()))
53
54    os.system("/bin/sh -c \"touch ~/calamares-dummypython\"")
55    accumulator = strftime("%Y-%m-%d %H:%M:%S", gmtime()) + "\n"
56    accumulator += "Calamares version: " + libcalamares.VERSION_SHORT + "\n"
57    accumulator += "This job's name: " + libcalamares.job.pretty_name + "\n"
58    accumulator += "This job's path: " + libcalamares.job.working_path
59    libcalamares.utils.debug(accumulator)
60
61    accumulator = "*** Job configuration "
62    accumulator += str(libcalamares.job.configuration)
63    libcalamares.utils.debug(accumulator)
64
65    accumulator = "*** globalstorage test ***"
66    accumulator += "lala: "
67    accumulator += str(libcalamares.globalstorage.contains("lala")) + "\n"
68    accumulator += "foo: "
69    accumulator += str(libcalamares.globalstorage.contains("foo")) + "\n"
70    accumulator += "count: " + str(libcalamares.globalstorage.count())
71    libcalamares.utils.debug(accumulator)
72
73    libcalamares.globalstorage.insert("item2", "value2")
74    libcalamares.globalstorage.insert("item3", 3)
75    accumulator = "keys: {}\n".format(str(libcalamares.globalstorage.keys()))
76    libcalamares.utils.debug(accumulator)
77
78    accumulator = "remove: {}\n".format(
79       str(libcalamares.globalstorage.remove("item2")))
80    accumulator += "values: {} {} {}\n".format(
81        str(libcalamares.globalstorage.value("foo")),
82        str(libcalamares.globalstorage.value("item2")),
83        str(libcalamares.globalstorage.value("item3")))
84    libcalamares.utils.debug(accumulator)
85
86    libcalamares.utils.debug("Run dummy python")
87
88    sleep(1)
89
90    try:
91        configlist = list(libcalamares.job.configuration["a_list"])
92    except KeyError:
93        configlist = ["no list"]
94
95    c = 1
96    for k in configlist:
97        libcalamares.utils.debug(_("Dummy python step {}").format(str(k)))
98        sleep(1)
99        libcalamares.job.setprogress(c * 1.0 / len(configlist))
100        c += 1
101
102    sleep(3)
103
104    # To indicate an error, return a tuple of:
105    # (message, detailed-error-message)
106    return None
Note: See TracBrowser for help on using the repository browser.