Exemple #1
0
def create_initial_structure(embedded):
    if isdir(config.STAGING_DIR):
        rmtree(config.STAGING_DIR)
    if isfile(config.STAGING_DIR):
        # in case someone put something (like a softlink) in its place
        remove(config.STAGING_DIR)

    try:
        makedirs(config.BUILD_DIR)
    except OSError:
        # dir exists
        pass

    copytree(config.SITE_SRC_DIR, config.STAGING_DIR)

    # copy the appropriate 'default' template, according to whether or not we are building embedded content
    if embedded:
        defaultTemplate = 'default.embedded.html'
    else:
        defaultTemplate = 'default.fullpage.html'
    copyfile(join(config.STAGING_DIR, '_layouts', defaultTemplate),
             join(config.STAGING_DIR, '_layouts', 'default.html'))

    # copy _data into place so that JSON is available to the Liquid templates
    copytree(config.DATA_DIR, join(config.STAGING_DIR, '_data'))
Exemple #2
0
def setup_logging(filename, level='INFO', resume=False):
    if not resume and isfile(filename):
        remove(filename)
    print('Logging to %s, level=%s' % (filename, level))
    logging_configuration = {
        'version': 1,
        'formatters': {
            'standard': {
                'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s',
                'datefmt': '%Y-%m-%d %H:%M:%S'
            },
        },
        'handlers': {
            'file': {
                'level': level,
                'class': 'logging.FileHandler',
                'formatter': 'standard',
                'filename': filename
            }
        },
        'loggers': {
            '': {
                'handlers': ['file'],
                'level': level,
                'propagate': True
            }
        }
    }
    dictConfigClass(logging_configuration).configure()
Exemple #3
0
 def link(self, srcdir, dstdir, filename, guard=True):
     if guard:
         try:
             posix.remove(os.path.join(dstdir, filename))
         except:
             pass
         posix.link(os.path.join(srcdir, filename), os.path.join(dstdir, filename))
Exemple #4
0
 def test_remove_unicode(self):
     # See 2 above ;)
     import posix
     try:
         posix.remove(u"ą")
     except OSError:
         pass
Exemple #5
0
def create_initial_structure(embedded):
    if isdir(config.STAGING_DIR):
        rmtree(config.STAGING_DIR)
    if isfile(config.STAGING_DIR):
        # in case someone put something (like a softlink) in its place
        remove(config.STAGING_DIR)

    try:
        makedirs(config.BUILD_DIR)
    except OSError:
        # dir exists
        pass

    copytree(config.SITE_SRC_DIR, config.STAGING_DIR)

    # copy the appropriate 'default' template, according to whether or not we are building embedded content
    if embedded:
        defaultTemplate = 'default.embedded.html'
    else:
        defaultTemplate = 'default.fullpage.html'
    copyfile(join(config.STAGING_DIR, '_layouts', defaultTemplate),
             join(config.STAGING_DIR, '_layouts', 'default.html'))

    # copy _data into place so that JSON is available to the Liquid templates
    copytree(config.DATA_DIR, join(config.STAGING_DIR, '_data'))
Exemple #6
0
 def test_remove_unicode(self):
     # See 2 above ;)
     import posix
     try:
         posix.remove(u"ą")
     except OSError:
         pass
Exemple #7
0
def link_site(site):
    target = site['link']
    if isfile(target) or islink(target):
        remove(target)
    if isdir(target):
        rmtree(target)
    symlink(join(site_root, site['root'], site['build']), target)
Exemple #8
0
 def link(self, srcdir, dstdir, filename, guard=True):
     if guard:
         try:
             posix.remove(os.path.join(dstdir, filename))
         except:
             pass
         posix.link(os.path.join(srcdir, filename),
                    os.path.join(dstdir, filename))
Exemple #9
0
    def remove_database_file(self, path):

        try:
            remove(path)
            Logger.get_instance().info('File : "' + str(path) + '" deleted.')
        except:
            Logger.get_instance().info('Can not delete file : ' + str(path))
            pass
Exemple #10
0
def nukeFile( fileName ):
	if not dryRun: 
		if os.path.isfile( fileName ):
			#do the nuking
			print "W: nuking " + fileName
			posix.remove( fileName )
	else:
		if os.path.isfile( fileName ):
			print "I: nuking " + fileName
	return 0
Exemple #11
0
def create_structure(src, target, site):
    if isdir(target):
        rmtree(target)
    if isfile(target):
        remove(target)
    try:
        makedirs(join(site_root, site['root'], site['build']))
    except OSError:
        # dir exists
        pass
    copytree(src, target)
    def remove_sqlite_db(self):

        if os.path.exists(self.db_path):
            try:
                remove(self.db_path)
            except Exception as e:
                raise DenCellORFException('The database located at ' +
                                          str(self.db_path) +
                                          ' cannot be deleted.')
            else:
                Logger.get_instance().info('The database file located at ' +
                                           str(self.db_path) +
                                           ' has been deleted.')

        else:
            Logger.get_instance().error(
                self.classname + '.remove_sqlite_db(): There is no file' +
                ' located at' + str(self.db_path) + '.' + ' Error code: ' +
                LogCodes.ERR_SQL_FILE + '.',
                ex=False)
Exemple #13
0
    def generate_host(self, host):
        dstdir = os.path.join(self.dstdir, host.hostname)
        self.makedirs(dstdir)

        self.generate_tpl_file(dstdir, 'passwd.tdb', users=host.users, host=host)
        self.generate_tpl_file(dstdir, 'group.tdb', groups=host.groups, host=host)
        self.generate_tpl_file(dstdir, 'sudo-passwd', users=host.users, host=host)
        self.generate_tpl_file(dstdir, 'shadow.tdb', users=host.users, guard=('NOPASSWD' not in host.exportOptions))
        self.generate_tpl_file(dstdir, 'bsmtp', users=self.users, host=host, guard=('BSMTP' in host.exportOptions))
        for gid in [match.group(1) for match in (re.search('GITOLITE=(.+)', exportOption) for exportOption in host.exportOptions) if match]:
            virts = set(chain.from_iterable([group.hid2virts[host.hid] for group in self.groups if group.gid == gid]))
            self.generate_tpl_file(dstdir, 'ssh-gitolite', users=virts, hosts=self.hosts, dstfile='ssh-gitolite-' + gid)
        self.generate_cdb_file(dstdir, 'user-forward.cdb', 'emailForward', users=host.users)
        self.generate_cdb_file(dstdir, 'batv-tokens.cdb', 'bATVToken', users=set()) # FIXME users=host.users)
        self.generate_cdb_file(dstdir, 'default-mail-options.cdb', 'mailDefaultOptions', users=set()) # FIXME users=host.users)
        self.link(self.dstdir, dstdir, 'disabled-accounts')
        self.link(self.dstdir, dstdir, 'mail-disable')
        self.link(self.dstdir, dstdir, 'mail-forward.cdb')
        self.link(self.dstdir, dstdir, 'mail-contentinspectionaction.cdb')
        self.link(self.dstdir, dstdir, 'debian-private', ('PRIVATE' not in host.exportOptions))
        self.link(self.dstdir, dstdir, 'authorized_keys', ('AUTHKEYS' in host.exportOptions))
        self.link(self.dstdir, dstdir, 'mail-greylist')
        self.link(self.dstdir, dstdir, 'mail-callout')
        self.link(self.dstdir, dstdir, 'mail-rbl')
        self.link(self.dstdir, dstdir, 'mail-rhsbl')
        self.link(self.dstdir, dstdir, 'mail-whitelist')
        self.link(self.dstdir, dstdir, 'web-passwords', ('WEB-PASSWORDS' in host.exportOptions))
        self.link(self.dstdir, dstdir, 'rtc-passwords', ('RTC-PASSWORDS' in host.exportOptions))
        self.link(self.dstdir, dstdir, 'forward-alias')
        self.link(self.dstdir, dstdir, 'markers', ('NOMARKERS' not in host.exportOptions))
        self.link(self.dstdir, dstdir, 'ssh_known_hosts')
        self.link(self.dstdir, dstdir, 'debianhosts')
        self.link(self.dstdir, dstdir, 'dns-zone', ('DNS' in host.exportOptions))
        self.link(self.dstdir, dstdir, 'dns-sshfp', ('DNS' in host.exportOptions))
        self.link(self.dstdir, dstdir, 'all-accounts.json')

        if 'KEYRING' in host.exportOptions:
            for element in settings.config['keyrings']:
                if os.path.isdir(element):
                    src = os.path.join(self.dstdir, os.path.basename(element))
                    dst = os.path.join(dstdir, os.path.basename(element))
                    shutil.rmtree(dst, True)
                    shutil.copytree(src, dst)
                else:
                    tgt = os.path.basename(element)
                    self.link(self.dstdir, dstdir, tgt)
        else:
            for element in settings.config['keyrings']:
                try:
                    if os.path.isdir(element):
                        dst = os.path.join(dstdir, os.path.basename(element))
                        shutil.rmtree(dst, True)
                    else:
                        tgt = os.path.join(dstdir, os.path.basename(element))
                        posix.remove(tgt)
                except:
                    pass

        tf = tarfile.open(name=os.path.join(self.dstdir, host.hostname, 'ssh-keys.tar.gz'), mode='w:gz')
        for user in host.users:
            if not hasattr(user, 'sshRSAAuthKey'):
                continue
            contents = ''
            for sshRSAAuthKey in user.sshRSAAuthKey:
                if sshRSAAuthKey.startswith('allowed_hosts=') and ' ssh-rsa ' in sshRSAAuthKey:
                    hostnames, sshRSAAuthKey = sshRSAAuthKey.split('=', 1)[1].split(' ', 1)
                    if host.hostname not in hostnames.split(','):
                        continue
                contents += sshRSAAuthKey + '\n'
            if contents:
                to = tarfile.TarInfo(name=user.uid)
                to.uid = 0
                to.gid = 65534
                to.uname = user.uid
                to.gname = user.gid
                to.mode  = 0400
                to.mtime = int(time.time())
                to.size = len(contents)
                tf.addfile(to, StringIO(contents))
        tf.close()

        self.link(self.dstdir, dstdir, 'last_update.trace')
Exemple #14
0
def Lpvalue(f,g,h,p,prec,N = None,modformsring = False, weightbound = False, eps = None, orthogonal_form = None, data_idx=None, magma_args = None,force_computation=False, algorithm='threestage', derivative_order=1, lauders_advice = False, use_magma = True, magma = None, num_coeffs_qexpansion = 20000, max_primes=5, outfile = None):
    if magma_args is None:
        magma_args = {}
    if algorithm not in ['twostage','threestage']:
        raise ValueError('Algorithm should be one of "twostage" (default) or "threestage"')

    if magma is None:
        from sage.interfaces.magma import Magma
        magma = Magma(**magma_args)
    if hasattr(g,'j_invariant'):
        elliptic_curve = g
        g = g.modular_form()
    else:
        elliptic_curve = None
    data = None
    if h is None:
        if hasattr(f, 'modulus'):
            # Assume we need to create f and h from Dirichlet character
            kronecker_character = f
            f, _, h = define_qexpansions_from_dirichlet_character(p, prec, kronecker_character, num_coeffs_qexpansion, magma)
        else:
            kronecker_character = None
            # Assume that f contains a list of lines of text to initialize both f and h
            data = f
            f, h = get_magma_qexpansions(data, data_idx, max(prec,200), Qp(p,prec), magma=magma)
            eps = f.character_full()


    ll,mm = g.weight(),h.weight()
    t = 0 # Assume t = 0 here
    kk = ll + mm - 2 * (1 + t) # Is this correct?
    p = ZZ(p)
    if N is None:
        N = lcm([ZZ(f.level()),ZZ(g.level()),ZZ(h.level())])
        nu = N.valuation(p)
        N = N.prime_to_m_part(p)
    else:
        N = ZZ(N)
        nu = N.valuation(p)
    if outfile is None:
        outfile = "output_iterated_integral_%s_%s_%s_%s.txt"%(p,g.level(), h.level(), prec)
    print("Writing output to file %s"%outfile)
    fwrite("######### STARTING COMPUTATION OF Lp ###########", outfile)

    if elliptic_curve is not None:
        fwrite("E = EllipticCurve(%s)"%list(elliptic_curve.ainvs()), outfile)
        fwrite("  cond(E) = %s"%elliptic_curve.conductor(), outfile)
    if kronecker_character is not None:
        fwrite("kronecker_character = %s"%kronecker_character, outfile)
        fwrite("  conductor = %s"%kronecker_character.conductor(), outfile)
    if data is not None:
        fwrite("Data for weight-1 forms:", outfile)
        for line in data:
            fwrite(line, outfile)
    fwrite("Tame level N = %s, prime p = %s, nu = %s"%(N,p,nu), outfile)
    fwrite("precision = %s"%prec, outfile)
    fwrite("------ parameters --------------------", outfile)
    fwrite("modformsring = %s"%modformsring, outfile)
    fwrite("weightbound = %s"%weightbound, outfile)
    fwrite("eps = %s"%eps, outfile)
    fwrite("orthogonal_form = %s"%orthogonal_form, outfile)
    fwrite("magma_args = %s"%magma_args, outfile)
    fwrite("force_computation = %s"%force_computation, outfile)
    fwrite("algorithm = %s"%algorithm, outfile)
    fwrite("derivative_order = %s"%derivative_order, outfile)
    fwrite("lauders_advice = %s"%lauders_advice, outfile)
    fwrite("use_magma = %s"%use_magma, outfile)
    fwrite("num_coeffs_qexpansion = %s"%num_coeffs_qexpansion, outfile)
    fwrite("##########################################", outfile)
    prec = ZZ(prec)

    fwrite("Step 1: Compute the Up matrix", outfile)
    if algorithm == "twostage":
        computation_name = '%s_%s_%s_%s_%s_%s_%s'%(p,N,nu,kk,prec,'triv' if eps is None else 'char',algorithm)
    else:
        computation_name = '%s_%s_%s_%s_%s_%s'%(p,N,nu,kk,prec,'triv' if eps is None else 'char')
    if use_magma:
        tmp_filename = '/tmp/magma_mtx_%s.tmp'%computation_name
        import os.path
        from sage.misc.persist import db, db_save
        try:
            if force_computation:
                raise IOError
            V = db('Lpvalue_Apow_ordbasis_eimat_%s'%computation_name)
            ord_basis, eimat, zetapm, elldash, mdash = V[:5]
            Apow_data = V[5:]
        except IOError:
            if force_computation or not os.path.exists(tmp_filename):
                if eps is not None:
                    eps_magma = sage_character_to_magma(eps,N,magma=magma)
                    magma.load("overconvergent_alan.m")
                    # Am, zetapm, eimatm, elldash, mdash = magma.UpOperatorData(p, eps_magma, kk, prec,WeightBound=weightbound,nvals=5)
                    Am, zetapm, eimatm, elldash, mdash = magma.HigherLevelUpGj(p, kk, prec, weightbound, eps_magma,'"B"',nvals=5)
                else:
                    # Am, zetapm, eimatm, elldash, mdash = magma.UpOperatorData(p, N, kk, prec,WeightBound=weightbound,nvals=5)
                    magma.load("overconvergent_alan.m")
                    Am, zetapm, eimatm, elldash, mdash = magma.HigherLevelUpGj(p, kk, prec, weightbound, N,'"B"',nvals=5)
                fwrite(" ..Converting to Sage...", outfile)
                Amodulus = Am[1,1].Parent().Modulus().sage()
                Aprec = Amodulus.valuation(p)
                Arows = Am.NumberOfRows().sage()
                Acols = Am.NumberOfColumns().sage()
                Emodulus = eimatm[1,1].Parent().Modulus().sage()
                Eprec = Emodulus.valuation(p)
                Erows = eimatm.NumberOfRows().sage()
                Ecols = eimatm.NumberOfColumns().sage()
                magma.load("get_qexpansions.m")
                magma.eval('F := Open("%s", "w");'%tmp_filename)
                magma.eval('fprintf F, "%s, %s, %s, %s \\n"'%(p,Aprec,Arows,Acols)) # parameters
                magma.eval('save_matrix(%s, F)'%(Am.name()))
                # for i in range(1,Arows+1):
                #     magma.eval('fprintf F, "%%o\\n", %s[%s]'%(Am.name(),i))
                magma.eval('fprintf F, "%s, %s, %s, %s \\n"'%(p,Eprec,Erows,Ecols)) # parameters
                magma.eval('save_matrix(%s, F)'%(eimatm.name()))
                # for i in range(1,Erows+1):
                #     magma.eval('fprintf F, "%%o\\n", %s[%s]'%(eimatm.name(),i))
                magma.eval('fprintf F, "%s\\n"'%zetapm)
                magma.eval('fprintf F, "%s\\n"'%elldash)
                magma.eval('fprintf F, "%s\\n"'%mdash)
                magma.eval('delete F;')
                magma.quit()

            # Read A and eimat from file
            from sage.structure.sage_object import load
            from sage.misc.sage_eval import sage_eval
            with open(tmp_filename,'r') as fmagma:
                A = read_matrix_from_file(fmagma)
                eimat = read_matrix_from_file(fmagma)
                zetapm= sage_eval(fmagma.readline())
                elldash = sage_eval(fmagma.readline())
                mdash = sage_eval(fmagma.readline())

            fwrite("Step 3b: Apply Up^(r-1) to H", outfile)
            if algorithm == 'twostage':
                V0  = list(find_Apow_and_ord_two_stage(A, eimat, p, prec))
            else:
                V0 = list(find_Apow_and_ord_three_stage(A,eimat,p,prec))
            ord_basis = V0[0]
            Apow_data = V0[1:]
            V = [ord_basis]
            V.extend([eimat, zetapm, elldash, mdash])
            V.extend(Apow_data)
            db_save(V,'Lpvalue_Apow_ordbasis_eimat_%s'%computation_name)
            from posix import remove
            remove(tmp_filename)

    else:
        A, eimat, elldash, mdash = UpOperator(p,N,kk,prec, modformsring = False, weightbound = 6)

    fwrite("Step 2: p-depletion, Coleman primitive, and multiply", outfile)
    fwrite(".. Need %s coefficients of the q-expansion..."%(p**(nu+1) * elldash), outfile)
    if data is not None:
        f, h = get_magma_qexpansions(data, data_idx, (p**(nu+1) * elldash) + 200, Qp(p,prec), magma=magma)

    H = depletion_coleman_multiply(g, h, p, p**(nu+1) * elldash, t=0)

    fwrite("Step 3a: Compute ordinary projection", outfile)

    if len(Apow_data) == 1:
        Hord = compute_ordinary_projection_two_stage(H, Apow_data, eimat, elldash,p)
    else:
        Hord = compute_ordinary_projection_three_stage(H, [ord_basis] + Apow_data, eimat, elldash,p,nu)
    fwrite('Changing Hord to ring %s'%g[1].parent(), outfile)
    Hord = Hord.change_ring(h[1].parent())
    print [Hord[i] for i in range(30)]
    fwrite("Step 4: Project onto f-component", outfile)
    while True:
        try:
            ell, piHord, epstwist = project_onto_eigenspace(f, ord_basis, Hord, kk, N * p, p = p, derivative_order=derivative_order, max_primes=max_primes)
            break
        except RuntimeError:
            derivative_order += 1
            verbose("Increasing experimental derivative order to %s"%derivative_order)
        except ValueError:
            verbose("Experimental derivative order (%s) seems too high"%derivative_order)
            fwrite("Experimental derivative_order = %s"%derivative_order, outfile)
            fwrite("Seems too high...", outfile)
            fwrite("######################################", outfile)
            assert 0
    n = 1
    while f[n] == 0:
        n = next_prime(n)
    if lauders_advice == True or orthogonal_form is None:
        Lpa =  piHord[n] / (f[n] * epstwist(n))
        fwrite("Experimental derivative_order = %s"%derivative_order, outfile)
        fwrite("Checking Lauder's coincidence... (following should be a bunch of 'large' valuations)", outfile)
        fwrite(str([(i,(Lpa * f[i] * epstwist(i) - piHord[i]).valuation(p)) for i in prime_range(50)]), outfile)
        fwrite("Done", outfile)
    else:
        gplus, gminus = f, orthogonal_form
        l1 = 2
        while N*p*ell % l1 == 0 or gplus[l1] == 0:
            l1 = next_prime(l1)
        proj_mat = matrix([[gplus[l1],gplus[p]],[gminus[l1],gminus[p]]])
        Lpalist =  (matrix([piHord[l1],piHord[p]]) * proj_mat**-1).list()
        Lpa = Lpalist[0]
        if Lpa.valuation() > prec / 2: # this is quite arbitrary!
            Lpa = Lpalist[1]
        Lpa = Lpa / f[n]
    fwrite("ell = %s"%ell, outfile)
    fwrite("######### FINISHED COMPUTATION ###########", outfile)
    fwrite("Lp = %s"%Lpa, outfile)
    fwrite("##########################################", outfile)
    return Lpa, ell
Exemple #15
0
def Lpvalue(f,
            g,
            h,
            p,
            prec,
            N=None,
            modformsring=False,
            weightbound=6,
            eps=None,
            orthogonal_form=None,
            magma_args=None,
            force_computation=False,
            algorithm='twostage'):
    if magma_args is None:
        magma_args = {}
    if algorithm not in ['twostage', 'threestage']:
        raise ValueError(
            'Algorithm should be one of "twostage" (default) or "threestage"')
    from sage.interfaces.magma import Magma
    magma = Magma(**magma_args)
    ll, mm = g.weight(), h.weight()
    t = 0  # Assume t = 0 here
    kk = ll + mm - 2 * (1 + t)  # Is this correct?
    p = ZZ(p)
    if N is None:
        N = LCM([ZZ(f.level()), ZZ(g.level()), ZZ(h.level())])
        N = N.prime_to_m_part(p)

    print("Tame level N = %s, prime p = %s" % (N, p))
    prec = ZZ(prec)

    print("Step 1: Compute the Up matrix")
    computation_name = '%s_%s_%s_%s_%s_%s' % (
        p, N, kk, prec, 'triv' if eps is None else 'char', algorithm)
    tmp_filename = '/tmp/magma_mtx_%s.tmp' % computation_name
    import os.path
    from sage.misc.persist import db, db_save
    try:
        if force_computation:
            raise IOError
        V = db('Lpvalue_Apow_ordbasis_eimat_%s' % computation_name)
        ord_basis, eimat, zetapm, elldash, mdash = V[:5]
        Apow_data = V[5:]
    except IOError:
        if force_computation or not os.path.exists(tmp_filename):
            if eps is not None:
                eps_magma = sage_character_to_magma(eps, magma=magma)
                Am, zetapm, eimatm, elldash, mdash = magma.UpOperatorData(
                    p, eps_magma, kk, prec, nvals=5)
            else:
                Am, zetapm, eimatm, elldash, mdash = magma.UpOperatorData(
                    p, N, kk, prec, nvals=5)
            print(" ..Converting to Sage...")
            Amodulus = Am[1, 1].Parent().Modulus().sage()
            Arows = Am.NumberOfRows().sage()
            Acols = Am.NumberOfColumns().sage()
            Emodulus = eimatm[1, 1].Parent().Modulus().sage()
            Erows = eimatm.NumberOfRows().sage()
            Ecols = eimatm.NumberOfColumns().sage()
            magma.eval('F := Open("%s", "w");' % tmp_filename)
            magma.eval('fprintf F, "Matrix(Zmod(%s),%s, %s, "' %
                       (Amodulus, Arows, Acols))
            magma.eval('fprintf F, "%%o", ElementToSequence(%s)' % Am.name())
            magma.eval('fprintf F, ") \\n"')
            magma.eval('fprintf F, "Matrix(Zmod(%s),%s, %s, "' %
                       (Emodulus, Erows, Ecols))
            magma.eval('fprintf F, "%%o", ElementToSequence(%s)' %
                       eimatm.name())
            magma.eval('fprintf F, ") \\n"')
            magma.eval('fprintf F, "%%o\\n", %s' % zetapm.name())
            magma.eval('fprintf F, "%%o\\n", %s' % elldash.name())
            magma.eval('fprintf F, "%%o\\n", %s' % mdash.name())
            magma.eval('delete F;')
            magma.quit()

        # Read A and eimat from file
        from sage.structure.sage_object import load
        from sage.misc.sage_eval import sage_eval
        with open(tmp_filename, 'r') as fmagma:
            A = sage_eval(fmagma.readline(), preparse=False)
            eimat = sage_eval(fmagma.readline(), preparse=False)
            zetapm = sage_eval(fmagma.readline())
            elldash = sage_eval(fmagma.readline())
            mdash = sage_eval(fmagma.readline())

        print("Step 3b: Apply Up^(r-1) to H")
        if algorithm == 'twostage':
            V0 = list(find_Apow_and_ord(A, eimat, p, prec))
        else:
            V0 = list(find_Apow_and_ord_three_stage(A, eimat, p, prec))
        ord_basis = V0[0]
        Apow_data = V0[1:]
        V = [ord_basis]
        V.extend([eimat, zetapm, elldash, mdash])
        V.extend(Apow_data)
        db_save(V, 'Lpvalue_Apow_ordbasis_eimat_%s' % computation_name)
        from posix import remove
        remove(tmp_filename)

    print("Step 2: p-depletion, Coleman primitive, and multiply")
    H = depletion_coleman_multiply(g, h, p, p * elldash, t=0)

    print("Step 3a: Compute Up(H)")
    UpH = vector([H(p * n) for n in range(elldash)])

    if len(Apow_data) == 1:
        Hord = compute_ordinary_projection_two_stage(UpH, Apow_data, eimat,
                                                     elldash)
    else:
        Hord = compute_ordinary_projection_three_stage(UpH,
                                                       [ord_basis] + Apow_data,
                                                       eimat, elldash)
    Hord = Hord.change_ring(Apow_data[0].parent().base_ring())

    print("Step 4: Project onto f-component")
    R = Qp(p, prec)
    if orthogonal_form is None:
        ell, piHord = project_onto_eigenspace(f, ord_basis,
                                              Hord.change_ring(R), kk, N * p,
                                              eps)
        n = 1
        while f[n] == 0:
            n += 1
        Lpa = R(piHord[n]) / R(f[n])
    else:
        ell, piHord = project_onto_eigenspace(f,
                                              ord_basis,
                                              Hord.change_ring(R),
                                              kk,
                                              N * p,
                                              eps,
                                              derivative_order=2)
        gplus, gminus = f, orthogonal_form
        l1 = 2
        while N * p * ell % l1 == 0 or gplus[l1] == 0:
            l1 = next_prime(l1)
        proj_mat = matrix([[gplus[l1], gplus[p]], [gminus[l1], gminus[p]]])
        Lpalist = (matrix([piHord[l1], piHord[p]]) * proj_mat**-1).list()
        Lpa = Lpalist[0]
        if Lpa.valuation() > prec / 2:  # this is quite arbitrary!
            Lpa = Lpalist[1]
        n = 1
        while f[n] == 0:
            n += 1
        Lpa = Lpa / f[n]
    return Lpa, ell
Exemple #16
0
 def tearDown(self):
     remove(self.檔案.name)
Exemple #17
0
    def generate_host(self, host):
        dstdir = os.path.join(self.dstdir, host.hostname)
        self.makedirs(dstdir)

        self.generate_tpl_file(dstdir,
                               'passwd.tdb',
                               users=host.users,
                               host=host)
        self.generate_tpl_file(dstdir,
                               'group.tdb',
                               groups=host.groups,
                               host=host)
        self.generate_tpl_file(dstdir,
                               'sudo-passwd',
                               users=host.users,
                               host=host)
        self.generate_tpl_file(dstdir,
                               'shadow.tdb',
                               users=host.users,
                               guard=('NOPASSWD' not in host.exportOptions))
        self.generate_tpl_file(dstdir,
                               'bsmtp',
                               users=self.users,
                               host=host,
                               guard=('BSMTP' in host.exportOptions))
        for gid, extra in [
                match.groups() for match in (
                    re.search('GITOLITE=(.+?)(?:,(.*))?$', exportOption)
                    for exportOption in host.exportOptions) if match
        ]:
            extra = extra.split(',') if extra is not None else []
            hosts = [] if 'nohosts' in extra else self.hosts
            virts = set(
                chain.from_iterable([
                    group.hid2virts[host.hid] for group in self.groups
                    if group.gid == gid
                ]))
            self.generate_tpl_file(dstdir,
                                   'ssh-gitolite',
                                   users=virts,
                                   hosts=hosts,
                                   dstfile='ssh-gitolite-' + gid)
        self.generate_cdb_file(dstdir,
                               'user-forward.cdb',
                               'emailForward',
                               users=host.users)
        self.generate_cdb_file(dstdir,
                               'batv-tokens.cdb',
                               'bATVToken',
                               users=set())  # FIXME users=host.users)
        self.generate_cdb_file(dstdir,
                               'default-mail-options.cdb',
                               'mailDefaultOptions',
                               users=set())  # FIXME users=host.users)
        self.link(self.dstdir, dstdir, 'disabled-accounts')
        self.link(self.dstdir, dstdir, 'mail-disable')
        self.link(self.dstdir, dstdir, 'mail-forward.cdb')
        self.link(self.dstdir, dstdir, 'mail-contentinspectionaction.cdb')
        self.link(self.dstdir, dstdir, 'debian-private',
                  ('PRIVATE' not in host.exportOptions))
        self.link(self.dstdir, dstdir, 'authorized_keys',
                  ('AUTHKEYS' in host.exportOptions))
        self.link(self.dstdir, dstdir, 'mail-greylist')
        self.link(self.dstdir, dstdir, 'mail-callout')
        self.link(self.dstdir, dstdir, 'mail-rbl')
        self.link(self.dstdir, dstdir, 'mail-rhsbl')
        self.link(self.dstdir, dstdir, 'mail-whitelist')
        self.link(self.dstdir, dstdir, 'web-passwords',
                  ('WEB-PASSWORDS' in host.exportOptions))
        self.link(self.dstdir, dstdir, 'rtc-passwords',
                  ('RTC-PASSWORDS' in host.exportOptions))
        self.link(self.dstdir, dstdir, 'forward-alias')
        self.link(self.dstdir, dstdir, 'markers',
                  ('NOMARKERS' not in host.exportOptions))
        self.link(self.dstdir, dstdir, 'ssh_known_hosts')
        self.link(self.dstdir, dstdir, 'debianhosts')
        self.link(self.dstdir, dstdir, 'dns-zone',
                  ('DNS' in host.exportOptions))
        self.link(self.dstdir, dstdir, 'dns-sshfp',
                  ('DNS' in host.exportOptions))
        self.link(self.dstdir, dstdir, 'all-accounts.json')

        if 'KEYRING' in host.exportOptions:
            for element in settings.config['keyrings']:
                if os.path.isdir(element):
                    src = os.path.join(self.dstdir, os.path.basename(element))
                    dst = os.path.join(dstdir, os.path.basename(element))
                    shutil.rmtree(dst, True)
                    shutil.copytree(src, dst)
                else:
                    tgt = os.path.basename(element)
                    self.link(self.dstdir, dstdir, tgt)
        else:
            for element in settings.config['keyrings']:
                try:
                    if os.path.isdir(element):
                        dst = os.path.join(dstdir, os.path.basename(element))
                        shutil.rmtree(dst, True)
                    else:
                        tgt = os.path.join(dstdir, os.path.basename(element))
                        posix.remove(tgt)
                except:
                    pass

        tf = tarfile.open(name=os.path.join(self.dstdir, host.hostname,
                                            'ssh-keys.tar.gz'),
                          mode='w:gz')
        for user in host.users:
            if not hasattr(user, 'sshRSAAuthKey'):
                continue
            contents = ''
            for sshRSAAuthKey in user.sshRSAAuthKey:
                if sshRSAAuthKey.startswith(
                        'allowed_hosts=') and ' ssh-rsa ' in sshRSAAuthKey:
                    hostnames, sshRSAAuthKey = sshRSAAuthKey.split('=',
                                                                   1)[1].split(
                                                                       ' ', 1)
                    if host.hostname not in hostnames.split(','):
                        continue
                contents += sshRSAAuthKey + '\n'
            if contents:
                to = tarfile.TarInfo(name=user.uid)
                to.uid = 0
                to.gid = 65534
                to.uname = user.uid
                to.gname = user.gid
                to.mode = 0400
                to.mtime = int(time.time())
                to.size = len(contents)
                tf.addfile(to, StringIO(contents))
        tf.close()

        self.link(self.dstdir, dstdir, 'last_update.trace')
 def tearDown(self):
     remove(self.檔案.name)