Changeset - 4f441d817890
[Not reviewed]
default
0 0 1
Mads Kiilerich (kiilerix) - 5 years ago 2020-03-12 20:48:01
mads@kiilerich.com
PoC: scripts/hgrc2db for mirroring hg config to db
1 file changed with 58 insertions and 0 deletions:
0 comments (0 inline, 0 general) First comment
scripts/hgrc2db
Show inline comments
 
new file 100755
 
#!/usr/bin/env python3
 
"""
 
PoC: store global hg configuration (based on `hg showconfig --debug`
 
functionality) in the Kallithea database.
 

	
 
To see existing database entries:
 

	
 
$ sqlite3 my.db '.headers on' 'select * from Ui'
 
ui_id|ui_section|ui_key|ui_value|ui_active
 
1|hooks|changegroup.update|hg update >&2|0
 
2|hooks|changegroup.repo_size|python:kallithea.lib.hooks.repo_size|1
 
3|hooks|changegroup.push_logger|python:kallithea.lib.hooks.log_push_action|1
 
5|hooks|outgoing.pull_logger|python:kallithea.lib.hooks.log_pull_action|1
 
7|extensions|largefiles||1
 
8|largefiles|usercache|/var/tmp/.cache/largefiles|1
 
9|extensions|hgsubversion||0
 
10|extensions|hggit||0
 
11|web|allow_archive|gz zip bz2|1
 
12|web|baseurl|/|1
 
13|paths|/|/var/tmp/|1
 
"""
 

	
 
import os
 
import sys
 

	
 
import mercurial.ui
 
import paste.deploy
 
import sqlalchemy.engine
 
import sqlalchemy.orm.session
 
from sqlalchemy.orm import sessionmaker
 

	
 
from kallithea.model import db
 

	
 

	
 
def main(ini_file):
 
    config = paste.deploy.appconfig('config:' + os.path.realpath(ini_file))
 
    Session = sessionmaker(bind=sqlalchemy.engine.create_engine(config['sqlalchemy.url']))
 
    dbsession = Session()
 
    db_uis = {(db_ui.ui_section, db_ui.ui_key): db_ui for db_ui in dbsession.query(db.Ui)}
 
    ui = mercurial.ui.ui.load()
 
    for b_section, b_name, b_value in ui.walkconfig():
 
        source = ui.configsource(b_section, b_name).decode().rsplit(':', 1)[0]
 
        if (source.startswith('resource:') or
 
            source == '/home/mk/hg-bin/contrib/kiilerix.hgrc' or
 
            source == '/etc/mercurial/hgrc.d/thgmergetools.rc'
 
        ):
 
            continue
 
        section = b_section.decode()
 
        name = b_name.decode()
 
        value = b_value.decode()
 
        print(section, name, value, source)
 
        db_ui = db_uis.get((section, name)) or db.Ui(ui_section=section, ui_key=name)
 
        db_ui.ui_value = value
 
        db_ui.ui_active = True
 
    # Note: not removing outdated entries
 
    dbsession.commit()
 

	
 
main(sys.argv[1])
0 comments (0 inline, 0 general) First comment
You need to be logged in to comment. Login now