Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_apps_to_backup(self):
"""
Get the list of applications that should be backed up by Mackup.
It's the list of allowed apps minus the list of ignored apps.
Returns:
(set) List of application names to back up
"""
# Instantiate the app db
app_db = appsdb.ApplicationsDatabase()
# If a list of apps to sync is specify, we only allow those
# Or we allow every supported app by default
apps_to_backup = self._config.apps_to_sync or app_db.get_app_names()
# Remove the specified apps to ignore
for app_name in self._config.apps_to_ignore:
apps_to_backup.discard(app_name)
return apps_to_backup
def __init__(self):
"""Create a ApplicationsDatabase instance."""
# Build the dict that will contain the properties of each application
self.apps = dict()
for config_file in ApplicationsDatabase.get_config_files():
config = configparser.SafeConfigParser(allow_no_value=True)
# Needed to not lowercase the configuration_files in the ini files
config.optionxform = str
if config.read(config_file):
# Get the filename without the directory name
filename = os.path.basename(config_file)
# The app name is the cfg filename with the extension
app_name = filename[: -len(".cfg")]
# Start building a dict for this app
self.apps[app_name] = dict()
# Add the fancy name for the app, for display purpose
app_pretty_name = config.get("application", "name")
elif args["restore"]:
# Check the env where the command is being run
mckp.check_for_usable_restore_env()
# Restore the Mackup config before any other config, as we might need
# it to know about custom settings
mackup_app = ApplicationProfile(
mckp, app_db.get_files(MACKUP_APP_NAME), dry_run, verbose
)
printAppHeader(MACKUP_APP_NAME)
mackup_app.restore()
# Initialize again the apps db, as the Mackup config might have changed
# it
mckp = Mackup()
app_db = ApplicationsDatabase()
# Restore the rest of the app configs, using the restored Mackup config
app_names = mckp.get_apps_to_backup()
# Mackup has already been done
app_names.discard(MACKUP_APP_NAME)
for app_name in sorted(app_names):
app = ApplicationProfile(mckp, app_db.get_files(app_name), dry_run, verbose)
printAppHeader(app_name)
app.restore()
elif args["uninstall"]:
# Check the env where the command is being run
mckp.check_for_usable_restore_env()
if dry_run or (
def main():
"""Main function."""
# Get the command line arg
args = docopt(__doc__, version="Mackup {}".format(VERSION))
mckp = Mackup()
app_db = ApplicationsDatabase()
def printAppHeader(app_name):
if verbose:
print(("\n{0} {1} {0}").format(header("---"), bold(app_name)))
# If we want to answer mackup with "yes" for each question
if args["--force"]:
utils.FORCE_YES = True
dry_run = args["--dry-run"]
verbose = args["--verbose"]
if args["backup"]:
# Check the env where the command is being run
mckp.check_for_usable_backup_env()