feat(license): allow import of license from rhodecode_enterprise.license which got broken after python3 migration
This commit is contained in:
parent
4938e6c7a4
commit
1a00627df3
3 changed files with 40 additions and 9 deletions
|
|
@ -108,11 +108,10 @@ def command(ini_path, force_yes, user, email, password, api_key, repos,
|
|||
dbmanage.create_permissions()
|
||||
dbmanage.populate_default_permissions()
|
||||
if apply_license_key:
|
||||
try:
|
||||
from rc_license.models import apply_trial_license_if_missing
|
||||
apply_trial_license_if_missing(force=True)
|
||||
except ImportError:
|
||||
pass
|
||||
from rhodecode.model.license import apply_license_from_file
|
||||
license_file_path = config.get('license.import_path')
|
||||
if license_file_path:
|
||||
apply_license_from_file(license_file_path, force=True)
|
||||
|
||||
Session().commit()
|
||||
|
||||
|
|
|
|||
17
rhodecode/model/license.py
Normal file
17
rhodecode/model/license.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
def apply_license(*args, **kwargs):
|
||||
pass
|
||||
|
||||
try:
|
||||
from rc_license.models import apply_license
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
def apply_license_from_file(*args, **kwargs):
|
||||
pass
|
||||
|
||||
try:
|
||||
from rc_license.models import apply_license_from_file
|
||||
except ImportError:
|
||||
pass
|
||||
|
|
@ -205,7 +205,7 @@ def write_usage_data(event):
|
|||
return
|
||||
|
||||
def get_update_age(dest_file):
|
||||
now = datetime.datetime.utcnow()
|
||||
now = datetime.datetime.now(datetime.UTC)
|
||||
|
||||
with open(dest_file, 'rb') as f:
|
||||
data = ext_json.json.loads(f.read())
|
||||
|
|
@ -216,10 +216,9 @@ def write_usage_data(event):
|
|||
|
||||
return 0
|
||||
|
||||
utc_date = datetime.datetime.utcnow()
|
||||
utc_date = datetime.datetime.now(datetime.UTC)
|
||||
hour_quarter = int(math.ceil((utc_date.hour + utc_date.minute/60.0) / 6.))
|
||||
fname = '.rc_usage_{date.year}{date.month:02d}{date.day:02d}_{hour}.json'.format(
|
||||
date=utc_date, hour=hour_quarter)
|
||||
fname = f'.rc_usage_{utc_date.year}{utc_date.month:02d}{utc_date.day:02d}_{hour_quarter}.json'
|
||||
ini_loc = os.path.dirname(rhodecode.CONFIG.get('__file__'))
|
||||
|
||||
usage_dir = os.path.join(ini_loc, '.rcusage')
|
||||
|
|
@ -314,6 +313,22 @@ def write_js_routes_if_enabled(event):
|
|||
log.exception('Failed to write routes.js into %s', jsroutes_file_path)
|
||||
|
||||
|
||||
def import_license_if_present(event):
|
||||
"""
|
||||
This is subscribed to the `pyramid.events.ApplicationCreated` event. It
|
||||
does a import license key based on a presence of the file.
|
||||
"""
|
||||
settings = event.app.registry.settings
|
||||
|
||||
license_file_path = settings.get('license.import_path')
|
||||
force = settings.get('license.import_path_mode') == 'force'
|
||||
if license_file_path:
|
||||
from rhodecode.model.meta import Session
|
||||
from rhodecode.model.license import apply_license_from_file
|
||||
apply_license_from_file(license_file_path, force=force)
|
||||
Session().commit()
|
||||
|
||||
|
||||
class Subscriber(object):
|
||||
"""
|
||||
Base class for subscribers to the pyramid event system.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue