Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New export command (issue #435) #2510

Merged
merged 27 commits into from
Jun 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4745c26
New export command
SpirosChadoulos Apr 13, 2017
8f3ca12
Put export before confirm
SpirosChadoulos Apr 14, 2017
d4413a2
obj instead of item
SpirosChadoulos Apr 14, 2017
a99b7e9
Provided default value for export.
SpirosChadoulos Apr 16, 2017
5361825
added 1 line before for loop
SpirosChadoulos Apr 19, 2017
7018307
deleted else
SpirosChadoulos Apr 19, 2017
3e9076b
deleted else
SpirosChadoulos Apr 19, 2017
de57602
fixed certain errors
SpirosChadoulos Apr 19, 2017
60318f1
fixed line length
SpirosChadoulos Apr 19, 2017
bab99f5
Added a test for the new export feature
SpirosChadoulos Apr 30, 2017
a881922
ExportTest correction
SpirosChadoulos Apr 30, 2017
90c30d8
Added an if album: statement
SpirosChadoulos May 4, 2017
167ae91
Changes at line 1486
SpirosChadoulos May 4, 2017
f5b23ff
Replaced all AssertNotExists with AssertExists
SpirosChadoulos May 6, 2017
0dc948d
Made sure that the destination directory will exist
SpirosChadoulos May 11, 2017
51835e7
Minor fixes to move tests
SpirosChadoulos May 11, 2017
c4ef23d
Minor Flake fixes
SpirosChadoulos May 11, 2017
8f62e8b
Requested changes done
SpirosChadoulos May 12, 2017
169cf59
Fixed bool variable error
SpirosChadoulos May 12, 2017
7c91989
Minor flake fixes
SpirosChadoulos May 12, 2017
3c852d3
docs
SpirosChadoulos May 13, 2017
29d6c27
Fix some spurious whitespace changes
sampsyo Jun 11, 2017
b25eb87
Remove unnecessary output capture
sampsyo Jun 11, 2017
2315287
Simplify implementation of export behavior
sampsyo Jun 11, 2017
714560a
Fix parameter order and binding
sampsyo Jun 11, 2017
730c84e
Correct tests for export mode
sampsyo Jun 11, 2017
ca4f96e
Consolidate export tests into MoveTest
sampsyo Jun 11, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions beets/ui/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,8 @@ def modify_func(lib, opts, args):

# move: Move/copy files to the library or a new base directory.

def move_items(lib, dest, query, copy, album, pretend, confirm=False):
def move_items(lib, dest, query, copy, album, pretend, confirm=False,
export=False):
"""Moves or copies items to a new base directory, given by dest. If
dest is None, then the library's base directory is used, making the
command "consolidate" files.
Expand All @@ -1463,6 +1464,7 @@ def move_items(lib, dest, query, copy, album, pretend, confirm=False):
isalbummoved = lambda album: any(isitemmoved(i) for i in album.items())
objs = [o for o in objs if (isalbummoved if album else isitemmoved)(o)]

copy = copy or export # Exporting always copies.
action = u'Copying' if copy else u'Moving'
act = u'copy' if copy else u'move'
entity = u'album' if album else u'item'
Expand All @@ -1488,8 +1490,12 @@ def move_items(lib, dest, query, copy, album, pretend, confirm=False):
for obj in objs:
log.debug(u'moving: {0}', util.displayable_path(obj.path))

obj.move(copy, basedir=dest)
obj.store()
if export:
# Copy without affecting the database.
obj.move(True, basedir=dest, store=False)
else:
# Ordinary move/copy: store the new path.
obj.move(copy, basedir=dest)


def move_func(lib, opts, args):
Expand All @@ -1500,7 +1506,7 @@ def move_func(lib, opts, args):
raise ui.UserError(u'no such directory: %s' % dest)

move_items(lib, dest, decargs(args), opts.copy, opts.album, opts.pretend,
opts.timid)
opts.timid, opts.export)


move_cmd = ui.Subcommand(
Expand All @@ -1522,6 +1528,10 @@ def move_func(lib, opts, args):
u'-t', u'--timid', dest='timid', action='store_true',
help=u'always confirm all actions'
)
move_cmd.parser.add_option(
u'-e', u'--export', default=False, action='store_true',
help=u'copy without changing the database path'
)
move_cmd.parser.add_album_option()
move_cmd.func = move_func
default_commands.append(move_cmd)
Expand Down
3 changes: 2 additions & 1 deletion docs/reference/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ box. To extract `rar` files, install the `rarfile`_ package and the
Optional command flags:

* By default, the command copies files your the library directory and
updates the ID3 tags on your music. In order to move the files, instead of
updates the ID3 tags on your music. In order to move the files, instead of
copying, use the ``-m`` (move) option. If you'd like to leave your music
files untouched, try the ``-C`` (don't copy) and ``-W`` (don't write tags)
options. You can also disable this behavior by default in the
Expand Down Expand Up @@ -275,6 +275,7 @@ query are renamed into your library directory structure. By specifying a
destination directory with ``-d`` manually, you can move items matching a query
anywhere in your filesystem. The ``-c`` option copies files instead of moving
them. As with other commands, the ``-a`` option matches albums instead of items.
The ``-e`` flag (for "export") copies files without changing the database.

To perform a "dry run", just use the ``-p`` (for "pretend") flag. This will
show you a list of files that would be moved but won't actually change anything
Expand Down
23 changes: 21 additions & 2 deletions test/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,9 @@ def setUp(self):
self.otherdir = os.path.join(self.temp_dir, b'testotherdir')

def _move(self, query=(), dest=None, copy=False, album=False,
pretend=False):
commands.move_items(self.lib, dest, query, copy, album, pretend)
pretend=False, export=False):
commands.move_items(self.lib, dest, query, copy, album, pretend,
export=export)

def test_move_item(self):
self._move()
Expand Down Expand Up @@ -476,6 +477,24 @@ def test_pretend_move_album(self):
self.i.load()
self.assertIn(b'srcfile', self.i.path)

def test_export_item_custom_dir(self):
self._move(dest=self.otherdir, export=True)
self.i.load()
self.assertEqual(self.i.path, self.itempath)
self.assertExists(self.otherdir)

def test_export_album_custom_dir(self):
self._move(dest=self.otherdir, album=True, export=True)
self.i.load()
self.assertEqual(self.i.path, self.itempath)
self.assertExists(self.otherdir)

def test_pretend_export_item(self):
self._move(dest=self.otherdir, pretend=True, export=True)
self.i.load()
self.assertIn(b'srcfile', self.i.path)
self.assertNotExists(self.otherdir)


class UpdateTest(_common.TestCase):
def setUp(self):
Expand Down