For this assignment, you are going to pretend that you are writing an application that uses JSON to store configuration data in it.

First, you are going to start by writing a JSON file called ("basic_config.json") that stores the following variables and their associated values:

1. Safe Mode - "On"
2. Memory - "32MB"
3. Error Log - "logs/errors.log"

Your program is going to load all of these values up on startup, display them just like I have them above, and then give the user the option to either modify an existing value or add new ones.

Use your program to add the following configuration options:

Allow File Uploads - "Yes"
Use Caching - "Yes"
Caching File - "cache/filecache.cache"
Mail Host - ""

Give the user the option to either save their changes or discard them. If the user chooses to accept the changes, the new configuration will be saved as config_override.json. Under no circumstances should basic_config.json ever be overwritten.

On subsequent program runs, in order to make this work properly, you are going to need to implement a check to see if config_override.json exists before loading the information in basic_config.json. In other words, once basic_config.json has been overwritten, you should always load config_override.json from that point on to make your changes and adjustments. When you save back, you must have a means in place to backup your old file. You do not need to have functionality in place to have your applications load or restore data from old backups.

Users may modify the value of any setting they wish, but they can only delete configurations for the following items:

Allow File Uploads - "Yes"
Use Caching - "Yes"
Caching File - "cache/filecache.cache"
Mail Host - ""

In other words, the keys contained in the basic_config.json file are all required. You must add logic and decide the best way to delete items the user wishes to remove.

Finally, you will create functions to (minimally - you can and probably should write more functions than the ones listed below) handle the following tasks:

Loading the information from the proper configuration file
Saving configuration data.
Adding a configuration
Please note that you must organize your functions into modules and produce documentation (using Pydoc) for your work using the principles discussed earlier in the class. You must also include exception handling in your code according to the principles previously discussed and explored in more detail this week.

Be sure to put comments in your code that clearly mark how you are performing your program logic.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import json

allowed_delete = ["Allow File Uploads", "Use Caching",
                  "Caching File", "Mail Host"]

def load_config():

    Load into program the configurations paramaters,
    if 'config_override.json' file is not found
    'basic_config.json' file is loaded instead

    return: Dictionary with the key, value pairs of configuration parameters
    basic_file = "basic_config.json"
    override_file = "config_override.json"
       with open(override_file) as f:
            data = json.load(f)

       with open(basic_file) as f:
            data = json.load(f)

    return data

def show_config(data):

    Prints in console the parameters configuration loaded,
    in a list format with the key and value for each

    return: None

By purchasing this solution you'll be able to access the following files:

for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats