Created
July 9, 2014 09:31
-
-
Save ceilfors/0f4831280f3c6fa30952 to your computer and use it in GitHub Desktop.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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