-
Notifications
You must be signed in to change notification settings - Fork 111
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
Copy files to journal #469
Draft
ruhugu
wants to merge
12
commits into
jendrikseipp:master
Choose a base branch
from
ruhugu:copy-files-to-journal
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2068bff
Add function to copy files without overwriting
ruhugu 4b3ea12
Add method in Journal to copy files to journal dir
ruhugu 74b6884
Check there is a media folder when opening journal
ruhugu baa3924
Make get_journal_files() ignore media dir
ruhugu 79a4ae0
Integrate add_file in insert_menu.py methods
ruhugu 68bb051
Change behaviour of Save As to copy media files
ruhugu af122b4
Don't create the media dir until is needed
ruhugu 449c390
Pull changes from master
ruhugu e0b5642
Replace safecopy function with copy
ruhugu e8c40f3
Add media_dir method to Filenames class
ruhugu 26bf74b
Make "Save as" copy media dir only if it exits
ruhugu e3436b1
Minor changes to comments and log messages
ruhugu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -347,6 +347,16 @@ def open_journal(self, data_dir): | |
|
||
self.months = storage.load_all_months_from_disk(data_dir) | ||
|
||
# Create the media folder if it does not exist | ||
# TODO: read media folder path from dirs | ||
media_dir = os.path.join(self.dirs.data_dir, 'media') | ||
try: | ||
filesystem.make_directory(media_dir) | ||
except OSError as err: | ||
logging.error( | ||
'Creating journal media directory failed: {}'.format(err)) | ||
return | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's only create the media dir when we need it, i.e., right before storing a file. |
||
# Nothing to save before first day change | ||
self.load_day(self.actual_date) | ||
|
||
|
@@ -556,6 +566,56 @@ def add_instruction_content(self): | |
|
||
self.change_date(current_date) | ||
|
||
def add_file(self, src): | ||
''' | ||
Copy file to journal directory. | ||
|
||
The file is copied to the directory: | ||
<journal_path>/media/<year>_<month> | ||
|
||
If a different file with the same name is found in the destination | ||
directory, the copy filename is modified to avoid overwritting. | ||
See util.filesystem.safecopy() function for details. | ||
|
||
The destination path of the copied relative to the journal | ||
directory file is returned. | ||
If there is a problem while copying the file, a None vale is | ||
returned. | ||
''' | ||
# TODO: read media folder path from dirs | ||
media_dir = os.path.join(self.dirs.data_dir, 'media') | ||
try: | ||
filesystem.make_directory(media_dir) | ||
except OSError as err: | ||
logging.error( | ||
'Creating journal media directory failed: {}'.format(err)) | ||
return | ||
|
||
# Create month directory | ||
monthmedia_dirname = storage.format_year_and_month( | ||
self.date.year, self.date.month) | ||
monthmedia_dir = os.path.join(media_dir, monthmedia_dirname) | ||
try: | ||
filesystem.make_directory(monthmedia_dir) | ||
except OSError as err: | ||
logging.error('Creating month media directory failed: {}'.format(err)) | ||
return | ||
|
||
# Copy file to previous dir | ||
dst = os.path.join( | ||
monthmedia_dir, os.path.basename(src)) | ||
try: | ||
dst = filesystem.safecopy(src, dst) | ||
except OSError as err: | ||
logging.error( | ||
'Copying file to journal directory failed: {}'.format(err)) | ||
return | ||
|
||
dst_rel = filesystem.get_relative_path( | ||
self.dirs.data_dir, dst) | ||
|
||
return dst_rel | ||
|
||
|
||
def main(): | ||
start_time = time.time() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think it's best to add a property
Filesystem.media_dir(self): return os.path.join(self.data_dir, 'media')
.