当前位置: 首页>>代码示例>>Python>>正文


Python SimilarSizeWriter.write方法代码示例

本文整理汇总了Python中Cerebrum.utils.atomicfile.SimilarSizeWriter.write方法的典型用法代码示例。如果您正苦于以下问题:Python SimilarSizeWriter.write方法的具体用法?Python SimilarSizeWriter.write怎么用?Python SimilarSizeWriter.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cerebrum.utils.atomicfile.SimilarSizeWriter的用法示例。


在下文中一共展示了SimilarSizeWriter.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_filegroup

# 需要导入模块: from Cerebrum.utils.atomicfile import SimilarSizeWriter [as 别名]
# 或者: from Cerebrum.utils.atomicfile.SimilarSizeWriter import write [as 别名]
    def generate_filegroup(self, filename):
        logger.debug("generate_group: %s" % filename)
        f = SimilarSizeWriter(filename, "w", encoding='UTF-8')
        f.max_pct_change = 5

        groups = self._exported_groups.keys()
        groups.sort()
        for group_id in groups:
            group_name = self._exported_groups[group_id]
            tmp = posix_group.illegal_name(group_name)
            if tmp or len(group_name) > 8:
                logger.warn("Bad groupname %s %s" % (group_name, tmp))
                continue
            try:
                group_members, user_members = self._expand_group(group_id)
            except Errors.NotFoundError:
                logger.warn("Group %s has no GID", group_id)
                continue
            tmp_users = self._filter_illegal_usernames(user_members,
                                                       group_name)

            logger.debug("%s -> g=%s, u=%s" % (
                group_id, group_members, tmp_users))
            f.write(self._wrap_line(group_name, ",".join(tmp_users),
                                    ':*:%i:' % self._group.posix_gid))
        if e_o_f:
            f.write('E_O_F\n')
        f.close()
开发者ID:unioslo,项目名称:cerebrum,代码行数:30,代码来源:generate_nismaps.py

示例2: write_ou_info

# 需要导入模块: from Cerebrum.utils.atomicfile import SimilarSizeWriter [as 别名]
# 或者: from Cerebrum.utils.atomicfile.SimilarSizeWriter import write [as 别名]
 def write_ou_info(self, institution_number, ou_file):
     """Lager fil med informasjon om alle OU-er"""
     logger.info("Writing OU info to '%s'", ou_file)
     f = SimilarSizeWriter(ou_file, mode='w', encoding=XML_ENCODING)
     f.max_pct_change = 50
     f.write(xml.xml_hdr + "<data>\n")
     cols, ouer = self._ext_cols(
         self.fs.info.list_ou(institution_number))
     for o in ouer:
         sted = {}
         for fs_col, xml_attr in (
                 ('faknr', 'fakultetnr'),
                 ('instituttnr', 'instituttnr'),
                 ('gruppenr', 'gruppenr'),
                 ('stedakronym', 'akronym'),
                 ('stedakronym', 'forkstednavn'),
                 ('stednavn_bokmal', 'stednavn'),
                 ('stedkode_konv', 'stedkode_konv'),
                 ('faknr_org_under', 'fakultetnr_for_org_sted'),
                 ('instituttnr_org_under', 'instituttnr_for_org_sted'),
                 ('gruppenr_org_under', 'gruppenr_for_org_sted'),
                 ('adrlin1', 'adresselinje1_intern_adr'),
                 ('adrlin2', 'adresselinje2_intern_adr'),
                 ('postnr', 'poststednr_intern_adr'),
                 ('adrlin1_besok', 'adresselinje1_besok_adr'),
                 ('adrlin2_besok', 'adresselinje2_besok_adr'),
                 ('postnr_besok', 'poststednr_besok_adr')):
             if o[fs_col] is not None:
                 sted[xml_attr] = xml.escape_xml_attr(o[fs_col])
         komm = []
         for fs_col, typekode in (
                 ('telefonnr', 'EKSTRA TLF'),
                 ('faxnr', 'FAX'),
                 ('emailadresse', 'EMAIL'),
                 ('url', 'URL')
         ):
             if o[fs_col]:  # Skip NULLs and empty strings
                 komm.append(
                     {'kommtypekode': xml.escape_xml_attr(typekode),
                      'kommnrverdi': xml.escape_xml_attr(o[fs_col])})
         # TODO: Kolonnene 'url' og 'bibsysbeststedkode' hentes ut fra
         # FS, men tas ikke med i outputen herfra.
         f.write('<sted ' +
                 ' '.join(["%s=%s" % item for item in sted.items()]) +
                 '>\n')
         for k in komm:
             f.write('<komm ' +
                     ' '.join(["%s=%s" % item for item in k.items()]) +
                     ' />\n')
         f.write('</sted>\n')
     f.write("</data>\n")
     f.close()
开发者ID:unioslo,项目名称:cerebrum,代码行数:54,代码来源:import_from_FS.py

示例3: main

# 需要导入模块: from Cerebrum.utils.atomicfile import SimilarSizeWriter [as 别名]
# 或者: from Cerebrum.utils.atomicfile.SimilarSizeWriter import write [as 别名]
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'd:f:o:t:a:', ['delim=',
                                                                'file=',
                                                                'out=', 'tag=',
                                                                'append='])
    except getopt.GetoptError:
        usage(2)

    big_xml = {}
    for opt, val in opts:
        if opt in ('-t', '--tag'):
            tag = val
        elif opt in ('-d', '--delim'):
            delim = val.split(":")
        elif opt in ('-f', '--file'):
            CollectParser(val, big_xml, delim)
        elif opt in ('-a', '--append'):
            CollectParser(val, big_xml, delim, True)
        elif opt in ('-o', '--out'):
            f = SimilarSizeWriter(val, "w")
            f.max_pct_change = 50
            xml = XMLHelper()
            f.write(xml.xml_hdr + "<data>\n")
            for bx_key in big_xml.keys():
                bx_delim = bx_key.split("¦")
                f.write("<%s %s>\n" % (
                    tag, " ".join(["%s=%s" % (delim[n],
                                              xml.escape_xml_attr(bx_delim[n]))
                                   for n in range(len(delim))])))
                for tmp_tag in big_xml[bx_key]:
                    tmp = tmp_tag['TagName']
                    del(tmp_tag['TagName'])

                    f.write("  <%s %s/>\n" % (
                        tmp, " ".join(
                            ["%s=%s" % (tk,
                                        xml.escape_xml_attr(tmp_tag[tk]))
                             for tk in tmp_tag.keys()])))

                f.write("</%s>\n" % tag)
            f.write("</data>\n")
            f.close()
开发者ID:unioslo,项目名称:cerebrum,代码行数:45,代码来源:merge_xml_files.py

示例4: write_edu_info

# 需要导入模块: from Cerebrum.utils.atomicfile import SimilarSizeWriter [as 别名]
# 或者: from Cerebrum.utils.atomicfile.SimilarSizeWriter import write [as 别名]
    def write_edu_info(self, edu_info_file):
        """Lag en fil med informasjon om alle studentenes 'aktiviteter'
        registrert i FS.

        Spesifikt, lister vi opp alle deltagelser ved:

          - undenh
          - undakt
          - kullklasser
          - kull
        """

        logger.info("Writing edu info for all students")
        f = SimilarSizeWriter(edu_info_file, mode='w',
                              encoding=XML_ENCODING)
        f.max_pct_change = 50
        f.write(xml.xml_hdr + "<data>\n")

        for xml_tag, generator in (
                ("undenh",
                 self.fs.undervisning.list_studenter_alle_undenh),
                ("undakt",
                 self.fs.undervisning.list_studenter_alle_undakt),
                ("kullklasse",
                 self.fs.undervisning.list_studenter_alle_kullklasser),
                ("kull",
                 self.fs.undervisning.list_studenter_alle_kull)):
            logger.debug("Processing %s entries", xml_tag)
            for row in generator():
                keys = row.keys()
                f.write(xml.xmlify_dbrow(row, keys, xml_tag) + "\n")

        f.write("</data>\n")
        f.close()
开发者ID:unioslo,项目名称:cerebrum,代码行数:36,代码来源:import_from_FS.py

示例5: write_kull_info

# 需要导入模块: from Cerebrum.utils.atomicfile import SimilarSizeWriter [as 别名]
# 或者: from Cerebrum.utils.atomicfile.SimilarSizeWriter import write [as 别名]
    def write_kull_info(self, kull_info_file):
        """Lag en fil med informasjon om alle studentenes kulldeltakelse
        registrert i FS.

        Spesifikt, lister vi opp alle deltagelser ved:
          - kullklasser
          - kull
        """
        logger.info("Writing kull info to '%s'", kull_info_file)
        f = SimilarSizeWriter(kull_info_file, mode='w',
                              encoding=XML_ENCODING)
        f.max_pct_change = 50
        f.write(xml.xml_hdr + "<data>\n")

        for xml_tag, generator in (
                ("kullklasse",
                 self.fs.undervisning.list_studenter_alle_kullklasser),
                ("kulldeltaker",
                 self.fs.undervisning.list_studenter_alle_kull),
                ("kull",
                 self.fs.info.list_kull)):
            for row in generator():
                keys = row.keys()
                f.write(xml.xmlify_dbrow(row, keys, xml_tag) + "\n")

        f.write("</data>\n")
        f.close()
开发者ID:unioslo,项目名称:cerebrum,代码行数:29,代码来源:import_from_FS.py

示例6: write_undenh_student

# 需要导入模块: from Cerebrum.utils.atomicfile import SimilarSizeWriter [as 别名]
# 或者: from Cerebrum.utils.atomicfile.SimilarSizeWriter import write [as 别名]
 def write_undenh_student(self, undenh_student_file):
     """Skriv oversikt over personer oppmeldt til undervisningsenheter.
     Tar med data for alle undervisingsenheter i inneværende+neste
     semester."""
     logger.info("Writing undenh_student info to '%s'",
                 undenh_student_file)
     f = SimilarSizeWriter(undenh_student_file, mode='w',
                           encoding=XML_ENCODING)
     f.max_pct_change = 50
     f.write(xml.xml_hdr + "<data>\n")
     for semester in ('current', 'next'):
         cols, undenh = self._ext_cols(
             self.fs.undervisning.list_undervisningenheter(sem=semester))
         for u in undenh:
             u_attr = {}
             for k in ('institusjonsnr', 'emnekode', 'versjonskode',
                       'terminnr', 'terminkode', 'arstall'):
                 u_attr[k] = u[k]
             student_cols, student = self._ext_cols(
                 self.fs.undervisning.list_studenter_underv_enhet(**u_attr))
             for s in student:
                 s_attr = u_attr.copy()
                 for k in ('fodselsdato', 'personnr'):
                     s_attr[k] = s[k]
                 f.write(xml.xmlify_dbrow({}, (), 'student',
                                          extra_attr=s_attr) + "\n")
     f.write("</data>\n")
     f.close()
开发者ID:unioslo,项目名称:cerebrum,代码行数:30,代码来源:import_from_FS.py

示例7: write_person_info

# 需要导入模块: from Cerebrum.utils.atomicfile import SimilarSizeWriter [as 别名]
# 或者: from Cerebrum.utils.atomicfile.SimilarSizeWriter import write [as 别名]
    def write_person_info(self, person_file):
        """Lager fil med informasjon om alle personer registrert i FS som
        vi muligens også ønsker å ha med i Cerebrum.  En person kan
        forekomme flere ganger i filen."""

        # TBD: Burde vi cache alle data, slik at vi i stedet kan lage en
        # fil der all informasjon om en person er samlet under en egen
        # <person> tag?

        logger.info("Writing person info to '%s'", person_file)
        f = SimilarSizeWriter(person_file, mode='w',
                              encoding=XML_ENCODING)
        f.max_pct_change = 50
        f.write(xml.xml_hdr + "<data>\n")

        # Aktive studenter
        cols, students = self._ext_cols(self.fs.student.list_aktiv())
        for s in students:
            f.write(
                xml.xmlify_dbrow(s, xml.conv_colnames(cols), 'aktiv') + "\n")

        # Eksamensmeldinger
        cols, students = self._ext_cols(
            self.fs.student.list_eksamensmeldinger())
        for s in students:
            f.write(xml.xmlify_dbrow(
                s, xml.conv_colnames(cols), 'eksamen') + "\n")

        # Aktive fagpersoner ved Hiøf
        cols, fagperson = self._ext_cols(
            self.fs.undervisning.list_fagperson_semester())
        for p in fagperson:
            f.write(
                xml.xmlify_dbrow(
                    p, xml.conv_colnames(cols), 'fagperson') + "\n")

        f.write("</data>\n")
        f.close()
开发者ID:unioslo,项目名称:cerebrum,代码行数:40,代码来源:import_from_FS.py

示例8: write_emne_info

# 需要导入模块: from Cerebrum.utils.atomicfile import SimilarSizeWriter [as 别名]
# 或者: from Cerebrum.utils.atomicfile.SimilarSizeWriter import write [as 别名]
 def write_emne_info(self, emne_info_file):
     """Lager fil med informasjon om alle definerte emner"""
     logger.info("Writing emne info to '%s'", emne_info_file)
     f = SimilarSizeWriter(emne_info_file, mode='w',
                           encoding=XML_ENCODING)
     f.max_pct_change = 50
     f.write(xml.xml_hdr + "<data>\n")
     cols, dta = self._ext_cols(self.fs.info.list_emner())
     for t in dta:
         f.write(
             xml.xmlify_dbrow(t, xml.conv_colnames(cols), 'emne') + "\n")
     f.write("</data>\n")
     f.close()
开发者ID:unioslo,项目名称:cerebrum,代码行数:15,代码来源:import_from_FS.py

示例9: write_role_info

# 需要导入模块: from Cerebrum.utils.atomicfile import SimilarSizeWriter [as 别名]
# 或者: from Cerebrum.utils.atomicfile.SimilarSizeWriter import write [as 别名]
 def write_role_info(self, role_file):
     """Lager fil med informasjon om alle roller definer i FS.PERSONROLLE"""
     logger.info("Writing role info to '%s'", role_file)
     f = SimilarSizeWriter(role_file, mode='w', encoding=XML_ENCODING)
     f.max_pct_change = 50
     f.write(xml.xml_hdr + "<data>\n")
     cols, role = self._ext_cols(
         self.fs.undervisning.list_alle_personroller())
     for r in role:
         f.write(
             xml.xmlify_dbrow(r, xml.conv_colnames(cols), 'rolle') + "\n")
     f.write("</data>\n")
     f.close()
开发者ID:unioslo,项目名称:cerebrum,代码行数:15,代码来源:import_from_FS.py

示例10: write_netpubl_info

# 需要导入模块: from Cerebrum.utils.atomicfile import SimilarSizeWriter [as 别名]
# 或者: from Cerebrum.utils.atomicfile.SimilarSizeWriter import write [as 别名]
 def write_netpubl_info(self, netpubl_file):
     """Lager fil med informasjon om status nettpublisering"""
     logger.info("Writing nettpubl info to '%s'", netpubl_file)
     f = SimilarSizeWriter(netpubl_file, mode='w',
                           encoding=XML_ENCODING)
     f.max_pct_change = 50
     f.write(xml.xml_hdr + "<data>\n")
     cols, nettpubl = self._ext_cols(self.fs.person.list_status_nettpubl())
     for n in nettpubl:
         f.write(xml.xmlify_dbrow(n,
                                  xml.conv_colnames(cols),
                                  'nettpubl') + "\n")
     f.write("</data>\n")
     f.close()
开发者ID:unioslo,项目名称:cerebrum,代码行数:16,代码来源:import_from_FS.py

示例11: write_evukurs_info

# 需要导入模块: from Cerebrum.utils.atomicfile import SimilarSizeWriter [as 别名]
# 或者: from Cerebrum.utils.atomicfile.SimilarSizeWriter import write [as 别名]
 def write_evukurs_info(self, evu_kursinfo_file):
     """Skriv data om alle EVU-kurs (vi trenger dette bl.a. for å bygge
     EVU-delen av CF)."""
     logger.info("Writing evukurs info to '%s'", evu_kursinfo_file)
     f = SimilarSizeWriter(evu_kursinfo_file, mode='w',
                           encoding=XML_ENCODING)
     f.max_pct_change = 50
     f.write(xml.xml_hdr + "<data>\n")
     cols, evukurs = self._ext_cols(self.fs.evu.list_kurs())
     for ek in evukurs:
         f.write(
             xml.xmlify_dbrow(
                 ek, xml.conv_colnames(cols), "evukurs") + "\n")
     f.write("</data>\n")
     f.close()
开发者ID:unioslo,项目名称:cerebrum,代码行数:17,代码来源:import_from_FS.py

示例12: write_misc_info

# 需要导入模块: from Cerebrum.utils.atomicfile import SimilarSizeWriter [as 别名]
# 或者: from Cerebrum.utils.atomicfile.SimilarSizeWriter import write [as 别名]
 def write_misc_info(self, misc_file, tag, func_name):
     """Lager fil med data fra gitt funksjon i access_FS"""
     logger.info("Writing misc info to '%s'", misc_file)
     f = SimilarSizeWriter(misc_file, mode='w', encoding=XML_ENCODING)
     f.max_pct_change = 50
     f.write(xml.xml_hdr + "<data>\n")
     func = reduce(
         lambda obj, attr: getattr(obj, attr),
         func_name.split('.'), self.fs)
     cols, dta = self._ext_cols(func())
     for t in dta:
         self.fix_float(t)
         f.write(xml.xmlify_dbrow(t, xml.conv_colnames(cols), tag) + "\n")
     f.write("</data>\n")
     f.close()
开发者ID:unioslo,项目名称:cerebrum,代码行数:17,代码来源:import_from_FS.py

示例13: write_undenh_metainfo

# 需要导入模块: from Cerebrum.utils.atomicfile import SimilarSizeWriter [as 别名]
# 或者: from Cerebrum.utils.atomicfile.SimilarSizeWriter import write [as 别名]
 def write_undenh_metainfo(self, undervenh_file):
     """Skriv metadata om undervisningsenheter for inneværende+neste
     semester."""
     logger.info("Writing undenh_meta info to '%s'", undervenh_file)
     f = SimilarSizeWriter(undervenh_file, mode='w',
                           encoding=XML_ENCODING)
     f.max_pct_change = 50
     f.write(xml.xml_hdr + "<undervenhet>\n")
     for semester in ('current', 'next'):
         cols, undenh = self._ext_cols(
             self.fs.undervisning.list_undervisningenheter(sem=semester))
         for u in undenh:
             f.write(
                 xml.xmlify_dbrow(u, xml.conv_colnames(cols), 'undenhet') +
                 "\n")
     f.write("</undervenhet>\n")
     f.close()
开发者ID:unioslo,项目名称:cerebrum,代码行数:19,代码来源:import_from_FS.py

示例14: generate_passwd

# 需要导入模块: from Cerebrum.utils.atomicfile import SimilarSizeWriter [as 别名]
# 或者: from Cerebrum.utils.atomicfile.SimilarSizeWriter import write [as 别名]
def generate_passwd(filename, shadow_file, spread=None):
    logger.debug("generate_passwd: %s", (filename, shadow_file, spread))
    if spread is None:
        raise ValueError("Must set user_spread")
    shells = {}
    for s in posix_user.list_shells():
        shells[int(s['code'])] = s['shell']
    f = SimilarSizeWriter(filename, "w", encoding='ISO-8859-1')
    f.max_pct_change = 10
    if shadow_file:
        s = SimilarSizeWriter(shadow_file, "w", encoding='UTF-8')
        s.max_pct_change = 10
    diskid2path = {}
    disk = Factory.get('Disk')(db)
    for d in disk.list(spread=spread):
        diskid2path[int(d['disk_id'])] = d['path']

    def process_user(user_rows):
        row = user_rows[0]
        uname = row['entity_name']
        tmp = posix_user.illegal_name(uname)
        if tmp:
            raise BadUsername("Bad username %s" % tmp)
        if len(uname) > 8:
            raise BadUsername("Bad username %s" % uname)
        passwd = row['auth_data']
        if passwd is None:
            passwd = '*'
        posix_group.posix_gid = row['posix_gid']
        gecos = row['gecos']
        if gecos is None:
            gecos = row['name']
        if gecos is None:
            gecos = "GECOS NOT SET"
        gecos = transliterate.to_iso646_60(gecos)
        shell = shells[int(row['shell'])]
        if row['quarantine_type'] is not None:
            now = mx.DateTime.now()
            quarantines = []
            for qrow in user_rows:
                if (qrow['start_date'] <= now
                    and (qrow['end_date'] is None or qrow['end_date'] >= now)
                    and (qrow['disable_until'] is None
                         or qrow['disable_until'] < now)):
                    # The quarantine found in this row is currently
                    # active.
                    quarantines.append(qrow['quarantine_type'])
            qh = QuarantineHandler.QuarantineHandler(db, quarantines)
            if qh.should_skip():
                raise UserSkipQuarantine
            if qh.is_locked():
                passwd = '*locked'
            qshell = qh.get_shell()
            if qshell is not None:
                shell = qshell

        home = posix_user.resolve_homedir(
            account_name=uname,
            home=row['disk_id'],
            disk_path=diskid2path[int(row['disk_id'])])
        if home is None:
            # TBD: Is this good enough?
            home = '/'

        if shadow_file:
            s.write("%s:%s:::\n" % (uname, passwd))
            if not passwd[0] == '*':
                passwd = "!!"

        line = ':'.join((uname, passwd, text_type(row['posix_uid']),
                         text_type(posix_group.posix_gid), gecos,
                         text_type(home), shell))
        if debug:
            logger.debug(line)
        f.write(line+"\n")
        # convert to 7-bit
    user_iter = posix_user.list_extended_posix_users(
        spread=spread, include_quarantines=True)
    prev_user = None
    user_rows = []
    for row in user_iter:
        if prev_user != row['account_id'] and prev_user is not None:
            try:
                process_user(user_rows)
            except NISMapError:
                logger.error("NISMapError", exc_info=1)
            except NISMapException:
                pass
            user_rows = [row]
        else:
            user_rows.append(row)
        prev_user = row['account_id']
    else:
        if user_rows:
            try:
                process_user(user_rows)
            except NISMapError:
                logger.error("NISMapError", exc_info=1)
            except NISMapException:
                pass
#.........这里部分代码省略.........
开发者ID:unioslo,项目名称:cerebrum,代码行数:103,代码来源:generate_nismaps.py

示例15: SimilarSizeWriter

# 需要导入模块: from Cerebrum.utils.atomicfile import SimilarSizeWriter [as 别名]
# 或者: from Cerebrum.utils.atomicfile.SimilarSizeWriter import write [as 别名]
    logger.info("Reading from: %s (%s bytes)",
                inFilePath, os.path.getsize(inFilePath))
    logger.info("Comparing to: %s (%s bytes)",
                outFilePath, os.path.getsize(outFilePath))

    if limit_percentage:
        ssw = SimilarSizeWriter(outFilePath, mode='w')
        ssw.max_pct_change = limit_percentage
    else:
        ssw = SimilarLineCountWriter(outFilePath, mode='w')
        ssw.max_line_change = limit_lines

    # read from input, write to temporary output file
    for line in inFile:
        ssw.write(line)

    try:
        # close() checks that changes are within limits
        ssw.close()
    except FileChangeTooBigError as err:
        logger.error(
            "Changes are too big, leaving behind temporary file %s",
            ssw._tmpname)
        raise err

    logger.info("Changes are within limits, file replaced")


def usage(exitcode=0):
    """Prints usage information."""
开发者ID:unioslo,项目名称:cerebrum,代码行数:32,代码来源:copy_with_size_check.py


注:本文中的Cerebrum.utils.atomicfile.SimilarSizeWriter.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。