mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-23 09:08:26 +01:00
add python3 compatibility
This commit is contained in:
parent
cf543e94fa
commit
0936e2448a
@ -1,34 +1,43 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import ConfigParser
|
||||
import StringIO
|
||||
import os
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import print_function, unicode_literals # We require Python 2.6 or later
|
||||
from string import Template
|
||||
import os
|
||||
import six
|
||||
from io import open
|
||||
|
||||
if six.PY2:
|
||||
import ConfigParser as ConfigParser
|
||||
import StringIO as StringIO
|
||||
|
||||
if six.PY3:
|
||||
import configparser as ConfigParser
|
||||
import io as StringIO
|
||||
|
||||
#Read configurations
|
||||
conf = StringIO.StringIO()
|
||||
conf.write("[configuration]\n")
|
||||
conf.write(open("harbor.cfg").read())
|
||||
conf.seek(0, os.SEEK_SET)
|
||||
cp = ConfigParser.RawConfigParser()
|
||||
cp.readfp(conf)
|
||||
rcp = ConfigParser.RawConfigParser()
|
||||
rcp.readfp(conf)
|
||||
|
||||
hostname = cp.get("configuration", "hostname")
|
||||
ui_url = cp.get("configuration", "ui_url_protocol") + "://" + hostname
|
||||
email_server = cp.get("configuration", "email_server")
|
||||
email_server_port = cp.get("configuration", "email_server_port")
|
||||
email_username = cp.get("configuration", "email_username")
|
||||
email_password = cp.get("configuration", "email_password")
|
||||
email_from = cp.get("configuration", "email_from")
|
||||
harbor_admin_password = cp.get("configuration", "harbor_admin_password")
|
||||
auth_mode = cp.get("configuration", "auth_mode")
|
||||
ldap_url = cp.get("configuration", "ldap_url")
|
||||
ldap_basedn = cp.get("configuration", "ldap_basedn")
|
||||
db_password = cp.get("configuration", "db_password")
|
||||
self_registration = cp.get("configuration", "self_registration")
|
||||
hostname = rcp.get("configuration", "hostname")
|
||||
ui_url = rcp.get("configuration", "ui_url_protocol") + "://" + hostname
|
||||
email_server = rcp.get("configuration", "email_server")
|
||||
email_server_port = rcp.get("configuration", "email_server_port")
|
||||
email_username = rcp.get("configuration", "email_username")
|
||||
email_password = rcp.get("configuration", "email_password")
|
||||
email_from = rcp.get("configuration", "email_from")
|
||||
harbor_admin_password = rcp.get("configuration", "harbor_admin_password")
|
||||
auth_mode = rcp.get("configuration", "auth_mode")
|
||||
ldap_url = rcp.get("configuration", "ldap_url")
|
||||
ldap_basedn = rcp.get("configuration", "ldap_basedn")
|
||||
db_password = rcp.get("configuration", "db_password")
|
||||
self_registration = rcp.get("configuration", "self_registration")
|
||||
########
|
||||
|
||||
base_dir = os.path.dirname(__file__)
|
||||
base_dir = os.path.dirname(__file__)
|
||||
config_dir = os.path.join(base_dir, "config")
|
||||
templates_dir = os.path.join(base_dir, "templates")
|
||||
|
||||
@ -45,17 +54,17 @@ def render(src, dest, **kw):
|
||||
t = Template(open(src, 'r').read())
|
||||
with open(dest, 'w') as f:
|
||||
f.write(t.substitute(**kw))
|
||||
print "Generated configuration file: %s" % dest
|
||||
print("Generated configuration file: %s" % dest)
|
||||
|
||||
ui_conf_env = os.path.join(config_dir, "ui", "env")
|
||||
ui_conf = os.path.join(config_dir, "ui", "app.conf")
|
||||
ui_conf = os.path.join(config_dir, "ui", "app.conf")
|
||||
registry_conf = os.path.join(config_dir, "registry", "config.yml")
|
||||
db_conf_env = os.path.join(config_dir, "db", "env")
|
||||
|
||||
conf_files = [ ui_conf, ui_conf_env, registry_conf, db_conf_env ]
|
||||
for f in conf_files:
|
||||
if os.path.exists(f):
|
||||
print "Clearing the configuration file: %s" % f
|
||||
print("Clearing the configuration file: %s" % f)
|
||||
os.remove(f)
|
||||
|
||||
render(os.path.join(templates_dir, "ui", "env"),
|
||||
@ -86,4 +95,4 @@ render(os.path.join(templates_dir, "db", "env"),
|
||||
db_conf_env,
|
||||
db_password=db_password)
|
||||
|
||||
print "The configuration files are ready, please use docker-compose to start the service."
|
||||
print("The configuration files are ready, please use docker-compose to start the service.")
|
||||
|
Loading…
Reference in New Issue
Block a user