RazmjenaVjestina
LinuxDistribucijaRazmjeneVjestina: Revision 5

evo trivijalno male verzije template file systema koja koristi fuse i empy libraryje

import em
import os
import mmap
import sys
import thread

from fuse import Fuse

active_module='__main__' #hack!!

def transform(file):
	tf = os.tmpfile()
	i = em.Interpreter(output=tf)
	i.include(file, sys.modules[active_module].__dict__)
	tf.flush()
	mm = mmap.mmap(tf.fileno(), os.fstat(tf.fileno()).st_size)
	return mm

class TmpltFS(Fuse):
	def __init__(self, *args, **kw):
		Fuse.__init__(self, *args, **kw)
		self.mountpoint = '/tmp/etc'
		self.multithreaded = 1
		self.template_dir='/tmp/template'

	def getdir(self, path):
		return map(lambda x: (x,0), os.listdir(self.template_dir + path))

	def getattr(self, path):
		return os.lstat(self.template_dir + path)
	
	def open(self, path, flags):
		os.close(os.open(self.template_dir + path, flags))
		return 0
	
	def read(self, path, len, offset):
		f = transform(self.template_dir + path)
		f.seek(offset)
		return f.read(len)

	def release(self, path, flags):
#		print path + ' >> close\n'
		return 0
	
#if __name__ == '__main__':
#	t()

def t():
	server = TmpltFS()
	server.main()

def run():
	thread.start_new_thread(t, ())

a koristi se ovako:

primjer Makefilea

import os

def gcc_mm(file):
    i,o,e = os.popen3(cc + ' -MM ' + file)
    ret = o.readline()
    return ret

def mkf_entry(_file):
    return gcc_mm(_file) + "\t" + cc + " -c " + _file + "\n\n"

def mk_head(flist):
    ret = "all: "
    for f in flist:
        ret += f[:-1] + 'o '
    return ret + "\n\t" + cc + " -o $@ $^\n\n"
    
def make_make(flist):
    lst = mk_head(flist)
    for f in flist:
        lst += mkf_entry(f)
    return lst

cc = 'gcc'

def get_cc():
    return cc

l = ['f1.c', 'f2.c']

i

CC=@make.cc
@{print make.make_make(make.l)}

ili (konfiguracija proftpd-a)

class ProFtpd:
    def __init__(self):
        self.name = 'Konferencija open source 2006'
        self.default_server = True
        self.require_valid_shell = False
        self.port = 8021
        self.umask = '022'
        self.max_instances = 10
        self.user = 'aka'
        self.group = 'users'
        self.allow_overwrite = True

def on_off(arg):
    if arg:
        return 'on'
    return 'off'

proftpd = ProFtpd()

i

# proftpd.conf template
# 
ServerName          "@proftpd.name"
ServerType          standalone
DefaultServer       @(on_off(proftpd.default_server))
RequireValidShell   @(on_off(proftpd.require_valid_shell))
AuthPAM             off
AuthPAMConfig       ftp

Port				@proftpd.port
Umask				@proftpd.umask

MaxInstances			@proftpd.max_instances

User				@proftpd.user
Group				@proftpd.group

<Directory />
  AllowOverwrite		@(on_off(proftpd.allow_overwrite))
</Directory>

<Anonymous ~ftp>
  User				ftp
  Group				ftp

  # We want clients to be able to login with "anonymous" as well as "ftp"
  UserAlias			anonymous ftp

  # Limit the maximum number of anonymous logins
  MaxClients			10

  # We want 'welcome.msg' displayed at login, and '.message' displayed
  # in each newly chdired directory.
  DisplayLogin			welcome.msg
  DisplayFirstChdir		.message

  # Limit WRITE everywhere in the anonymous chroot
  <Limit WRITE>
    DenyAll
  </Limit>

</Anonymous>

... detalji o teoretskom djelu sljede uskoro ...


original Jun 17 10:04am