def test_run_ground(): Inform(prog_name=False, logfile=False) set_prefs(use_inform=True) cmd = './test_prog 1' try: p = Run(cmd, 'sOEW') assert False, 'expected exception' except Error as e: assert str(e) == 'this is stderr.' assert e.cmd == './test_prog 1' assert e.stdout == 'this is stdout.' assert e.stderr == 'this is stderr.' assert e.status == 1 assert e.msg == 'this is stderr.' set_prefs(use_inform=False)
def test_run_ground(): with cd(wd): Inform(prog_name=False, logfile=False) set_prefs(use_inform=True) cmd = "./test_prog 1" try: Run(cmd, "sOEW") assert False, "expected exception" except Error as e: assert str(e) == "this is stderr." assert e.cmd == "./test_prog 1" assert e.stdout == "this is stdout." assert e.stderr == "this is stderr." assert e.status == 1 assert e.msg == "this is stderr." set_prefs(use_inform=False)
# Imports {{{1 from .collection import Collection from .preferences import ( BORG_SETTINGS, DEFAULT_COMMAND, EMBORG_SETTINGS, PROGRAM_NAME, ) from .settings import Settings from .utilities import two_columns, render_paths, gethostname hostname = gethostname() from inform import (Color, Error, codicil, conjoin, cull, full_stop, is_str, narrate, os_error, output, render, warn) from docopt import docopt from shlib import cd, cwd, mkdir, mv, rm, to_path, Run, set_prefs set_prefs(use_inform=True, log_cmd=True) from textwrap import dedent import arrow import json import sys # Utilities {{{1 # title() {{{2 def title(text): return full_stop(text.capitalize()) # get_available_archives() {{{2 def get_available_archives(settings): # run borg
import os import pwd import socket # Utilities {{{1 def getusername(): return pwd.getpwuid(os.getuid()).pw_name def gethostname(): return socket.gethostname() # Globals {{{1 set_prefs(use_inform=True) overdue_message = dedent(""" Backup of {host} is overdue. The backup sentinel file ({path!s}) has not changed in {age:0.0f} hours. """).strip() error_message = dedent(f""" {get_prog_name()} generated the following error: host: {gethostname()} user: {getusername()} message: {{}} """) # Main {{{1
# version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see http://www.gnu.org/licenses/. # Imports {{{1 from inform import cull, display, error, Error, os_error, warn from shlib import to_path, rm, Cmd, set_prefs import sys, os set_prefs(use_inform=True) # Defaults {{{1 DEFAULT_GUI = True DEFAULT_VIM = 'gvimdiff -v' DEFAULT_GVIM = 'gvimdiff -f' # Map class {{{1 class Map(object): def __init__(self, key, cmd, desc): self.key = key self.cmd = cmd self.desc = desc def mapping(self): if self.key.startswith('Ctrl-'): key = '<C-%s>' % self.key.replace('Ctrl-', '')