OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
make-m2-proxy Namespace Reference

Functions

def simple_xml
 
def gen_proxy
 
def make_settings
 
def main
 

Variables

tuple _made_ids = set()
 

Function Documentation

def make-m2-proxy.gen_proxy (   var_name)

Definition at line 23 of file make-m2-proxy.py.

References simple_xml().

Referenced by make_settings().

23 
24 def gen_proxy(var_name):
25  value = os.environ.get(var_name, '')
26  if not value:
27  return None
28  try:
29  parsed = re.search(r'''((?P<protocol>[^:]+)://)? # protocol followed by ://, optional
30  ((?P<username>[^:]+)(:(?P<password>[^@]+))?@)? # user:password part, optional
31  (?P<host>[^@]+?) # hostname, which is basically everything but other known parts
32  (:(?P<port>\d+))? # port, optional
33  $''', value, re.VERBOSE).groupdict()
34  except AttributeError:
35  sys.stderr.write('WARNING: unexpected format, could not parse $%s=%s\n' % (var_name, value))
36  return None
37 
38  if not parsed['host']:
39  return None
40  id_name = var_name.lower()
41  if id_name in _made_ids:
42  num = 0
43  while ('%s.%s' % (id_name, num)) in _made_ids:
44  num +=1
45  id_name = '%s.%s' % (id_name, num)
46  _made_ids.add(id_name)
47  sections = [('id', id_name), ('active', 'true')]
48  for param_name in ('protocol', 'host', 'port', 'username', 'password'):
49  if parsed[param_name]:
50  sections.append((param_name, parsed[param_name]))
51  return simple_xml('proxy', sections)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def make-m2-proxy.main ( )

Definition at line 70 of file make-m2-proxy.py.

References make_settings(), and heavyai.open().

70 
71 def main():
72  settings = make_settings('http_proxy', 'HTTP_PROXY', 'https_proxy', 'HTTPS_PROXY')
73  target = os.path.expanduser('~/.m2/settings.xml')
74  if not settings:
75  try:
76  os.remove(target)
77  except OSError as ex:
78  if ex.errno != errno.ENOENT:
79  raise
80  return
81  try:
82  os.makedirs(os.path.dirname(target))
83  except OSError as ex:
84  if ex.errno != errno.EEXIST:
85  raise
86  with open(target, 'w') as out:
87  out.write(settings)
int open(const char *path, int flags, int mode)
Definition: heavyai_fs.cpp:66

+ Here is the call graph for this function:

def make-m2-proxy.make_settings (   var_names)

Definition at line 52 of file make-m2-proxy.py.

References gen_proxy(), and join().

Referenced by main().

52 
53 def make_settings(*var_names):
54  sections = []
55  for name in var_names:
56  value = gen_proxy(name)
57  if value:
58  sections.append(value)
59  if not sections:
60  return None
61  template = '''<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
62  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
63  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
64  https://maven.apache.org/xsd/settings-1.0.0.xsd">
65  <proxies>
66 %s
67  </proxies>
68 </settings>'''
69  return template % '\n'.join(sections)
std::string join(T const &container, std::string const &delim)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def make-m2-proxy.simple_xml (   name,
  sections 
)
very simple xml generator for one-level depth items 

Definition at line 13 of file make-m2-proxy.py.

References join().

Referenced by gen_proxy().

13 
14 def simple_xml(name, sections):
15  ''' very simple xml generator for one-level depth items '''
16  result = ['<%s>' % name]
17  for sec_name, sec_value in sections:
18  result.append(' <{0}>{1}</{0}>'.format(sec_name, sec_value))
19  result.append('</%s>' % name)
20  return '\n'.join(' ' + line for line in result)
std::string join(T const &container, std::string const &delim)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

tuple make-m2-proxy._made_ids = set()

Definition at line 21 of file make-m2-proxy.py.