Пример #1
0
 def _remount_fs(self, mode='rw'):
     if hardware.platfrom.__name__ != 'raspberry':
         return True
     for i in range(10):
         log.info("remount {fs} {mode}".format(fs=self._fs, mode=mode))
         shell.execute('sudo sync')
         if mode == 'ro' and self._current_mode() == 'ro':
             log.info('fs is already read-only')
             return True
         if mode == 'rw' and self._current_mode() == 'rw':
             log.info('fs is already read-write')
             return True
         self._before_remount_to(mode)
         (r, o, e) = shell.execute(
             "sudo mount -o remount,{mode} {fs}".format(mode=mode,
                                                        fs=self._fs))
         self._after_remount_to(mode)
         if r == 0:
             return True
         else:
             log.error('fs remount failed: {e}\n{o}'.format(e=e, o=o))
             time.sleep(1)
             continue
     log.error("couldn't remount {fs} after 10 retries".format(fs=self._fs))
     return False
Пример #2
0
def mkdir(path):
    if hardware.platfrom.__name__ == 'raspberry':
        sudo = 'sudo '
    else:
        sudo = ''
    shell.execute("{s}mkdir -p {p}".format(p=path, s=sudo))
    chown_to_current(path)
Пример #3
0
 def change_timezone(self, tz):
     if 'debian' not in system.systeminfo.linux_disto():
         log.error('cannot change timezone on non-Debian distro')
         return False
     sign = tz[0]
     value = tz[1:3]
     if sign == '+':
         sign = '-'
     elif sign == '-':
         sign = '+'
     posix_gmt_tz = 'Etc/GMT{sign}{value}'.format(sign=sign,
                                                  value=int(value))
     cli = "sudo sh -c 'echo \"{gmt_tz}\" > /etc/timezone'".format(
         gmt_tz=posix_gmt_tz)
     with rw_fs.Root():
         (r, o, e) = shell.execute_shell(cli)
         if r != 0:
             log.error('error setting timezone: {e}\n{o}'.format(e=e, o=o))
             return False
         (r, o, e) = shell.execute(
             "sudo dpkg-reconfigure -f noninteractive tzdata")
         if r != 0:
             log.error('error changing timezone: {e}\n{o}'.format(e=e, o=o))
             return False
         log.debug('change timezone result: {r}\n{o}\n{e}'.format(r=r,
                                                                  o=o,
                                                                  e=e))
         return True
Пример #4
0
 def _set_framebuffer_resolution(self, x, y):
     (r, o, e) = shell.execute("sudo fbset -xres {x} -yres {y}".format(x=x,
                                                                       y=y))
     if r != 0:
         raise RuntimeError(
             "error setting framebuffer resolution to {x}x{y}: {e}\n{o}".
             format(x=x, y=y, e=e, o=o))
Пример #5
0
 def _read_monitor_name(self):
     (r, o, e) = shell.execute("sudo tvservice -n")
     if r != 0:
         raise RuntimeError(
             "error getting info about connected monitors: {e}\n{o}".format(
                 e=e, o=o))
     return o.strip()
Пример #6
0
 def __init__(self, repo):
     cli = "git --version"
     try:
         (r,o,e) = shell.execute(cli, repo)
         self.__raise_if_error(cli, r, e, o)
         log.info("using git: {v}".format(v=o.strip()))   
     except OSError as e:
         log.exception("error communicating with git")
         raise RuntimeError("error communicating with git: " + srt(e))
     self.__repo__ = repo
Пример #7
0
 def set_hwclock_to_system_time(self):
     log.debug("setting hwclock to system time")
     if not self.is_hwclock_present():
         return False
     with rw_fs.Root():
         (r, o, e) = shell.execute("sudo hwclock -w")
         if r != 0:
             log.error(
                 "error setting hardware clock to system time: {e}\n{o}".
                 format(e=e, o=o))
         return r == 0
 def call(self):
     cli = "ssh -R {ext_port}:localhost:{int_port} {user}@{server} -p {server_port} -f sleep {dur}"\
         .format(ext_port=self._data['external_port'],
                 int_port=self._data['internal_port'],
                 user=self._data['username'],
                 server=self._data['server'],
                 server_port=self._data['server_port'],
                 dur=self._data['duration'])
     m = "opening ssh tunnel: '{cli}'".format(cli=cli)
     log.info(m)
     self._ack(True, m)
     r, o, e = shell.execute(cli)
     # self._sender('ack').call(ok=(r == 0), sequence=self._sequence, message=(m + ";" + str(o) + ";" + str(e)))
     log.info("ssh tunnel result: {r}, stdout: {o}, stderr: {e}".format(
         r=r, o=o, e=e))
Пример #9
0
 def _before_remount_to(self, mode):
     if mode == 'ro' and self._restart_player:
         self._player().stop()
         shell.execute('sudo sync')
Пример #10
0
 def is_hwclock_present(self):
     (r, o, e) = shell.execute("sudo hwclock -r")
     return r == 0
Пример #11
0
 def reboot(self):
     (r, o, e) = shell.execute("sudo reboot")
     log.debug("reboot return code: {r}\n{o}\n{e}".format(r=r, o=o, e=e))
     return r, o, e
Пример #12
0
 def _read_status(self):
     (r, o, e) = shell.execute("sudo tvservice -s")
     if r != 0:
         raise RuntimeError(
             "error getting current hdmi status: {e}\n{o}".format(e=e, o=o))
     return o.strip()
Пример #13
0
 def _set_preferred_mode(self):
     (r, o, e) = shell.execute("sudo tvservice -p")
     if r != 0:
         raise RuntimeError(
             "error setting preferrend mode: {e}\n{o}".format(e=e, o=o))
Пример #14
0
def chown(path, user, group):
    if hardware.platfrom.__name__ == 'raspberry':
        shell.execute("sudo chown -R {u}:{g} {p}".format(p=path,
                                                         u=user,
                                                         g=group))
Пример #15
0
def chmod(path, mode):
    shell.execute("sudo chmod -R {m} {p}".format(p=path, m=mode))
Пример #16
0
 def __exec(self, cli):
     (r, o, e) = shell.execute(cli, self.__repo__)
     self.__raise_if_error(cli, r, e, o)
     return (r, o, e)