Skip to content

Commit

Permalink
Add `auto' linking option to Python jgo
Browse files Browse the repository at this point in the history
Fixes #22
  • Loading branch information
hanslovsky committed Nov 27, 2018
1 parent 944f61c commit cc05988
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions jgo/jgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,30 @@ def executable_path_or_raise(tool):
def executable_path(tool):
return shutil.which(tool)

def link(source, link_name, link_type="hard"):
if link_type.lower() == "soft":
os.symlink(source, link_name)
elif link_type.lower() == "hard":
os.link(source, link_name)
else:
shutil.copyfile(source, link_name)
def link(source, link_name, link_type='auto'):
_logger.debug("Linking source %s to target %s with link_type %s", source, link_name, link_type)
if link_type.lower() == 'soft':
return os.symlink(source, link_name)
elif link_type.lower() == 'hard':
return os.link(source, link_name)
elif link_type.lower() == 'copy':
return shutil.copyfile(source, link_name)
elif link_type.lower() == 'auto':
try:
return link(source=source, link_name=link_name, link_type='hard')
except OSError as e:
if e.errno != 18:
raise e
try:
return link(source=source, link_name=link_name, link_type='soft')
except OSError as e:
pass

return link(source=source, link_name=link_name, link_type='copy')

raise Exception('Unable to link source {} to target {} with link_type {}', source, link_name, link_type)



def m2_path():
return os.getenv("M2_REPO", (pathlib.Path.home() / '.m2').absolute())
Expand Down Expand Up @@ -225,7 +242,7 @@ def jgo_main(argv=sys.argv[1:]):
parser.add_argument('-a', '--additional-jars', nargs='+', help='Add additional jars to classpath', default=[], required=False)
parser.add_argument( '--additional-endpoints', nargs='+', help='Add additional endpoints', default=[], required=False)
parser.add_argument('--ignore-jgorc', action='store_true', help='Ignore ~/.jgorc')
parser.add_argument('--link-type', default=None, type=str, help='How to link from local maven repository into jgo cache. Defaults to the `links\' setting in ~/.jrunrc or \'hard\' if not specified.', choices=('hard', 'soft', 'copy'))
parser.add_argument('--link-type', default=None, type=str, help='How to link from local maven repository into jgo cache. Defaults to the `links\' setting in ~/.jrunrc or \'auto\' if not specified.', choices=('hard', 'soft', 'copy', 'auto'))


try:
Expand Down Expand Up @@ -271,7 +288,7 @@ def default_config():
config.add_section('settings')
config.set('settings', 'm2Repo', os.path.join(str(pathlib.Path.home()), '.m2', 'repository'))
config.set('settings', 'cacheDir', os.path.join(str(pathlib.Path.home()), '.jgo'))
config.set('settings', 'links', 'hard')
config.set('settings', 'links', 'auto')

# repositories
config.add_section('repositories')
Expand Down Expand Up @@ -345,7 +362,7 @@ def resolve_dependencies(
endpoint_string,
cache_dir,
m2_repo,
link_type='hard',
link_type='auto',
update_cache=False,
force_update=False,
manage_dependencies=False,
Expand Down

0 comments on commit cc05988

Please sign in to comment.