As a convenience to new users, allow a missing default excludes file.
This commit is contained in:
parent
38322a3f6f
commit
58d33503a1
5 changed files with 56 additions and 8 deletions
3
NEWS
3
NEWS
|
@ -1,5 +1,6 @@
|
||||||
0.1.2-dev
|
0.1.2
|
||||||
|
|
||||||
|
* As a convenience to new users, allow a missing default excludes file.
|
||||||
* New issue tracker, linked from documentation.
|
* New issue tracker, linked from documentation.
|
||||||
|
|
||||||
0.1.1
|
0.1.1
|
||||||
|
|
|
@ -14,10 +14,11 @@ from atticmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
|
||||||
|
|
||||||
def create_archive(excludes_filename, verbosity, source_directories, repository, command):
|
def create_archive(excludes_filename, verbosity, source_directories, repository, command):
|
||||||
'''
|
'''
|
||||||
Given an excludes filename, a vebosity flag, a space-separated list of source directories, a
|
Given an excludes filename (or None), a vebosity flag, a space-separated list of source
|
||||||
local or remote repository path, and a command to run, create an attic archive.
|
directories, a local or remote repository path, and a command to run, create an attic archive.
|
||||||
'''
|
'''
|
||||||
sources = tuple(source_directories.split(' '))
|
sources = tuple(source_directories.split(' '))
|
||||||
|
exclude_flags = ('--exclude-from', excludes_filename) if excludes_filename else ()
|
||||||
verbosity_flags = {
|
verbosity_flags = {
|
||||||
VERBOSITY_SOME: ('--stats',),
|
VERBOSITY_SOME: ('--stats',),
|
||||||
VERBOSITY_LOTS: ('--verbose', '--stats'),
|
VERBOSITY_LOTS: ('--verbose', '--stats'),
|
||||||
|
@ -25,13 +26,12 @@ def create_archive(excludes_filename, verbosity, source_directories, repository,
|
||||||
|
|
||||||
full_command = (
|
full_command = (
|
||||||
command, 'create',
|
command, 'create',
|
||||||
'--exclude-from', excludes_filename,
|
|
||||||
'{repo}::{hostname}-{timestamp}'.format(
|
'{repo}::{hostname}-{timestamp}'.format(
|
||||||
repo=repository,
|
repo=repository,
|
||||||
hostname=platform.node(),
|
hostname=platform.node(),
|
||||||
timestamp=datetime.now().isoformat(),
|
timestamp=datetime.now().isoformat(),
|
||||||
),
|
),
|
||||||
) + sources + verbosity_flags
|
) + sources + exclude_flags + verbosity_flags
|
||||||
|
|
||||||
subprocess.check_call(full_command)
|
subprocess.check_call(full_command)
|
||||||
|
|
||||||
|
|
|
@ -18,17 +18,20 @@ def parse_arguments(command_name, *arguments):
|
||||||
parse the arguments and return them as an ArgumentParser instance. Use the command name to
|
parse the arguments and return them as an ArgumentParser instance. Use the command name to
|
||||||
determine the default configuration and excludes paths.
|
determine the default configuration and excludes paths.
|
||||||
'''
|
'''
|
||||||
|
config_filename_default = DEFAULT_CONFIG_FILENAME_PATTERN.format(command_name)
|
||||||
|
excludes_filename_default = DEFAULT_EXCLUDES_FILENAME_PATTERN.format(command_name)
|
||||||
|
|
||||||
parser = ArgumentParser()
|
parser = ArgumentParser()
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-c', '--config',
|
'-c', '--config',
|
||||||
dest='config_filename',
|
dest='config_filename',
|
||||||
default=DEFAULT_CONFIG_FILENAME_PATTERN.format(command_name),
|
default=config_filename_default,
|
||||||
help='Configuration filename',
|
help='Configuration filename',
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--excludes',
|
'--excludes',
|
||||||
dest='excludes_filename',
|
dest='excludes_filename',
|
||||||
default=DEFAULT_EXCLUDES_FILENAME_PATTERN.format(command_name),
|
default=excludes_filename_default if os.path.exists(excludes_filename_default) else None,
|
||||||
help='Excludes filename',
|
help='Excludes filename',
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from flexmock import flexmock
|
||||||
from nose.tools import assert_raises
|
from nose.tools import assert_raises
|
||||||
|
|
||||||
from atticmatic import command as module
|
from atticmatic import command as module
|
||||||
|
@ -9,6 +11,8 @@ COMMAND_NAME = 'foomatic'
|
||||||
|
|
||||||
|
|
||||||
def test_parse_arguments_with_no_arguments_uses_defaults():
|
def test_parse_arguments_with_no_arguments_uses_defaults():
|
||||||
|
flexmock(os.path).should_receive('exists').and_return(True)
|
||||||
|
|
||||||
parser = module.parse_arguments(COMMAND_NAME)
|
parser = module.parse_arguments(COMMAND_NAME)
|
||||||
|
|
||||||
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME_PATTERN.format(COMMAND_NAME)
|
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME_PATTERN.format(COMMAND_NAME)
|
||||||
|
@ -17,6 +21,8 @@ def test_parse_arguments_with_no_arguments_uses_defaults():
|
||||||
|
|
||||||
|
|
||||||
def test_parse_arguments_with_filename_arguments_overrides_defaults():
|
def test_parse_arguments_with_filename_arguments_overrides_defaults():
|
||||||
|
flexmock(os.path).should_receive('exists').and_return(True)
|
||||||
|
|
||||||
parser = module.parse_arguments(COMMAND_NAME, '--config', 'myconfig', '--excludes', 'myexcludes')
|
parser = module.parse_arguments(COMMAND_NAME, '--config', 'myconfig', '--excludes', 'myexcludes')
|
||||||
|
|
||||||
assert parser.config_filename == 'myconfig'
|
assert parser.config_filename == 'myconfig'
|
||||||
|
@ -24,7 +30,29 @@ def test_parse_arguments_with_filename_arguments_overrides_defaults():
|
||||||
assert parser.verbosity == None
|
assert parser.verbosity == None
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_arguments_with_missing_default_excludes_file_sets_filename_to_none():
|
||||||
|
flexmock(os.path).should_receive('exists').and_return(False)
|
||||||
|
|
||||||
|
parser = module.parse_arguments(COMMAND_NAME)
|
||||||
|
|
||||||
|
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME_PATTERN.format(COMMAND_NAME)
|
||||||
|
assert parser.excludes_filename == None
|
||||||
|
assert parser.verbosity == None
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_arguments_with_missing_overridden_excludes_file_retains_filename():
|
||||||
|
flexmock(os.path).should_receive('exists').and_return(False)
|
||||||
|
|
||||||
|
parser = module.parse_arguments(COMMAND_NAME, '--excludes', 'myexcludes')
|
||||||
|
|
||||||
|
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME_PATTERN.format(COMMAND_NAME)
|
||||||
|
assert parser.excludes_filename == 'myexcludes'
|
||||||
|
assert parser.verbosity == None
|
||||||
|
|
||||||
|
|
||||||
def test_parse_arguments_with_verbosity_flag_overrides_default():
|
def test_parse_arguments_with_verbosity_flag_overrides_default():
|
||||||
|
flexmock(os.path).should_receive('exists').and_return(True)
|
||||||
|
|
||||||
parser = module.parse_arguments(COMMAND_NAME, '--verbosity', '1')
|
parser = module.parse_arguments(COMMAND_NAME, '--verbosity', '1')
|
||||||
|
|
||||||
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME_PATTERN.format(COMMAND_NAME)
|
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME_PATTERN.format(COMMAND_NAME)
|
||||||
|
@ -33,6 +61,7 @@ def test_parse_arguments_with_verbosity_flag_overrides_default():
|
||||||
|
|
||||||
|
|
||||||
def test_parse_arguments_with_invalid_arguments_exits():
|
def test_parse_arguments_with_invalid_arguments_exits():
|
||||||
|
flexmock(os.path).should_receive('exists').and_return(True)
|
||||||
original_stderr = sys.stderr
|
original_stderr = sys.stderr
|
||||||
sys.stderr = sys.stdout
|
sys.stderr = sys.stdout
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,8 @@ def insert_datetime_mock():
|
||||||
).mock
|
).mock
|
||||||
|
|
||||||
|
|
||||||
CREATE_COMMAND = ('attic', 'create', '--exclude-from', 'excludes', 'repo::host-now', 'foo', 'bar')
|
CREATE_COMMAND_WITHOUT_EXCLUDES = ('attic', 'create', 'repo::host-now', 'foo', 'bar')
|
||||||
|
CREATE_COMMAND = CREATE_COMMAND_WITHOUT_EXCLUDES + ('--exclude-from', 'excludes')
|
||||||
|
|
||||||
|
|
||||||
def test_create_archive_should_call_attic_with_parameters():
|
def test_create_archive_should_call_attic_with_parameters():
|
||||||
|
@ -46,6 +47,20 @@ def test_create_archive_should_call_attic_with_parameters():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_archive_with_none_excludes_filename_should_call_attic_without_excludes():
|
||||||
|
insert_subprocess_mock(CREATE_COMMAND_WITHOUT_EXCLUDES)
|
||||||
|
insert_platform_mock()
|
||||||
|
insert_datetime_mock()
|
||||||
|
|
||||||
|
module.create_archive(
|
||||||
|
excludes_filename=None,
|
||||||
|
verbosity=None,
|
||||||
|
source_directories='foo bar',
|
||||||
|
repository='repo',
|
||||||
|
command='attic',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_create_archive_with_verbosity_some_should_call_attic_with_stats_parameter():
|
def test_create_archive_with_verbosity_some_should_call_attic_with_stats_parameter():
|
||||||
insert_subprocess_mock(CREATE_COMMAND + ('--stats',))
|
insert_subprocess_mock(CREATE_COMMAND + ('--stats',))
|
||||||
insert_platform_mock()
|
insert_platform_mock()
|
||||||
|
|
Loading…
Reference in a new issue