Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A simple script to provide multiple profiles for your maven settings at {user.home}/.m2/settings.xml. See description in the python file below for details.
description = """A simple script to provide multiple profiles for your maven settings at {user.home}/.m2/settings.xml.
With the folder structure like below, profile [home] and [work] will be available be used.
{user.home}/.m2/profile
|-home
| |-settings.xml
|-work
| |-settings.xml
"""
import argparse, os, shutil
from argparse import RawTextHelpFormatter
parser = argparse.ArgumentParser(description=description, formatter_class=RawTextHelpFormatter)
parser.add_argument('profile')
args = parser.parse_args()
settings_home = os.path.join(os.environ['HOME'], ".m2")
os.chdir(settings_home)
profile_dir = "profile"
# Creates sample profile folder if not exist yet
if not os.path.exists(profile_dir):
print('First time running the script. Creating "home" and "work" profile directory at {}'.format(
os.path.abspath(profile_dir)))
os.makedirs(os.path.join(profile_dir, "home"))
os.makedirs(os.path.join(profile_dir, "work"))
# Proceed with profile copying
profile_settings = os.path.join(profile_dir, args.profile, "settings.xml")
if os.path.exists(profile_settings):
print("Switching [{}] to [{}]".format(os.path.abspath("settings.xml"), args.profile))
shutil.copyfile(profile_settings, "settings.xml")
else:
print("Profile [{}] doesn't exist.".format(args.profile))
print("The profile settings should be located here: [{}]".format(os.path.abspath(profile_settings)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment