<commit_before>#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#
# Database settings is defined in ~/.pgpass

from __future__ import print_function, unicode_literals
import sys
import os
import logging
if __name__ != '__main__':
    print('XMPP synchronisation extension for NGW loading.')

if __name__ == '__main__':
    sys.path += [ '/usr/lib/' ]
    os.environ['DJANGO_SETTINGS_MODULE'] = 'ngw.settings'
from django.db import connections
from ngw.core.models import ( ContactFieldValue, ContactGroup,
    FIELD_LOGIN, FIELD_PASSWORD_PLAIN )
from ngw.extensions import hooks

__cursor__ = None
def get_common_cursor():
    global __cursor__
    if not __cursor__:
        __cursor__ = get_common_db().cursor()
        __cursor__ = connections['jabber'].cursor()
    return __cursor__

def sync_user(u):
    f_login = u.get_fieldvalue_by_id(FIELD_LOGIN)
    logging.debug("Sync'ing %s", f_login)
    f_login = f_login.lower()
    f_password = ContactFieldValue.objects.get(contact_id=u.id, contact_field_id=FIELD_PASSWORD_PLAIN).value
    sql = 'INSERT INTO users (username, password) SELECT %s, %s WHERE NOT EXISTS (SELECT * FROM users WHERE username=%s)' 
    get_common_cursor().execute(sql, (f_login, f_password, f_login))

    sql = 'UPDATE users SET password=%s WHERE username=%s'
    get_common_cursor().execute(sql, (f_password, f_login))
    return f_login

def remove_unknown(login_set):
    #TODO
    pass

def cross_subscribe(login1, login2):
    '''<commit_msg>Bugfix xmpp extension: Removed old broken line<commit_after>#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#
# Database settings is defined in ~/.pgpass

from __future__ import print_function, unicode_literals
import sys
import os
import logging
if __name__ != '__main__':
    print('XMPP synchronisation extension for NGW loading.')

if __name__ == '__main__':
    sys.path += [ '/usr/lib/' ]
    os.environ['DJANGO_SETTINGS_MODULE'] = 'ngw.settings'
from django.db import connections
from ngw.core.models import ( ContactFieldValue, ContactGroup,
    FIELD_LOGIN, FIELD_PASSWORD_PLAIN )
from ngw.extensions import hooks

__cursor__ = None
def get_common_cursor():
    global __cursor__
    if not __cursor__:
        __cursor__ = connections['jabber'].cursor()
    return __cursor__

def sync_user(u):
    f_login = u.get_fieldvalue_by_id(FIELD_LOGIN)
    logging.debug("Sync'ing %s", f_login)
    f_login = f_login.lower()
    f_password = ContactFieldValue.objects.get(contact_id=u.id, contact_field_id=FIELD_PASSWORD_PLAIN).value
    sql = 'INSERT INTO users (username, password) SELECT %s, %s WHERE NOT EXISTS (SELECT * FROM users WHERE username=%s)' 
    get_common_cursor().execute(sql, (f_login, f_password, f_login))

    sql = 'UPDATE users SET password=%s WHERE username=%s'
    get_common_cursor().execute(sql, (f_password, f_login))
    return f_login

def remove_unknown(login_set):
    #TODO
    pass

def cross_subscribe(login1, login2):
    '''
{'fraction_non_alphanumeric': 0.1105818305546104, 'fraction_numerical': 0.002041510717931269, 'mean_word_length': 4.434380776340111, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6482403', 'n_tokens_mistral': 977, 'n_tokens_neox': 957, 'n_words': 242}