示例#1
0
文件: generate.py 项目: zobelhelas/ud
 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))
示例#2
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'))
示例#3
0
 def test_remove_unicode(self):
     # See 2 above ;)
     import posix
     try:
         posix.remove(u"ą")
     except OSError:
         pass
示例#4
0
文件: generate.py 项目: zobelhelas/ud
    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')
 def tearDown(self):
     remove(self.檔案.name)