Skip to content

Commit

Permalink
Merge pull request #49 from ralish/no-lang-set
Browse files Browse the repository at this point in the history
Fix UnicodeEncodeError exception & minor PEP8 fixes
  • Loading branch information
miracle2k committed Jul 8, 2018
2 parents 3ea975f + 4f21044 commit 4206dba
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions tarsnapper/script.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import json
import sys, os
from os import path
import uuid
import subprocess
from io import StringIO
import re
from string import Template
from datetime import datetime, timedelta
import logging
import argparse
import dateutil.parser
import getpass

import logging
import os
import pexpect
import re
import subprocess
import sys
import uuid

from datetime import datetime
from io import StringIO
from os import path
from string import Template

from . import expire, config
from . import config, expire
from .config import Job


Expand Down Expand Up @@ -67,9 +67,8 @@ def call(self, *arguments):
def _exec_tarsnap(self, args):
self.log.debug("Executing: %s" % " ".join(args))
env = os.environ
env['LANG'] = 'C' # ensure the tarsnap output is in english
child = pexpect.spawn(args[0], args[1:], env=env, timeout=None,
encoding='utf-8')
encoding='utf-8')

if self.log.isEnabledFor(logging.DEBUG):
child.logfile = sys.stdout
Expand Down Expand Up @@ -137,7 +136,7 @@ def get_backups(self, job):
target = Template(job.target).substitute(
{'name': possible_name, 'date': unique})
regexes.append(re.compile("^%s$" %
re.escape(target).replace(unique, '(?P<date>.*?)')))
re.escape(target).replace(unique, '(?P<date>.*?)')))

backups = {}
for backup_path in self.get_archives():
Expand Down Expand Up @@ -186,7 +185,7 @@ def expire(self, job):
# Delete all others
to_delete = []
for name, _ in list(backups.items()):
if not name in to_keep:
if name not in to_keep:
to_delete.append(name)

to_keep.sort()
Expand Down Expand Up @@ -333,10 +332,10 @@ def setup_arg_parser(self, parser):
@classmethod
def validate_args(self, args):
if not args.config and not args.target:
raise ArgumentError('Since you are not using a config file, '\
raise ArgumentError('Since you are not using a config file, '
'you need to give --target')
if not args.config and not args.deltas and not args.no_expire:
raise ArgumentError('Since you are not using a config file, and '\
raise ArgumentError('Since you are not using a config file, and '
'have not specified --no-expire, you will '
'need to give --deltas')
if not args.config and not args.sources:
Expand Down Expand Up @@ -381,7 +380,7 @@ def run(self, job):
self.backend.make(job)
except Exception:
self.log.exception(("Something went wrong with backup job: '%s'")
% job.name)
% job.name)

if job.exec_after:
self.backend._exec_util(job.exec_after)
Expand Down Expand Up @@ -419,14 +418,14 @@ def parse_args(argv):
parser.add_argument('--config', '-c', help='use the given config file')

group = parser.add_argument_group(
description='Instead of using a configuration file, you may define '\
description='Instead of using a configuration file, you may define '
'a single job on the command line:')
group.add_argument('--target', help='target filename for the backup')
group.add_argument('--sources', nargs='+', help='paths to backup',
default=[])
default=[])
group.add_argument('--deltas', '-d', metavar='DELTA',
type=timedelta_string,
help='generation deltas', nargs='+')
type=timedelta_string,
help='generation deltas', nargs='+')
group.add_argument('--dateformat', '-f', help='dateformat')

for plugin in PLUGINS:
Expand Down

0 comments on commit 4206dba

Please sign in to comment.