Esempio n. 1
0
    def mysql_user(self):
        if fs.sh_file_exists(self.my_debian_conf):
            content = fs.sh_cat(self.my_debian_conf, sudo=True)
            return text.safefind('(?m)^user\s+=\s+(.*)$', content)

        elif fs.sh_dir_exists(self.zar_live_config):
            fp = join(self.zar_live_config, 'server.cfg')
            content = fs.sh_cat(fp, sudo=True)
            return text.safefind('(?m)^mysql_user\s+=\s+(.*)$', content)
Esempio n. 2
0
    def mysql_user(self):
        if fs.sh_file_exists(self.my_debian_conf):
            content = fs.sh_cat(self.my_debian_conf, sudo=True)
            return text.safefind('(?m)^user\s+=\s+(.*)$', content)

        elif fs.sh_dir_exists(self.zar_live_config):
            fp = join(self.zar_live_config, 'server.cfg')
            content = fs.sh_cat(fp, sudo=True)
            return text.safefind('(?m)^mysql_user\s+=\s+(.*)$', content)
Esempio n. 3
0
def detect_database_dn():
    content = env.sudo(
        'ldapsearch -Y EXTERNAL -H ldapi:/// -b "{0}" "(olcSuffix={1})" "dn" -LLL'
        .format(env.ldap_config_dn, env.ldap_dit_dn),
        capture=True)

    return text.safefind('(?m)^dn: (.*?),.*$', content)
Esempio n. 4
0
    def do_pkg_rpm(self, destdir=None, targz_fp=None):
        if not targz_fp:
            targz_fp = self.pkg_tarball(destdir=destdir)

        # untar tarball
        with archive.tarfile(targz_fp, 'r:gz') as tar:
            tar.extractall(destdir)

        # create skeleton for rpmbuild
        rpmbuild_dir = join(destdir, 'rpmbuild')
        for d in ['RPMS', 'SOURCES', 'SPECS', 'SRPMS', 'BUILD']:
            d = join(rpmbuild_dir, d)
            os.makedirs(d)

        # copy tarball to the right place
        shutil.copyfile(targz_fp,
                        join(rpmbuild_dir, 'SOURCES', self.targz_name))

        # clone spec file
        specfile = '{0}.spec'.format(self.name)
        specfile_fp = join(destdir, specfile)
        shutil.copyfile(join(self.repo_basedir, 'etc', 'packaging', 'skel.spec'),
                        specfile_fp)

        # extract list of installed files from makefile
        makefile_fp = join(destdir, self.pkgname, 'Makefile')
        content = open(makefile_fp, 'rt').read()
        content = text.safefind('(?s)install:\s*.*', content)

        files = []
        lines = content.split('\n')
        for line in lines:
            if '${DESTDIR}' in line:
                parts = re.split('[ ]', line)
                path = parts[-1]
                path = re.sub('^' + re.escape('${DESTDIR}'), '', path)
                files.append(path)
        files.sort()

        # patch spec file
        context = {
            '(?m)^(Summary:\s*).*': '\g<1> {0}'.format(self.rpmmeta_summary),
            '(?m)^(Name:\s*).*': '\g<1> {0}'.format(self.name),
            '(?m)^(Version:\s*).*': '\g<1> {0}'.format(self.versiontag),
            '(?m)^(Release:\s*).*': '\g<1> {0}'.format(self.buildnum),
            '(?m)^(License:\s*).*': '\g<1> {0}'.format(self.license),
            '(?m)^(Group:\s*).*': '\g<1> {0}'.format(self.rpmmeta_group),
            '(?m)^(BuildArch:\s*).*': '\g<1> {0}'.format(self.rpmmeta_arch),
            '(?m)^(Source:\s*).*': '\g<1> {0}'.format(self.targz_name),
            '(?m)^(BuildRoot:\s*).*': '\g<1> {0}/%{{name}}-buildroot'.format(d),
            '(?m)^(Requires:\s*).*': '\g<1> {0}'.format(', '.join(self.rpmmeta_requires)),
            '(?m)^.*[<]desc[>].*': self.rpmmeta_desc,
            '(?m)^.*[<]files[>].*': '\n'.join(files),
        }
        text.patch_file(context, specfile_fp, dest=specfile_fp, literal=False)

        with warn_only():
            run_cmd('rpmbuild -ba {0} --define "_topdir {1}"'.format(
                specfile_fp, rpmbuild_dir))
Esempio n. 5
0
def detect_database_dn():
    content = env.sudo(
        'ldapsearch -Y EXTERNAL -H ldapi:/// -b "{0}" "(olcSuffix={1})" "dn" -LLL'.format(
        env.ldap_config_dn,
        env.ldap_dit_dn),
        capture=True)

    return text.safefind('(?m)^dn: (.*?),.*$', content)
Esempio n. 6
0
def detect_distro():
    distro = None

    if fs.sh_which('lsb_release'):
        stdout = env.run('lsb_release -a', capture=True)
        name = text.safefind('(?m)^Distributor ID:\s*(.*)$', stdout)
        release = text.safefind('(?m)^Release:\s*(.*)$', stdout)
        distro = Distro(name, release)

    else:
        redhat_release = '/etc/redhat-release'
        if os.path.exists(redhat_release):
            content = fs.sh_cat(redhat_release)
            name, release = text.safefind('(.*) release (.*) [(].*[)]',
                                          content)
            distro = Distro(name, release)

    return distro
Esempio n. 7
0
def detect_distro():
    distro = None

    if fs.sh_which('lsb_release'):
        stdout = env.run('lsb_release -a', capture=True)
        name = text.safefind('(?m)^Distributor ID:\s*(.*)$', stdout)
        release = text.safefind('(?m)^Release:\s*(.*)$', stdout)
        distro = Distro(name, release)

    else:
        redhat_release = '/etc/redhat-release'
        if os.path.exists(redhat_release):
            content = fs.sh_cat(redhat_release)
            name, release = text.safefind('(.*) release (.*) [(].*[)]',
                                          content)
            distro = Distro(name, release)

    return distro
Esempio n. 8
0
def get_commit_id():
    '''Find the commit id of the checked out repo we are in.'''

    id = ''

    if fs.sh_which('svn'):
        with quiet():
            content = run_cmd('svn info')
            if content:
                detected = text.safefind('(?m)^Revision: ([0-9]+)', content)
                if detected:
                    id = detected

    if not id:
        if fs.sh_which('git'):
            with quiet():
                content = run_cmd('git svn info')
                if content:
                    detected = text.safefind('(?m)^Revision: ([0-9]+)', content)
                    if detected:
                        id = detected

    return id
Esempio n. 9
0
    def switch_zarafa_server_plugin(self):
        content = open(self.zarafa_server_cfg, 'rt').read()
        plugin = text.safefind('(?m)^user_plugin\s*=\s*(.*)$', content)

        if plugin not in ['ldap', 'ldapms']:
            stdio.die('Invalid zarafa user plugin found: {0}'.format(plugin))

        zarafa_ldap_cfg = self.zarafa_ldap_cfg_tmpl.format(plugin)

        if not os.path.isfile(zarafa_ldap_cfg):
            stdio.die('Ldap config not found: {0}'.format(zarafa_ldap_cfg))

        context = {
            'user_plugin_config': zarafa_ldap_cfg,
        }
        text.patch_config_file(context, self.zarafa_server_cfg,
                               dest=self.zarafa_server_cfg)
Esempio n. 10
0
    def switch_zarafa_server_plugin(self):
        content = open(self.zarafa_server_cfg, 'rt').read()
        plugin = text.safefind('(?m)^user_plugin\s*=\s*(.*)$', content)

        if plugin not in ['ldap', 'ldapms']:
            stdio.die('Invalid zarafa user plugin found: {0}'.format(plugin))

        zarafa_ldap_cfg = self.zarafa_ldap_cfg_tmpl.format(plugin)

        if not os.path.isfile(zarafa_ldap_cfg):
            stdio.die('Ldap config not found: {0}'.format(zarafa_ldap_cfg))

        context = {
            'user_plugin_config': zarafa_ldap_cfg,
        }
        text.patch_config_file(context,
                               self.zarafa_server_cfg,
                               dest=self.zarafa_server_cfg)
Esempio n. 11
0
def unload_modules():
    ldap_env = LdapEnv.get()

    for name in env.ldap_modules:
        filepath = None

        files = fs.sh_listdir(ldap_env.cn_config_path, sudo=True)
        files = fnmatch.filter(files, 'cn=module{*}.ldif')
        for f in files:
            fp = join(ldap_env.cn_config_path, f)
            if fs.sh_file_exists(fp, sudo=True):
                content = fs.sh_cat(fp, sudo=True)
                if text.safefind('(?m)^olcModuleLoad: {[0-9]+}' + name, content):
                    filepath = fp

        if not filepath:
            putw('Failed to detect loaded module: {0}'.format(name))
        else:
            puth('Removing module {0}'.format(name))
            fs.sh_rm(filepath, sudo=True)
Esempio n. 12
0
def drop_database():
    ldap_env = LdapEnv.get()

    files = fs.sh_listdir(ldap_env.cn_config_path, sudo=True)
    files = fnmatch.filter(files, 'olcDatabase={*}hdb.ldif')

    filepath = None
    for f in files:

        fp = join(ldap_env.cn_config_path, f)
        content = fs.sh_cat(fp, sudo=True)
        if text.safefind('(?m)^olcSuffix: ' + env.ldap_dit_dn, content):
            filepath = fp

    if not filepath:
        putw('Failed to detect database: {0}'.format(env.ldap_dit_dn))
    else:
        puth('Removing database config {0}'.format(filepath))
        fs.sh_rm(filepath, sudo=True)

        root, _ = os.path.splitext(filepath)
        if fs.sh_dir_exists(root, sudo=True):
            puth('Removing database config subdir {0}'.format(root))
            fs.sh_rmtree(root, sudo=True)