-
Notifications
You must be signed in to change notification settings - Fork 115
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
Added hardlink and copy options #172
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! Seems like a useful addition
Two things:
-
I'll merge Migrate from
os.rename
toshutil.move
#161 just now - would you mind rebasing your changes on to this? -
Would it be possible to merge the options into one "how to move the file" option?
As in instead of separate
always_copy
andalways_hardlink
booleans (which are mutually exclusive), it would be neater if there was something like a "move mode" type enum option (which could be set to "always copy", or "hardlink or copy" etc)Would need a bit of thought as to what options are needed, particularly to cover what happens when a certain operation isn't possible (e.g hardlink to a different drive isn't possible).
This would deprecate the
always_move
option - I think that can be handled quite easily - ifalways_move
is True, set themove_mode
option to the appropriate setting and output a deprecation warning.
tvnamer/utils.py
Outdated
@@ -1093,16 +1102,21 @@ def newPath(self, new_path = None, new_fullpath = None, force = False, always_co | |||
new_fullpath, self.filename)) | |||
|
|||
if same_partition(self.filename, new_dir): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, there is another pull request pending merging, #161, which will conflict with this (the same_partition
stuff is removed)
master branch should be good to rebase with if you have the time - I've also fixed up the integration tests which were failing, so the Travis status should be valid again \o/ |
You're welcome. Thank you to you, this tools is very useful and represent a fair amount of work!
This is indeed a problem. I could do without the
I thought of doing that at the beginning but did not want to propose to big of a change. I also think it would be better but will also require some refactoring. I will look into it. I need to get more into the different config options before doing anything clean. Just to be clear, if I understand correctly the code and your proposition, your are suggesting to use Also, sometimes functions use Config[...], sometimes they take those as parameter and some other time a mix of both. Is there a guideline of some sort ? |
Great! I'll rebase the code ASAP |
Yep I think this is correct:
A lot of that is legacy of the config being introduced later because lots of functions took too many arguments When things should be an simple argument (e.g bool/str) versus using the config is slightly tricky, as with hindsight I don't think the config should have been a global object (ideally the config would be passed to the relevant "core" parts of the code, and then when lower level functions just use one or two options, it would be clearer when the config items can be neatly passed in as arguments) I guess it should mostly boil down to making things easy to unit-test - it is easier to write a test for a function which takes a bool than uses the config. However with methods like |
So as a first-pass, I think the modes required are:
|
I started rebasing. Do I revert the same_partition function or not ? |
Ok, digging more into |
bdbcce8
to
b2558b8
Compare
I am not convinced by the idea that it should always fallback. In my use case, I would prefer it to not copy some huge files and fail or skip it with an error message. I suggest to use two options |
I implemented the new
Should I keep the always_move and leave_symlink options in the config file for retro-compatibility ? They would then simply set the right mode except that I would need to handle the case where the mode is also set at the same time. What should be the behavior then ? I suppose, an error since a user of the previous config won't see anything break. |
Good point - that set of options seem good to me! For maintaining backwards compatibility, I think what you suggest is pretty much the way to do it. Specifically I would suggest:
|
I pass almost all the tests but two because, as stated previously, I had to inverse to order in which we "rename then move" to "move then rename". This is necessary for the copy and linking type of moves as the idea would be to keep the original files unchanged. As you discussed in #40, the behavior should change and I agree. I think that a small step in that direction is worth taking in this PR as it is the "logical thing to do" to implement copy and linking. Now, to issue arise: What about backwards compatibility and how to do it ?
The failing tests are:
Also, I do not understand why the two input files (scrubs.s01e01.avi and scrubs - [01x01].avi) were processed in one order in |
This isn't intend behaviour, just a side-effect of of retrofitting the move feature - I'm definitely happy if that can be fixed! For the implementation, the builder approach sounds reasonable - sounds similar to the approach I started taking with an experimental version of tvnamer written in Rust, Not sure how familiar you are with Rust, but it is essentially how I intended (or intend) tvnamer's code to be structured - fairly well summarised in this method: ..allowing more complex action chaining is definitely a future thing - but if the Renamer class could be refactored to something vaguely in line with this, that'd be good |
This PR adds the ability to leave original files untouched and copy or create a hard link to them.
I think it answers issues partially #46, I think #40 and #10
I added the command line options:
-C
or--copy
To copy a file (compatible with -d option)-l
or--link
To hard link a file (compatible with -d option)I added the config options:
always_copy
To always copy filesprefer_hardlink_to_copy
To create a hardlink when possible if copyingalways_hardlink
To always hardlinkI am quite new to this tool (and to contributing) so I may have not seen some corner cases.
The biggest change I had to do is renaming file after moving/copying them. This was to avoid making too many changes to the code base.