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

Config changes per Issue #11 #12

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft

Conversation

dgou
Copy link
Contributor

@dgou dgou commented Jul 9, 2023

@peterkaminski
Submitting this as a pull request, but still WIP.
All the config file loading stuff is done.
The copy/diff part is NOT done because I have questions about how backups work when we start cherry-picking files deeper in the vault configuration than the top level directories.

To requests:

  1. Review the code so far. README is yet to come!
  2. Discuss in OSM needs config file(s), and needs to find obsidian.json #11 what we want the backup strategy to look like.

dgou added 13 commits July 8, 2023 15:24
Keeping the next diff cleaner.
No code changes, just adding comments and moving code.
The diff is bad enough without having to look for a code change too.
Next commits will implement based on comments/discussion from:
peterkaminski#11
The encoded JSON needs to be a raw string to prevent backslash quoting explosion
Added primitive tracing to help when things do work as expected.
Very preliminary implmentation. ENV VARs are a quick way to
set values before the command line is parsed but aren't as user friendly.
This also involved tracking the Obsidian Root dirctory since it is
no longer a parameter or env var to the script
Also, hoist the code for version and config printing to above
where the configs are loaded. They don't depend on it, and this makes
it easier to bootstrap a custom configuration.
@dgou dgou marked this pull request as draft July 9, 2023 02:09
osm.py Outdated
@@ -401,6 +417,8 @@ def main():
print("Error: Cannot locate the 'diff' command, aborting.")
exit(-1)

load_osm_config()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I know, I forgot the args.config parameter here, it will be fixed in a later commit :-)

dgou added 2 commits July 9, 2023 08:16
Helps us to be more careful about using the config.
Usages to follow in the next commits.
Next commits will implement finding the files in a specific vault.
osm.py Outdated
@@ -492,6 +538,7 @@ def main():

try:
vault_paths = get_vault_paths()
directives = list(get_processing_directives())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was on the fence about where in the code to do this as it is a defacto check on the configuration file even if no file operations are going to be performed.
On the one hand, validating early is good.
On the the other hand, validating when it won't be used (say for --list) could make it harder for someone to incrementally create/tweak their config...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way is fine, of course - I can make UX arguments either way, and so for me, the UX arguments are kind of a wash.

Tiebreaker might be simplicity / readability of the code itself, and I think that argues for validating early.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think I am ok with early too until a compelling argument comes in for postponing.

dgou added 4 commits July 9, 2023 09:40
Probably needs more work too.
It's much easier on the human brain to see them in sorted order
esp when looking at diffs.
Sure, you could use `--diff-to` and try to sort it out, but as you
are adjusting your files_to_copy list, it would be nice to see
how it would pull files from a specific vault without the other output
@dgou
Copy link
Contributor Author

dgou commented Jul 9, 2023

Putting pen down as of commit 19 to sort out the backups thing.

dgou added 2 commits July 10, 2023 22:27
Was left over from when there were two separate backup action functions.
]
],
"backup": {
"archive_format_priority_list": ["zip", "gztar", "bztar", "xztar", "tar"],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peterkaminski the idea here is that since any one format might not be available, better to have a list of preferred formats, and work left to right until make_archive works.
I'm open to better names for the keys/values here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks fine to me.

@dgou
Copy link
Contributor Author

dgou commented Jul 22, 2023

Whoa, has it been two weeks! Crikey!
Planning on working more on this today, day-job has been unexpectedly long hours.

@peterkaminski
Copy link
Owner

Whoa, has it been two weeks! Crikey! Planning on working more on this today, day-job has been unexpectedly long hours.

Me too! 🙂

dgou added 2 commits July 22, 2023 14:21
Remove the leading dash so that it can be used as a prefix.
Match the ISO string anywhere, prefix, suffix, or embedded.
Also backup before doing an update.

NOTE: update hasn't been fixed yet,
      only the backup code is working at this point
@dgou
Copy link
Contributor Author

dgou commented Jul 22, 2023

@peterkaminski - take a look at the latest two commits.
the update functionality isn't done yet, but I wanted to get your thoughts on the new backup code, the new command options, etc.

osm.py Outdated
try:
backup_file = shutil.make_archive(backup_file, backup_format, root_dir=backup_from_dir)
if backup_file:
print("Backup made:", backup_file)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we like how this works, I'll update to have versbose and dry-run implemented. The trick with dry-run though is that until we try to call make_archive we don't know for sure sure sure if that format is actually supported.
There is https://docs.python.org/3/library/shutil.html#shutil.get_archive_formats but I am not sure if those are guaranteed to work, or if they are just potentially available...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shutil.make_archive() takes a dry_run boolean. ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D'oh! So it does! I think I knew that when I first found it, but then forgot, thanks!

@peterkaminski
Copy link
Owner

the update functionality isn't done yet, but I wanted to get your thoughts on the new backup code, the new command options, etc.

@dgou, looks good to me.

@@ -536,7 +536,7 @@ def diff_settings(dest, src):


def backup_vault(vault_path):
print('#', vault_path)
print(f'# Backing up settings for: {vault_path}')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure about keeping this as print vs verbose but when I was testing it I liked seeing that it was doing something and where, but I'm open to making this verbose instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants