|
60 | 60 | from textual.widgets import DataTable, Footer, Button
|
61 | 61 |
|
62 | 62 | __app__ = 'Froster, a user friendly S3/Glacier archiving tool'
|
63 |
| -__version__ = '0.10.2' |
| 63 | +__version__ = '0.10.4' |
64 | 64 |
|
65 | 65 |
|
66 | 66 | class ConfigManager:
|
@@ -88,7 +88,9 @@ def __init__(self):
|
88 | 88 | # Initialize the variables that check if specific configuration sections have been initialized
|
89 | 89 | self.user_init = False
|
90 | 90 | self.aws_init = False
|
| 91 | + self.nih_init = False |
91 | 92 | self.s3_init = False
|
| 93 | + self.configuration_done = False |
92 | 94 |
|
93 | 95 | # Whoami
|
94 | 96 | self.whoami = getpass.getuser()
|
@@ -193,6 +195,9 @@ def __init__(self):
|
193 | 195 | # NIH configuration
|
194 | 196 | self.is_nih = config.getboolean('NIH', 'is_nih', fallback=None)
|
195 | 197 |
|
| 198 | + # Set nih init flag |
| 199 | + self.nih_init = True if self.is_nih is not None else False |
| 200 | + |
196 | 201 | # Current S3 Bucket name
|
197 | 202 | self.bucket_name = config.get(
|
198 | 203 | 'S3', 'bucket_name', fallback=None)
|
@@ -241,6 +246,10 @@ def __init__(self):
|
241 | 246 | self.ec2_last_instance = config.get(
|
242 | 247 | 'CLOUD', 'ec2_last_instance', fallback=None)
|
243 | 248 |
|
| 249 | + if self.user_init and self.aws_init and self.s3_init and self.nih_init: |
| 250 | + self.configuration_done = True |
| 251 | + |
| 252 | + |
244 | 253 | def __repr__(self):
|
245 | 254 | ''' Return a string representation of the object'''
|
246 | 255 |
|
@@ -4664,26 +4673,33 @@ def convert_size(self, size_bytes):
|
4664 | 4673 |
|
4665 | 4674 | def _archive_json_add_entry(self, key, value):
|
4666 | 4675 | '''Add a new entry to the archive JSON file'''
|
| 4676 | + try: |
4667 | 4677 |
|
4668 |
| - # Initialize the data dictionary in case archive_json does not exist |
4669 |
| - data = {} |
| 4678 | + # Initialize the data dictionary in case archive_json does not exist |
| 4679 | + data = {} |
4670 | 4680 |
|
4671 |
| - # Read the archive JSON file |
4672 |
| - if os.path.isfile(self.archive_json): |
4673 |
| - with open(self.archive_json, 'r') as file: |
4674 |
| - try: |
4675 |
| - data = json.load(file) |
4676 |
| - except: |
4677 |
| - print('Error in Archiver._archive_json_add_entry():') |
4678 |
| - print(f'Cannot read {self.archive_json}, file corrupt?') |
4679 |
| - return False |
| 4681 | + # Read the archive JSON file |
| 4682 | + if os.path.isfile(self.archive_json): |
| 4683 | + with open(self.archive_json, 'r') as file: |
| 4684 | + try: |
| 4685 | + data = json.load(file) |
| 4686 | + except: |
| 4687 | + print('Error in Archiver._archive_json_add_entry():') |
| 4688 | + print( |
| 4689 | + f'Cannot read {self.archive_json}, file corrupt?') |
| 4690 | + return |
4680 | 4691 |
|
4681 |
| - # Add the new entry to the data dictionary |
4682 |
| - data[key] = value |
| 4692 | + # Add the new entry to the data dictionary |
| 4693 | + data[key] = value |
4683 | 4694 |
|
4684 |
| - # Write the updated data dictionary to the archive JSON file |
4685 |
| - with open(self.archive_json, 'w') as file: |
4686 |
| - json.dump(data, file, indent=4) |
| 4695 | + # Create the directory for the archive JSON file if it does not exist |
| 4696 | + os.makedirs(os.path.dirname(self.archive_json), exist_ok=True) |
| 4697 | + |
| 4698 | + # Write the updated data dictionary to the archive JSON file |
| 4699 | + with open(self.archive_json, 'w') as file: |
| 4700 | + json.dump(data, file, indent=4) |
| 4701 | + except: |
| 4702 | + print_error() |
4687 | 4703 |
|
4688 | 4704 | def _is_folder_archived(self, folder):
|
4689 | 4705 | '''Check if an entry exists in the archive JSON file'''
|
@@ -5221,7 +5237,7 @@ def _run_rclone_command(self, command, background=False):
|
5221 | 5237 |
|
5222 | 5238 | # This is the solution i found to prevent the popen subprocess to throw errors due
|
5223 | 5239 | # our particular usage of rclone.
|
5224 |
| - output = True |
| 5240 | + output = False |
5225 | 5241 |
|
5226 | 5242 | if output:
|
5227 | 5243 | # Print output in stdout
|
@@ -6558,6 +6574,13 @@ def main():
|
6558 | 6574 | if cfg.is_shared and cfg.shared_dir:
|
6559 | 6575 | cfg.assure_permissions_and_group(cfg.shared_dir)
|
6560 | 6576 |
|
| 6577 | + # Do not allow other commands rather than config if the configuration is not set |
| 6578 | + if not cfg.configuration_done and args.subcmd not in ['config', 'cnf']: |
| 6579 | + print('\nFroster is not full configured yet.\n') |
| 6580 | + print('Run "froster config" for a full new configuration.') |
| 6581 | + print('Run "froster config --help" for more information.\n') |
| 6582 | + sys.exit(1) |
| 6583 | + |
6561 | 6584 | # call a function for each sub command in our CLI
|
6562 | 6585 | if args.subcmd in ['config', 'cnf']:
|
6563 | 6586 | subcmd_config(args, cfg, aws)
|
|
0 commit comments