Ejemplo n.º 1
0
 def ready_target(self):
     self._check_target()
     makepaths(self.target)
     device = self.machine.array_hack(self.machine.current.machine_type)
     clause = Eq('filesystem', self.machine.current.filesystem)
     clause &= Gt('partition', '0')
     table = 'filesystem_mounts natural join mounts'
     mounts = self.cursor.select(table=table, clause=clause, order='mnt_point')
     if mounts[0].mnt_point != '/':
         raise Error, 'bad set of mounts', mounts
     mddev = False
     mdnum = 0
     if device == '/dev/md':
         mddev = True
         pdev = '/dev/md0'
         mdnum += 1
     else:
         pdev = self._pdev(device, mounts[0].partition)
     print 'mounting target', pdev, self.target
     clause &= Neq('mnt_point', '/')
     mounts = self.cursor.select(table=table, clause=clause, order='ord')
     runlog('mount %s %s' % (pdev, self.target))
     for mnt in mounts:
         tpath = os.path.join(self.target, mnt.mnt_point[1:])
         makepaths(tpath)
         if mddev:
             pdev = '/dev/md%d' % mdnum
         else:
             pdev = self._pdev(device, mnt.partition)
         mdnum += 1
         runlog('mount %s %s' % (pdev, tpath))
     self._mounted = True
Ejemplo n.º 2
0
 def export_scripts(self, bkup_path):
     makepaths(join(bkup_path, 'scripts'))
     for row in self.scripts():
         npath = join(bkup_path, 'scripts', row.script)
         nfile = self.scriptfile(row.script)
         filecopy(nfile, npath)
         nfile.close()
Ejemplo n.º 3
0
 def backup_scripts(self, bkup_path):
     makepaths(join(bkup_path, 'scripts'))
     for row in self.scripts():
         npath = join(bkup_path, 'scripts', row.script)
         nfile = self.scriptfile(row.script)
         filecopy(nfile, npath)
         nfile.close()
Ejemplo n.º 4
0
def make_sources_list(cfg, target, suite):
    section = 'debrepos'
    aptdir = os.path.join(target, 'etc', 'apt')
    makepaths(aptdir)
    sources_list = file(os.path.join(aptdir, 'sources.list'), 'w')
    source = RepositorySource()
    source.uri = cfg.get(section, 'http_mirror')
    source.suite = suite
    source.set_path()
    sources_list.write(str(source) + '\n')
    source.type = 'deb-src'
    sources_list.write(str(source) + '\n')
    source.type = 'deb'
    if suite == 'woody' or cfg.has_option(section, '%s_nonus' % suite):
        source.suite += '/non-US'
        sources_list.write(str(source) + '\n')
        source.type = 'deb-src'
        sources_list.write(str(source) + '\n')
    loption = suite + '_local'
    if cfg.has_option(section, loption) and cfg[loption] == 'true':
        sources_list.write('deb %s/local %s/\n' % (source.uri, suite))
        sources_list.write('deb-src %s/local %s/\n' % (source.uri, suite))
    coption = suite + '_common'
    if cfg.has_option(section, coption) and cfg[coption] == 'true':
        sources_list.write('deb %s/local common/\n' % source.uri)
        sources_list.write('deb-src %s/local common/\n' % source.uri)
    sources_list.write('\n')
    sources_list.close()
Ejemplo n.º 5
0
 def ready_target(self):
     self._check_target()
     makepaths(self.target)
     device = self.machine.array_hack(self.machine.current.machine_type)
     clause = Eq("filesystem", self.machine.current.filesystem)
     clause &= Gt("partition", "0")
     table = "filesystem_mounts natural join mounts"
     mounts = self.cursor.select(table=table, clause=clause, order="mnt_point")
     if mounts[0].mnt_point != "/":
         raise Error, "bad set of mounts", mounts
     mddev = False
     mdnum = 0
     if device == "/dev/md":
         mddev = True
         pdev = "/dev/md0"
         mdnum += 1
     else:
         pdev = self._pdev(device, mounts[0].partition)
     print "mounting target", pdev, self.target
     clause &= Neq("mnt_point", "/")
     mounts = self.cursor.select(table=table, clause=clause, order="ord")
     runlog("mount %s %s" % (pdev, self.target))
     for mnt in mounts:
         tpath = os.path.join(self.target, mnt.mnt_point[1:])
         makepaths(tpath)
         if mddev:
             pdev = "/dev/md%d" % mdnum
         else:
             pdev = self._pdev(device, mnt.partition)
         mdnum += 1
         runlog("mount %s %s" % (pdev, tpath))
     self._mounted = True
Ejemplo n.º 6
0
def make_sources_list(cfg, target, suite):
    section = 'debrepos'
    aptdir = os.path.join(target, 'etc', 'apt')
    makepaths(aptdir)
    sources_list = file(os.path.join(aptdir, 'sources.list'), 'w')
    source = RepositorySource()
    source.uri = cfg.get(section, 'http_mirror')
    source.suite = suite
    source.set_path()
    sources_list.write(str(source) +'\n')
    source.type = 'deb-src'
    sources_list.write(str(source) +'\n')
    source.type = 'deb'
    if suite == 'woody' or cfg.has_option(section, '%s_nonus' % suite):
        source.suite += '/non-US'
        sources_list.write(str(source) +'\n')
        source.type = 'deb-src'
        sources_list.write(str(source) +'\n')
    loption = suite + '_local'
    if cfg.has_option(section, loption) and cfg[loption] == 'true':
        sources_list.write('deb %s/local %s/\n' % (source.uri, suite))
        sources_list.write('deb-src %s/local %s/\n' % (source.uri, suite))
    coption = suite + '_common'
    if cfg.has_option(section, coption) and cfg[coption] == 'true':
        sources_list.write('deb %s/local common/\n' % source.uri)
        sources_list.write('deb-src %s/local common/\n' % source.uri)
    sources_list.write('\n')
    sources_list.close()
Ejemplo n.º 7
0
def make_base_filesystem(suite, name, cfg=None, size=3000, mkfs='mke2fs'):
    if cfg is None:
        cfg = Configuration('pbootstrap')
    path = join(cfg['basetarball_path'], name)
    makepaths(dirname(path))
    create_root_filesystem(path, 3000)
    uml = UmlBootstrapper(suite, path)
    uml.run_uml()
Ejemplo n.º 8
0
 def backup_templates(self, bkup_path):
     makepaths(join(bkup_path, 'templates'))
     for t in self.templates():
         npath = join(bkup_path, 'templates', t.package, t.template)
         tfile = self.templatefile(t.package, t.template)
         makepaths(dirname(npath))
         filecopy(tfile, npath + '.template')
         tfile.close()
Ejemplo n.º 9
0
 def export_templates(self, bkup_path):
     makepaths(join(bkup_path, 'templates'))
     for t in self.templates():
         npath = join(bkup_path, 'templates', t.package, t.template)
         tfile = self.templatefile(t.package, t.template)
         makepaths(dirname(npath))
         filecopy(tfile, npath + '.template')
         tfile.close()
Ejemplo n.º 10
0
def select_a_file(action, path, ok_function):
    filesel = FileSelection(title="__select_a_file__")
    filesel.cancel_button.connect("clicked", lambda x: filesel.destroy())
    makepaths(dirname(path))
    filesel.show()
    filesel.ok_button.connect("clicked", ok_function, filesel)
    filesel.set_data("action", action)
    filesel.set_filename(path)
    return filesel
Ejemplo n.º 11
0
def unpack_kernel(kernel, target):
    isolinux_dir = join(target, 'isolinux')
    dp = DpkgDeb()
    tmp = join(target, 'tmp')
    if isdir(tmp):
        os.system('rm %s -fr' % tmp)
    makepaths(tmp)
    os.system('dpkg-deb -x %s %s' % (kernel, tmp))
    os.system('cp %s/boot/vmlinuz-* %s/vmlinuz' % (tmp, isolinux_dir))
    os.system('rm %s -fr' % tmp)
Ejemplo n.º 12
0
def select_a_file(action, path, ok_function):
        filesel = FileSelection(title='__select_a_file__')
        filesel.cancel_button.connect('clicked',
                                      lambda x: filesel.destroy())
        makepaths(dirname(path))
        filesel.show()
        filesel.ok_button.connect('clicked', ok_function, filesel)
        filesel.set_data('action', action)
        filesel.set_filename(path)
        return filesel
Ejemplo n.º 13
0
def unpack_kernel(kernel, target):
    isolinux_dir = join(target, "isolinux")
    dp = DpkgDeb()
    tmp = join(target, "tmp")
    if isdir(tmp):
        os.system("rm %s -fr" % tmp)
    makepaths(tmp)
    os.system("dpkg-deb -x %s %s" % (kernel, tmp))
    os.system("cp %s/boot/vmlinuz-* %s/vmlinuz" % (tmp, isolinux_dir))
    os.system("rm %s -fr" % tmp)
Ejemplo n.º 14
0
 def check_release_file(self, release_file):
     release_file.seek(0)
     makepaths(self.local_src.distpath)
     localpath = join(self.local_src.distpath, 'Release')
     if isfile(localpath):
         rsum = md5sum(release_file, keepopen=True)
         lsum = md5sum(file(localpath))
         release_file.seek(0)
         return rsum == lsum
     else:
         return False
Ejemplo n.º 15
0
 def extract_packages(self, packages, path):
     makepaths(path)
     os.system("rm %s/* -fr" % path)
     print "extracting ", ", ".join(packages)
     print "current_suite", self.current_suite
     for package in packages:
         tmp_path = join(path, package)
         makepaths(tmp_path)
         package_path = self.repos.full_path(self.current_suite, package)
         self.dpkg.extract(package_path, tmp_path)
         self.dpkg.control(package_path, tmp_path)
Ejemplo n.º 16
0
 def extract_packages(self, packages, path):
     makepaths(path)
     gpath = '%s/*' % path
     subprocess.call(['rm', gpath, '-fr'])
     print 'extracting ', ', '.join(packages)
     print 'current_suite', self.current_suite
     for package in packages:
         tmp_path = join(path, package)
         makepaths(tmp_path)
         package_path = self.repos.full_path(self.current_suite, package)
         self.dpkg.extract(package_path, tmp_path)
         self.dpkg.control(package_path, tmp_path)
Ejemplo n.º 17
0
 def backup_trait(self, tball_path):
     xmldata = TraitElement(self.conn, self.suite)
     xmldata.set(self.current_trait)
     bkup_path = tempfile.mkdtemp(self.suite, self.current_trait)
     makepaths(bkup_path)
     xmlfile = file(join(bkup_path, 'trait.xml'), 'w')
     xmlfile.write(xmldata.toprettyxml())
     xmlfile.close()
     self._templates.backup_templates(bkup_path)
     self._scripts.backup_scripts(bkup_path)
     make_tarball(bkup_path, tball_path, self.current_trait)
     os.system('rm %s -fr' % bkup_path)
Ejemplo n.º 18
0
 def backup_trait(self, tball_path):
     xmldata = TraitElement(self.conn, self.suite)
     xmldata.set(self.current_trait)
     bkup_path = tempfile.mkdtemp(self.suite, self.current_trait)
     makepaths(bkup_path)
     xmlfile = file(join(bkup_path, 'trait.xml'), 'w')
     xmlfile.write(xmldata.toprettyxml())
     xmlfile.close()
     self._templates.backup_templates(bkup_path)
     self._scripts.backup_scripts(bkup_path)
     make_tarball(bkup_path, tball_path, self.current_trait)
     os.system('rm %s -fr' % bkup_path)
Ejemplo n.º 19
0
 def insert_new_template(self, package, template, path):
     newfile = readfile(path)
     filename = self.template_filename(package, template)
     makepaths(dirname(filename))
     writefile(filename, newfile)
     try:
         self.traittemplate.insert_template(dict(package=package, template=template),
                                            file(path))
     except OperationalError:
         dialogs.Message('template already exists')
     self.set_template(package, template)
     self.reset_rows()
Ejemplo n.º 20
0
 def backup_trait(self, tball_path):
     print 'this needs to be called export_trait'
     xmldata = TraitElement(self.conn, self.suite)
     xmldata.set(self.current_trait)
     bkup_path = join(tball_path, self.current_trait)
     makepaths(bkup_path)
     xmlfile = file(join(bkup_path, 'trait.xml'), 'w')
     xmlfile.write(xmldata.toprettyxml())
     xmlfile.close()
     self._templates.export_templates(bkup_path)
     self._scripts.export_scripts(bkup_path)
     print 'all exported', os.listdir(bkup_path)
Ejemplo n.º 21
0
 def backup_trait(self, tball_path):
     print 'this needs to be called export_trait'
     xmldata = TraitElement(self.conn, self.suite)
     xmldata.set(self.current_trait)
     bkup_path = join(tball_path, self.current_trait)
     makepaths(bkup_path)
     xmlfile = file(join(bkup_path, 'trait.xml'), 'w')
     xmlfile.write(xmldata.toprettyxml())
     xmlfile.close()
     self._templates.export_templates(bkup_path)
     self._scripts.export_scripts(bkup_path)
     print 'all exported', os.listdir(bkup_path)
Ejemplo n.º 22
0
 def insert_new_template(self, package, template, path):
     newfile = readfile(path)
     filename = self.template_filename(package, template)
     makepaths(dirname(filename))
     writefile(filename, newfile)
     try:
         self.traittemplate.insert_template(
             dict(package=package, template=template), file(path))
     except OperationalError:
         dialogs.Message('template already exists')
     self.set_template(package, template)
     self.reset_rows()
Ejemplo n.º 23
0
 def update_flatrepos(self):
     rpath = self.release.path(section, release=release)
     localpath = pjoin(self.local.source.distpath, rpath)
     url = pjoin(self.source.distpath, rpath)
     status = self.local.check_section(section, release=release)
     if status == 'missing':
         makepaths(dirname(localpath))
         rfile = get_url(url)
         filecopy(rfile, localpath)
     elif status == 'corrupt':
         rfile = get_url(url)
         filecopy(rfile, localpath)
     else:
         print localpath, status
Ejemplo n.º 24
0
 def _update_section_(self, section, release=False):
     rpath = self.release.path(section, release=release)
     localpath = path.join(self.backup.source.distpath, rpath)
     url = path.join(self.local.source.distpath, rpath)
     status = self.backup.check_section(section, release=release)
     if status == 'missing':
         makepaths(path.dirname(localpath))
         rfile = file(url)
         filecopy(rfile, localpath)
     elif status == 'corrupt':
         rfile = file(url)
         filecopy(rfile, localpath)
     else:
         print localpath, status
Ejemplo n.º 25
0
 def export_client(self, client):
     cpath, ppath, fpath, tpath = self._cpaths_(client)
     makepaths(cpath)
     profiles, families, traits = self._client_schema(client)
     disks, mtypes, machines = self._client_mdata(client)
     if not disks:
         disks = None
     if not mtypes:
         mtypes = None
     if not machines:
         machines = None
     element = ClientMachineDatabaseElement(self.conn, disks, mtypes,
                                            machines)
     mdbpath = join(cpath, 'machine_database.xml')
     mdfile = file(mdbpath, 'w')
     mdfile.write(element.toprettyxml())
     mdfile.close()
     if profiles:
         makepaths(ppath)
         pp = PaellaProfiles(self.conn)
         for profile in profiles:
             pp.write_profile(profile, ppath)
     if families:
         makepaths(fpath)
         f = Family(self.conn)
         for family in families:
             f.write_family(family, fpath)
     if traits:
         makepaths(tpath)
Ejemplo n.º 26
0
 def export_client(self, client):
     cpath, ppath, fpath, tpath = self._cpaths_(client)
     makepaths(cpath)
     profiles, families, traits = self._client_schema(client) 
     disks, mtypes, machines = self._client_mdata(client)
     if not disks:
         disks = None
     if not mtypes:
         mtypes = None
     if not machines:
         machines = None
     element = ClientMachineDatabaseElement(self.conn, disks, mtypes, machines)
     mdbpath = join(cpath, 'machine_database.xml')
     mdfile = file(mdbpath, 'w')
     mdfile.write(element.toprettyxml())
     mdfile.close()
     if profiles:
         makepaths(ppath)
         pp = PaellaProfiles(self.conn)
         for profile in profiles:
             pp.write_profile(profile, ppath)
     if families:
         makepaths(fpath)
         f = Family(self.conn)
         for family in families:
             f.write_family(family, fpath)
     if traits:
         makepaths(tpath)
Ejemplo n.º 27
0
 def _update_section_(self, section, release=False):
     rpath = self.release.path(section, release=release)
     localpath = pjoin(self.local.source.distpath, rpath)
     url = pjoin(self.source.distpath, rpath)
     status = self.local.check_section(section, release=release)
     if status == 'missing':
         makepaths(dirname(localpath))
         rfile = get_url(url)
         filecopy(rfile, localpath)
     elif status == 'corrupt':
         rfile = get_url(url)
         filecopy(rfile, localpath)
     else:
         print localpath, status
Ejemplo n.º 28
0
def store_trait(traittemplate, tmpl_path, bkup_path, name):
    trait = traittemplate.current_trait
    suite = traittemplate.suite
    conn = traittemplate.conn
    xmldata = TraitElement(conn, suite)
    xmldata.set(trait)
    root_path = join(bkup_path, suite, trait, name)
    os.system('rm %s -fr' %root_path)
    makepaths(root_path)
    xmlfile = file(join(root_path, 'trait.xml'), 'w')
    xmlfile.write(xmldata.toprettyxml())
    xmlfile.close()
    traittemplate.set_template_path(tmpl_path)
    traittemplate.backup_templates(join(root_path, 'templates'))
Ejemplo n.º 29
0
 def update_flatrepos(self):
     rpath = self.release.path(section, release=release)
     localpath = path.join(self.backup.source.distpath, rpath)
     url = path.join(self.local.source.distpath, rpath)
     status = self.backup.check_section(section, release=release)
     if status == 'missing':
         makepaths(path.dirname(localpath))
         rfile = get_url(url)
         filecopy(rfile, localpath)
     elif status == 'corrupt':
         rfile = get_url(url)
         filecopy(rfile, localpath)
     else:
         print localpath, status
Ejemplo n.º 30
0
def store_trait(traittemplate, tmpl_path, bkup_path, name):
    trait = traittemplate.current_trait
    suite = traittemplate.suite
    conn = traittemplate.conn
    xmldata = TraitElement(conn, suite)
    xmldata.set(trait)
    root_path = join(bkup_path, suite, trait, name)
    os.system('rm %s -fr' %root_path)
    makepaths(root_path)
    xmlfile = file(join(root_path, 'trait.xml'), 'w')
    xmlfile.write(xmldata.toprettyxml())
    xmlfile.close()
    traittemplate.set_template_path(tmpl_path)
    traittemplate.backup_templates(join(root_path, 'templates'))
Ejemplo n.º 31
0
 def update_release(self):
     makepaths(self.backup.source.distpath)
     localpath = path.join(self.backup.source.distpath, 'Release')
     url = path.join(self.local.source.distpath, 'Release')
     release = file(url)
     if not path.isfile(localpath):
         self._write_release_(release, localpath)
     release.seek(0)
     rsum = md5sum(release, keepopen=True)
     lsum = md5sum(file(localpath))
     release.seek(0)
     if lsum != rsum:
         self._write_release_(release, localpath)
     release.seek(0)
     self.backup.parse_release()
     self.release = self.backup.release
Ejemplo n.º 32
0
 def update_release(self):
     makepaths(self.local.source.distpath)
     localpath = pjoin(self.local.source.distpath, 'Release')
     url = pjoin(self.source.distpath, 'Release')
     release = get_url(url)
     if not isfile(localpath):
         self._write_release_(release, localpath)
     release.seek(0)
     rsum = md5sum(release, keepopen=True)
     lsum = md5sum(file(localpath))
     release.seek(0)
     if lsum != rsum:
         self._write_release_(release, localpath)
     release.seek(0)
     self.local.parse_release()
     self.release = self.local.release
Ejemplo n.º 33
0
 def backup(self, path=None):
     if path is None:
         path = self.path
     if not isdir(path):
         raise Error, '%s not a directory' % path
     dbfile = file(join(path, 'database.xml'), 'w')
     self.writexml(dbfile, indent='\t', newl='\n', addindent='\t')
     dbfile.close()
     self.backup_profiles(path)
     suites = [x.suite for x in self._suite_rows()]
     for suite in suites:
         makepaths(join(path, suite))
         trait = Trait(self.conn, suite)
         for t in trait.get_trait_list():
             trait.set_trait(t)
             trait.backup_trait(join(path, suite))
Ejemplo n.º 34
0
 def backup(self, path=None):
     if path is None:
         path = self.path
     if not isdir(path):
         raise Error, '%s not a directory' % path
     dbfile = file(join(path, 'database.xml'), 'w')
     self.writexml(dbfile, indent='\t', newl='\n', addindent='\t')
     dbfile.close()
     self.backup_profiles(path)
     suites = [x.suite for x in self._suite_rows()]
     for suite in suites:
         makepaths(join(path, suite))
         trait = Trait(self.conn, suite)
         for t in trait.get_trait_list():
             trait.set_trait(t)
             trait.backup_trait(join(path, suite))
Ejemplo n.º 35
0
 def ready_base_for_install(self):
     self._check_bootstrap()
     self._check_installer()
     fstab = self.machine.make_fstab()
     ready_base_for_install(self.target, self.cfg, self.suite, fstab)
     if self._raid_setup:
         mdpath = join(self.target, 'etc/mdadm')
         makepaths(mdpath)
         mdconf = file(join(mdpath, 'mdadm.conf'), 'w')
         for diskname in self._raid_drives:
             devices = ['%s*' % d for d in self._raid_drives[diskname]]
             line = 'DEVICE %s' % ' '.join(devices)
             mdconf.write(line + '\n')
         arrdata = commands.getoutput('mdadm -E -s')
         mdconf.write(arrdata + '\n')
         mdconf.write('\n')
         mdconf.close()
Ejemplo n.º 36
0
 def ready_base_for_install(self):
     self._check_bootstrap()
     self._check_installer()
     fstab = self.machine.make_fstab()
     ready_base_for_install(self.target, self.cfg, self.suite, fstab)
     if self._raid_setup:
         mdpath = join(self.target, "etc/mdadm")
         makepaths(mdpath)
         mdconf = file(join(mdpath, "mdadm.conf"), "w")
         for diskname in self._raid_drives:
             devices = ["%s*" % d for d in self._raid_drives[diskname]]
             line = "DEVICE %s" % " ".join(devices)
             mdconf.write(line + "\n")
         arrdata = commands.getoutput("mdadm -E -s")
         mdconf.write(arrdata + "\n")
         mdconf.write("\n")
         mdconf.close()
Ejemplo n.º 37
0
def secure_target(target, admin, keys, homepath):
    while homepath[0] == '/':
        homepath = homepath[1:]
    os.system('chroot %s rm /etc/ssh/ssh_host_*' % target)
    os.system('chroot %s dpkg-reconfigure -plow ssh' % target)
    os.system('chroot %s shadowconfig on' % target)
    admin_home = os.path.join(target, homepath, admin)
    sshdir = os.path.join(admin_home, '.ssh')
    if not os.path.isdir(sshdir):
        makepaths(sshdir)
    authorized = os.path.join(sshdir, 'authorized_keys')
    authorizedfile = file(authorized, 'w')
    authorizedfile.write(keys + '\n')
    authorizedfile.close()
    chroot_home = os.path.join('/', homepath, admin)
    os.system('chroot %s chown -R %s:staff %s' % (target, admin, chroot_home))
    os.system('chmod 0600 %s' % authorized)
    os.system('chmod 0750 %s' % sshdir)
Ejemplo n.º 38
0
 def _make_template_common(self, template, tmpl):
     sub = self.traittemplate.template.sub()
     newpath = join(self.target, template.template)
     self.log.info('target template %s' % newpath)
     dir = dirname(newpath)
     if not isdir(dir):
         makepaths(dir)
     if tmpl != sub:
         self.log.info('%s %s subbed' % (template.package, template.template))
     newfile = file(newpath, 'w')
     newfile.write(sub)
     newfile.close()
     mode = template.mode
     if mode[0] == '0' and len(mode) <= 7 and mode.isdigit():
         mode = eval(mode)
     os.chmod(newpath, mode)
     own = ':'.join([template.owner, template.grp_owner])
     os.system(self.command('chown', '%s %s' %(own, join('/', template.template))))
Ejemplo n.º 39
0
def secure_target(target, admin, keys, homepath):
    while homepath[0] == '/':
        homepath = homepath[1:]
    os.system('chroot %s rm /etc/ssh/ssh_host_*' % target)
    os.system('chroot %s dpkg-reconfigure -plow ssh' % target)
    os.system('chroot %s shadowconfig on' % target)
    admin_home = os.path.join(target, homepath, admin)
    sshdir = os.path.join(admin_home, '.ssh')
    if not os.path.isdir(sshdir):
        makepaths(sshdir)
    authorized = os.path.join(sshdir, 'authorized_keys')
    authorizedfile = file(authorized, 'w')
    authorizedfile.write(keys + '\n')
    authorizedfile.close()
    chroot_home = os.path.join('/', homepath, admin)
    os.system('chroot %s chown -R %s:staff %s' % (target, admin, chroot_home))
    os.system('chmod 0600 %s' % authorized)
    os.system('chmod 0750 %s' % sshdir)
Ejemplo n.º 40
0
 def ready_target(self):
     self._check_target()
     makepaths(self.target)
     device = self.machine.array_hack(self.machine.current.machine_type)
     clause = Eq('filesystem', self.machine.current.filesystem)
     clause &= Gt('partition', '0')
     table = 'filesystem_mounts natural join mounts'
     mounts = self.cursor.select(table=table, clause=clause, order='mnt_point')
     if mounts[0].mnt_point != '/':
         raise Error, 'bad set of mounts', mounts
     pdev = self._pdev(device, mounts[0].partition)
     print 'mounting target', pdev, self.target
     runlog('mount %s %s' % (pdev, self.target))
     for mnt in mounts[1:]:
         tpath = os.path.join(self.target, mnt.mnt_point[1:])
         makepaths(tpath)
         pdev = self._pdev(device, mnt.partition)
         runlog('mount %s %s' % (pdev, tpath))
     self._mounted = True
Ejemplo n.º 41
0
 def ready_target(self):
     self._check_target()
     makepaths(self.target)
     device = self.machine.array_hack(self.machine.current.machine_type)
     clause = Eq('filesystem', self.machine.current.filesystem)
     clause &= Gt('partition', '0')
     table = 'filesystem_mounts natural join mounts'
     mounts = self.cursor.select(table=table, clause=clause, order='mnt_point')
     if mounts[0].mnt_point != '/':
         raise Error, 'bad set of mounts', mounts
     pdev = self._pdev(device, mounts[0].partition)
     print 'mounting target', pdev, self.target
     runlog('mount %s %s' % (pdev, self.target))
     for mnt in mounts[1:]:
         tpath = os.path.join(self.target, mnt.mnt_point[1:])
         makepaths(tpath)
         pdev = self._pdev(device, mnt.partition)
         runlog('mount %s %s' % (pdev, tpath))
     self._mounted = True
Ejemplo n.º 42
0
 def __init__(self, conn, suite, trait, tmp_path, name='ConfigGen'):
     MenuWindow.__init__(self)
     self.__original_text__ = ''
     self.editor = TemplateEnvironment(conn)
     self.editor.set_suite(suite)
     self.editor.set_trait(trait)
     self.vbox.add(self.editor)
     self.conn = conn
     self.__add_menus__()
     self.filename = ''
     self.filesel = None
     self.set_size_request(600, 500)
     self.cfg = Configuration()
     self.cfg.section = 'paella-admin'
     self.conf_path = self.cfg['config_path']
     self.template_path = pjoin(self.cfg['template_path'], suite, trait)
     self.tmp_path = tmp_path
     makepaths(self.template_path)
     self.dialogs = {}.fromkeys(['template_record', 'environment'])
Ejemplo n.º 43
0
 def sync_section(self, section):
     missing, corrupt = self.diff[section]
     for a_path in missing:
         lpath = path.join(self.backup.source.root, a_path)
         url = path.join(self.local.source.root, a_path)
         if not path.isdir(path.dirname(lpath)):
             print path.dirname(lpath)
             makepaths(path.dirname(lpath))
         try:
             link(url, lpath)
         except OSError:
             print 'bad', url
     for a_path in corrupt:
         lpath = path.join(self.backup.source.root, a_path)
         url = path.join(self.local.source.root, a_path)
         if not path.isdir(path.dirname(lpath)):
             makepaths(path.dirname(lpath))
         try:
             link(url, lpath)
         except OSError:
             print 'bad', url
Ejemplo n.º 44
0
 def sync_section(self, section):
     missing, corrupt = self.diff[section]
     for a_path in missing:
         lpath = path.join(self.backup.source.root, a_path)
         url = path.join(self.local.source.root, a_path)
         if not path.isdir(path.dirname(lpath)):
             print path.dirname(lpath)
             makepaths(path.dirname(lpath))
         try:
             link(url, lpath)
         except OSError:
             print 'bad', url
     for a_path in corrupt:
         lpath = path.join(self.backup.source.root, a_path)
         url = path.join(self.local.source.root, a_path)
         if not path.isdir(path.dirname(lpath)):
             makepaths(path.dirname(lpath))
         try:
             link(url, lpath)
         except OSError:
             print 'bad', url
Ejemplo n.º 45
0
 def _update_section_(self, section, release=False):
     
     rpath = self.release.path(section, release=release)
     localpath = join(self.local_src.distpath, rpath)
     url = join(self.remote_src.distpath, rpath)
     status = self.local.check_dist_section(section, release=release)
     please_insert = False
     if not self.local._section_.count_rows(section) and not release:
             please_insert = True
     while status in ['missing', 'corrupt']:
         if status == 'missing':
             makepaths(dirname(localpath))
         rfile = get_url(url)
         filecopy(rfile, localpath)
         print localpath, status
         status = self.local.check_dist_section(section, release=release)
     print localpath, status
     if please_insert:
         self.insert_section_data(section)
     elif status == 'corrupt':
         self.insert_section_data(section)
Ejemplo n.º 46
0
 def _make_template_common(self, template, tmpl):
     sub = self.traittemplate.template.sub()
     newpath = join(self.target, template.template)
     self.log.info('target template %s' % newpath)
     dir = dirname(newpath)
     if not isdir(dir):
         makepaths(dir)
     if tmpl != sub:
         self.log.info('%s %s subbed' %
                       (template.package, template.template))
     newfile = file(newpath, 'w')
     newfile.write(sub)
     newfile.close()
     mode = template.mode
     if mode[0] == '0' and len(mode) <= 7 and mode.isdigit():
         mode = eval(mode)
     os.chmod(newpath, mode)
     own = ':'.join([template.owner, template.grp_owner])
     os.system(
         self.command('chown',
                      '%s %s' % (own, join('/', template.template))))
Ejemplo n.º 47
0
 def make_sources_list(self):
     section = self.cfg.section
     self.cfg.change('repos')
     aptdir = join(self.target, 'etc', 'apt')
     makepaths(aptdir)
     sources_list = file(join(aptdir, 'sources.list'), 'w')
     source = RepositorySource()
     source.uri = self.cfg['local_http']
     suite = self.options['paellasuite'].value
     source.suite = suite
     source.set_path()
     sources_list.write(str(source) + '\n')
     source.type = 'deb-src'
     sources_list.write(str(source) + '\n')
     source.type = 'deb'
     if suite == 'woody':
         source.suite = 'woody/non-US'
         sources_list.write(str(source) + '\n')
         source.type = 'deb-src'
         sources_list.write(str(source) + '\n')
     sources_list.close()
     self.cfg.change(section)
Ejemplo n.º 48
0
 def run(self):
     c = self.curl
     while True:
         try:
             self.current_job = self.jobs.get()
         except Empty:
             self.current_job = None
         else:
             if self.current_job is not None:
                 c.setopt(c.URL, self.current_job.url)
                 self.urlfun(self.current_job.url)
                 try:
                     f = file(self.current_job.path, 'w')
                 except IOError:
                     makepaths(dirname(self.current_job.path))
                     f = file(self.current_job.path, 'w')
                 c.setopt(c.WRITEFUNCTION, f.write)
                 c.perform()
                 f.close()
                 self.progress(1, 1, 0, 0)
                 self.current_job = None
             else:
                 pass
Ejemplo n.º 49
0
 def run(self):
     c = self.curl
     while True:
         try:
             self.current_job = self.jobs.get()
         except Empty:
             self.current_job = None
         else:
             if self.current_job is not None:
                 c.setopt(c.URL, self.current_job.url)
                 self.urlfun(self.current_job.url)
                 try:
                     f = file(self.current_job.path, 'w')
                 except IOError:
                     makepaths(dirname(self.current_job.path))
                     f = file(self.current_job.path, 'w')
                 c.setopt(c.WRITEFUNCTION, f.write)
                 c.perform()
                 f.close()
                 self.progress(1, 1, 0, 0)
                 self.current_job = None
             else:
                 pass
Ejemplo n.º 50
0
 def ask_file_dialog(self, menuitem, name):
     if name in ['open', 'save']:
         filesel = FileSelection(title=name)
         filesel.cancel_button.connect('clicked',
                                       lambda x: filesel.destroy())
         filesel.show()
     if name == 'save':
         if not has_extension(self.filename, 'template'):
             path = self._tmpl_path_()
         else:
             path = pjoin(self.template_path, self.filename)
         makepaths(dirname(path))
     elif name =='open':
         self.filename = ''
         path = pjoin(self.tmp_path, self.filename)
         print 'open', path
     elif name == 'edit' and self.filename:
         path = self._tmpl_path_()
         self._fill_from_path(self._tmpl_path_())
         
     if name in ['open', 'save']:
         filesel.set_filename(path)
         filesel.ok_button.connect('clicked', self.ok_file, filesel)
         filesel.set_data('action', name)
Ejemplo n.º 51
0
    def ask_file_dialog(self, menuitem, name):
        if name in ['open', 'save']:
            filesel = FileSelection(title=name)
            filesel.cancel_button.connect('clicked',
                                          lambda x: filesel.destroy())
            filesel.show()
        if name == 'save':
            if not has_extension(self.filename, 'template'):
                path = self._tmpl_path_()
            else:
                path = pjoin(self.template_path, self.filename)
            makepaths(dirname(path))
        elif name == 'open':
            self.filename = ''
            path = pjoin(self.tmp_path, self.filename)
            print 'open', path
        elif name == 'edit' and self.filename:
            path = self._tmpl_path_()
            self._fill_from_path(self._tmpl_path_())

        if name in ['open', 'save']:
            filesel.set_filename(path)
            filesel.ok_button.connect('clicked', self.ok_file, filesel)
            filesel.set_data('action', name)
Ejemplo n.º 52
0
 def set_logfile(self, logfile):
     self.logfile = os.environ['LOGFILE']
     makepaths(os.path.dirname(self.logfile))
     format = '%(name)s - %(asctime)s - %(levelname)s: %(message)s'
     self.log = Log('paella-installer', self.logfile, format)
Ejemplo n.º 53
0
 def backup_profiles(self, path=None):
     profiles_dir = join(path, 'profiles')
     makepaths(profiles_dir)
     self.profiles.export_profiles(profiles_dir)
Ejemplo n.º 54
0
def setup_directory(target):
    isolinux_dir = join(target, "isolinux")
    if not isdir(isolinux_dir):
        makepaths(isolinux_dir)
    if not isfile(join(isolinux_dir, "isolinux.bin")):
        os.system("cp /usr/lib/syslinux/isolinux.bin %s" % isolinux_dir)
Ejemplo n.º 55
0
 def set_path(self, directory):
     self.path = directory
     makepaths(self.path)
     os.system('chmod 777 %s' % self.path)
Ejemplo n.º 56
0
def bootstrap_base(suite, path, cfg=None, size=3000, mkfs='mke2fs'):
    cfg = UmlConfig()
    makepaths(dirname(path))
    create_sparse_file(path, size=size)
    uml = UmlBootstrapper(suite, path, cfg=cfg)
    uml.run_uml()
Ejemplo n.º 57
0
 def set_path(self, directory):
     self.path = directory
     makepaths(self.path)
     os.system('chmod 777 %s' % self.path)
Ejemplo n.º 58
0
def setup_directory(target):
    isolinux_dir = join(target, 'isolinux')
    if not isdir(isolinux_dir):
        makepaths(isolinux_dir)
    if not isfile(join(isolinux_dir, 'isolinux.bin')):
        os.system('cp /usr/lib/syslinux/isolinux.bin %s' % isolinux_dir)