-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy path__init__.py
More file actions
162 lines (119 loc) · 4.22 KB
/
__init__.py
File metadata and controls
162 lines (119 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import logging
import os
import pathlib
import jpype
from jgo import maven_scijava_repository
_logger = logging.getLogger(__name__)
endpoints = []
_repositories = {'scijava.public': maven_scijava_repository()}
_verbose = 0
_manage_deps = True
_cache_dir = pathlib.Path.home() / '.jgo'
_m2_repo = pathlib.Path.home() / '.m2' / 'repository'
_options = []
def add_endpoints(*new_endpoints):
"""
DEPRECATED since v1.2.1
Please modify the endpoints field directly instead.
"""
_logger.warning('Deprecated method call: scyjava.config.add_endpoints(). Please modify scyjava.config.endpoints directly instead.')
global endpoints
_logger.debug('Adding endpoints %s to %s', new_endpoints, endpoints)
endpoints.extend(new_endpoints)
def get_endpoints():
"""
DEPRECATED since v1.2.1
Please access the endpoints field directly instead.
"""
_logger.warning('Deprecated method call: scyjava.config.get_endpoints(). Please access scyjava.config.endpoints directly instead.')
global endpoints
return endpoints
def add_repositories(*args, **kwargs):
global _repositories
for arg in args:
_logger.debug('Adding repositories %s to %s', arg, _repositories)
_repositories.update(arg)
_logger.debug('Adding repositories %s to %s', kwargs, _repositories)
_repositories.update(kwargs)
def get_repositories():
global _repositories
return _repositories
def set_verbose(level):
global _verbose
_logger.debug('Setting verbose level to %d (was %d)', level, _verbose)
_verbose = level
def get_verbose():
global _verbose
_logger.debug('Getting verbose level: %d', _verbose)
return _verbose
def set_manage_deps(manage):
global _manage_deps
_logger.debug('Setting manage deps to %d (was %d)', manage, _manage_deps)
_manage_deps = manage
def get_manage_deps():
global _manage_deps
return _manage_deps
def set_cache_dir(dir):
global _cache_dir
_logger.debug('Setting cache dir to %s (was %s)', dir, _cache_dir)
_cache_dir = dir
def get_cache_dir():
global _cache_dir
return _cache_dir
def set_m2_repo(dir):
global _m2_repo
_logger.debug('Setting m2 repo dir to %s (was %s)', dir, _m2_repo)
_m2_repo = dir
def get_m2_repo():
global _m2_repo
return _m2_repo
def add_classpath(*path):
"""
Add elements to the Java class path.
See also find_jars, which can be combined with add_classpath to
add all the JARs beneath a given directory to the class path, a la:
add_classpath(*find_jars('/path/to/folder-of-jars'))
:param path:
One or more file paths to add to the Java class path.
A valid Java class path element is typically either a .jar file or a
directory. When a class needs to be loaded, the Java runtime looks
beneath each class path element for the .class file, nested in a folder
structure matching the class's package name. For example, when loading
a class foo.bar.Fubar, if a directory /home/jdoe/classes is included as
a class path element, the class file at
/home/jdoe/classes/foo/bar/Fubar.class will be used. It works the same
for JAR files, except that the class files are loaded from the
directory structure inside the JAR; in this example, a JAR file
/home/jdoe/jars/fubar.jar on the class path containing file
foo/bar/Fubar.class inside would be another way to provide the class
foo.bar.Fubar.
"""
for p in path:
jpype.addClassPath(p)
def find_jars(directory):
"""
Find .jar files beneath a given directory.
:param directory: the folder to be searched
:return: a list of JAR files
"""
jars = []
for root, dirs, files in os.walk(directory):
for f in files:
if f.lower().endswith('.jar'):
path = os.path.join(root, f)
jars.append(path)
return jars
def get_classpath():
return jpype.getClassPath()
def add_option(option):
global _options
_options.append(option)
def add_options(options):
global _options
if isinstance(options, str):
_options.append(options)
else:
_options.extend(options)
def get_options():
global _options
return _options