⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 install.py

📁 开源游戏代码
💻 PY
字号:
#!/usr/bin/env python# $Id: install.py,v 1.7 2002/01/04 11:12:33 marijn Exp $################# INSTALLER CODE ####################### Only touch if you know what your doing! ####### For configuration changes go to install.cfg #######################################################import sysimport osimport globimport shutilfiles = {}execfile("./install.cfg")if os.path.exists('./DEVELOPER'): # If we are developer    # change some settings. it will install into $HOME/test/    # and simlinking the files.     print prefix    for i in files.keys():        s = files[i]        s = s.replace(prefix, os.environ['HOME'] + '/test/')        files[i] = s           MakeSimLinks = 1 # force symlinks for development. class Installer:    def __init__(self, files):        cwd = os.getcwd()        self.root = Root()        for k in files.keys():            f = cwd + "/" + k            t = files[k]            self.root.build(f, t)                def install(self):        print "--- Looking good, starting installation ---"        self.root.start()class Item:    def __init__(self, parent, name):        self.parent = parent        self.name = name        self.children = {}    def path(self):        if(self.parent):            return self.parent.path() + "/" + self.name        else:            return self.name    def build(self, f, t):        path = t[1:]        p = path.find('/')        if(p == -1):            childName = path            childType = File            to = self.path()        else:            to = path[p:]            childName = path[0:p]            childType = Directory        if(self.children.has_key(childName)):            child = self.children[childName]        else:            child = childType(self, childName)            self.children[childName] = child            #print "p = %2d, parent = %s, name = %s, path = %s" % (p, self.path(), childName, to)        child.build(f, to)    def walk(self):        self.install()        for i in self.children.values():            i.walk()    def install(self):        raise "Abstract method", "This method shouldn't be called directly"    class Root(Item):    def __init__(self):        self.name = self.parent = '/'        self.children = {}    def path(self):        return ""    def start(self):        self.walk()    def install(self):        pass    class Directory(Item):    def install(self):        if os.path.exists(self.path()):            print "%s already exists, skipping" % self.path()        else:            print "make directory %s" % self.path()            try:                os.mkdir(self.path())            except OSError, e:                print e                sys.exit(1)class File(Item):    def build(self, f, t):        self.children = self.findFiles(f)        self.to = t    def findFiles(self, f):        res = []        if f[-1] == "/": f = f + "*"        if os.path.isdir(f) : f = f + "/*"        if os.path.isfile(f):            res.append(f)        else:            res = glob.glob(f)        return res    def walk(self):        for i in self.children:            self.install(i, self.to)    def install(self, src, dest):        p = src.rfind("/")        name = src[p:]        dest = dest + name        if MakeSimLinks:            if os.path.exists(dest):                print "%s already exists, replacing with Symlink from %s" % (dest, src)                os.unlink(dest)            else:                print "symLink %s -> %s" % (src, dest)            os.symlink(src, dest)        else:            if os.path.exists(dest):                print "%s already exists, replacing with %s" % (dest, src)            else:                print "copy %s -> %s" % (src, dest)            shutil.copy(src, dest)i = Installer(files)i.install()# $Log: install.py,v $# Revision 1.7  2002/01/04 11:12:33  marijn# Added developer configuration via ./DEVELOPER file## Revision 1.6  2002/01/03 22:07:26  marijn# Noved installer config to install.cfg## Revision 1.5  2002/01/03 16:25:51  marijn# Fixed execution bits on installed files.## Revision 1.4  2002/01/03 14:38:39  marijn# Now works when files already exist, and other fixes.## Revision 1.3  2001/12/31 22:35:10  marijn# Now works, still needs more testing.## Revision 1.2  2001/12/31 02:41:07  marijn# Much improved installer, still doesn't install thou..#

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -