示例#1
0
文件: file.py 项目: pasandteam/pyabr
def copy(src, dest):
    su = files.readall("/proc/info/su")
    if permissions.check(files.output(src), "r", su):
        if isfile(src):
            if permissions.check(files.output(dest), "w", su):
                if files.isdir(dest):
                    colors.show("libabr.file.copy", "fail",
                                dest + ": dest is a directory.")
                else:
                    perm = permissions.get_permissions(files.output(src))
                    control.write_record(files.output(dest), perm,
                                         "/etc/permtab")
                    files.copy(src, dest)
            else:
                colors.show("libabr.file.copy", "perm", "")
        elif isdir(src):
            if permissions.check(files.output(dest), "w", su):
                if files.isfile(dest):
                    colors.show("libabr.file.copy", "fail",
                                dest + ": dest is a file.")
                else:
                    perm = permissions.get_permissions(files.output(src))
                    control.write_record(files.output(dest), perm,
                                         "/etc/permtab")
                    files.copydir(src, dest)
            else:
                colors.show("libabr.file.copy", "perm", "")
        else:
            colors.show("libabr.file.copy", "fail",
                        src + ": source not found.")
    else:
        colors.show("libabr.file.copy", "perm", "")
示例#2
0
def start (id):

    ## Check exists ##
    if files.isfile ('/proc/id/'+id):
        pass

    colors.show (id,'ok-start','')

    ## Create id ##
    files.create ("/proc/id/"+id)


    ## Check desktop shortcut ##
    if files.isfile ("/usr/share/applications/"+id):
        files.copy ("/usr/share/applications/"+id+".desk","/proc/id/"+id) # Copy all informations about this GUI application

    ## Set default id ##
    files.write ("/proc/info/id",id)
示例#3
0
文件: mv.py 项目: pasandteam/pyabr
def mv(src, dest):
    if files.isdir(src):
        if files.isfile(dest):
            colors.show("mv", "fail", dest + ": dest is a file.")
        else:
            if permissions.check(
                    files.output(src), "r",
                    files.readall("/proc/info/su")) and permissions.check(
                        files.output(src), "w",
                        files.readall("/proc/info/su")):
                if permissions.check(files.output(dest), "w",
                                     files.readall("/proc/info/su")):
                    perm = permissions.get_permissions(files.output(src))
                    control.write_record(files.output(dest), perm,
                                         "/etc/permtab")
                    files.copydir(src, dest)
                    files.removedirs(src)
                else:
                    colors.show("mv", "perm", "")
            else:
                colors.show("mv", "perm", "")
    elif files.isfile(src):
        if files.isdir(dest):
            colors.show("mv", "fail", dest + ": dest is a directory.")
        else:
            if permissions.check(
                    files.output(src), "r",
                    files.readall("/proc/info/su")) and permissions.check(
                        files.output(src), "w",
                        files.readall("/proc/info/su")):
                if permissions.check(files.output(dest), "w",
                                     files.readall("/proc/info/su")):
                    perm = permissions.get_permissions(files.output(src))
                    control.write_record(files.output(dest), perm,
                                         "/etc/permtab")
                    files.copy(src, dest)
                    files.remove(src)
                else:
                    colors.show("mv", "perm", "")
            else:
                colors.show("mv", "perm", "")
    else:
        colors.show("mv", "fail", src + ": source not found.")
示例#4
0
def unpack(name):
    if permissions.check_root(files.readall("/proc/info/su")):
        ## unpack package ##
        shutil.unpack_archive(files.input(name),
                              files.input("/app/cache/archives/build"), "zip")

        shutil.unpack_archive(
            files.input("/app/cache/archives/build/data.tar.xz"),
            files.input("/app/cache/archives/data"), "xztar")
        shutil.unpack_archive(
            files.input("/app/cache/archives/build/control.tar.xz"),
            files.input("/app/cache/archives/control"), "xztar")

        ## Get database of this package ##
        name = control.read_record(
            "name", "/app/cache/archives/control/manifest").lower()
        unpack = control.read_record("unpack",
                                     "/app/cache/archives/control/manifest")
        depends = control.read_record("depends",
                                      "/app/cache/archives/control/manifest")

        if not (depends == None):
            depends.split(",")

        ## Search for tree dependency ##

        if not depends == None:
            for i in depends:
                if not files.isfile("/app/packages/" + i + ".manifest"):
                    core.system('paye -i ' + name)

        ## Write dependency ##

        if not depends == None:
            for i in depends:
                files.create("/app/packages/" + i + ".depends")
                files.write("/app/packages/" + i + ".depends", name + "\n")

        ## Run preinstall script ##

        if files.isfile('/app/cache/archives/control/preinstall.py'):
            files.compile('/app/cache/archives/control/preinstall.py',
                          '/usr/bin/preinstall.pyc')
            core.system('preinstall')  # Run it
            files.remove('/usr/bin/preinstall.pyc')

            ## Copy preinstall script ##

            files.copy('/app/cache/archives/control/preinstall.py',
                       '/app/packages/' + name + ".preinstall")

        ## Setting up ##

        if files.isfile("/app/cache/archives/control/list"):
            files.copy("/app/cache/archives/control/list",
                       "/app/packages/" + name + ".list")
        if files.isfile("/app/cache/archives/control/manifest"):
            files.copy("/app/cache/archives/control/manifest",
                       "/app/packages/" + name + ".manifest")

        ## Unpack data again ##
        shutil.unpack_archive(
            files.input("/app/cache/archives/build/data.tar.xz"),
            files.input(unpack), "xztar")

        ## After install ##

        ## Run postinstall script ##

        if files.isfile('/app/cache/archives/control/postinstall.py'):
            files.compile('/app/cache/archives/control/postinstall.py',
                          '/usr/bin/postinstall.pyc')
            core.system('postinstall')  # Run it
            files.remove('/usr/bin/postinstall.pyc')

            ## Copy preinstall script ##

            files.copy('/app/cache/archives/control/postinstall.py',
                       '/app/packages/' + name + ".postinstall")

        ## Copy other scripts ##
        if files.isfile('/app/cache/archives/control/preremove.py'):
            files.copy('/app/cache/archives/control/preremove.py',
                       '/app/packages/' + name + ".preremove")

        if files.isfile('/app/cache/archives/control/postremove.py'):
            files.copy('/app/cache/archives/control/postremove.py',
                       '/app/packages/' + name + ".postremove")

        ## Unlock the cache ##
    else:
        colors.show("libpa.unpack", "perm", "")
示例#5
0
def remove(name):
    if permissions.check_root(files.readall("/proc/info/su")):

        location = "/app/packages/" + name.lower() + ".manifest"

        if not files.isfile(location):
            colors.show("libpa.remove", "fail", name + ": package not found")
            clean()
            sys.exit(0)

        ## Database control ##

        list = "/app/packages/" + name.lower() + ".list"
        preinstall = "/app/packages/" + name.lower() + ".preinstall"
        postinstall = "/app/packages/" + name.lower() + ".postinstall"
        preremove = "/app/packages/" + name.lower() + ".preremove"
        postremove = "/app/packages/" + name.lower() + ".postremove"
        compile = "/app/packages/" + name.lower() + ".compile"
        depends = "/app/packages/" + name.lower() + ".depends"

        ## Create preremove and postremove copies ##

        if files.isfile(preremove):
            files.copy(preremove, "/app/cache/archives/control/preremove.py")
        if files.isfile(postremove):
            files.copy(postremove, "/app/cache/archives/control/postremove.py")

        ## Run pre remove script ##

        if files.isfile("/app/cache/archives/control/preremove.py"):
            files.compile("/app/cache/archives/control/preremove.py",
                          '/usr/bin/preremove.pyc')
            core.system("preremove")
            files.remove('/usr/bin/preremove.pyc')

        ## Remove depends ##

        if files.isfile(depends):
            depends = control.read_list(depends)
            for i in depends:
                remove(i)

        ####################

        unpack = control.read_record("unpack", location)

        ## Unpacked removal ##
        filelist = control.read_list(list)

        for i in filelist:
            if files.isdir(unpack + "/" + i):
                files.removedirs(unpack + "/" + i)
            elif files.isfile(unpack + "/" + i):
                files.remove(unpack + "/" + i)

        ## Database removal ##

        if files.isfile(location): files.remove(location)
        if files.isfile(compile): files.remove(compile)
        if files.isfile(list): files.remove(list)
        if files.isfile(preinstall): files.remove(preinstall)
        if files.isfile(postinstall): files.remove(postinstall)
        if files.isfile(preremove): files.remove(preremove)
        if files.isfile(postremove): files.remove(postremove)
        if files.isfile(depends): files.remove(depends)

        ## Remove source code ##
        if files.isdir('/usr/src/' + name):
            files.removedirs('/usr/src/' + name)

        ## Run postremove script ##

        if files.isfile("/app/cache/archives/control/postremove.py"):
            files.compile('/app/cache/archives/control/postremove.py',
                          '/usr/bin/postremove.pyc')
            core.system("postremove")
            files.remove('/usr/bin/postremove.pyc')

    else:
        colors.show("libpa.remove", "perm", "")
示例#6
0
process.check(switch)  # Check the switched process

if switch == None:
    switch = 0

files.write("/proc/info/sel", "/proc/" + str(switch))
select = files.readall("/proc/info/sel")

colors.show("/proc/" + str(switch), "ok-switch", "")

####################################################################################################

## @core/hostname ##

if files.isfile("/etc/hostname"):
    files.copy("/etc/hostname", "/proc/info/host")
    hostname = files.readall("/etc/hostname")
    colors.show("hostname", "ok-start", "")
else:
    colors.show("hostname", "fail-start", "")
    colors.show("kernel", "stop", "")
    sys.exit(0)

## @core/distro ##

if files.isfile("/etc/distro"):
    distro_name = control.read_record("name", "/etc/distro")
    distro_code = control.read_record("code", "/etc/distro")
    distro_version = control.read_record("version", "/etc/distro")
    distro_build = control.read_record("build", "/etc/distro")
    files.write("/proc/info/cs", distro_name)
示例#7
0
## Check root ##
if not permissions.check_root(files.readall("/proc/info/su")):
    colors.show("upgrade", "perm", "")
    exit(0)

upgrade_mirror = files.readall('/app/mirrors/update-mirror')

## Check nulls ##
if upgrade_mirror == None or upgrade_mirror == '' or upgrade_mirror == " ":
    colors.show("upgrade", "fail",
                "cannot upgrade system; upgrade mirror record is none.")
    exit()

    ## Back /etc files ##
colors.show("", "ok", "Create backup files ...")
files.copy('/etc/deskdirs', '/app/backups/deskdirs.bak')
files.copy('/etc/color', '/app/backups/color.bak')
files.copy('/etc/guest', '/app/backups/guest.bak')
files.copy('/etc/gui', '/app/backups/gui.bak')
files.copy('/etc/hostname', '/app/backups/hostname.bak')
files.copy('/etc/interface', '/app/backups/interface.bak')
files.copy('/etc/modules', '/app/backups/modules.bak')
files.copy('/etc/permtab', '/app/backups/permtab.bak')
files.copy('/etc/procmsg', '/app/backups/procmsg.bak')
files.copy('/etc/prompt', '/app/backups/prompt.bak')
files.copy('/etc/time', '/app/backups/time.bak')
files.copy('/etc/users/root', '/app/backups/root.bak')

## Get packages ##
colors.show("", "ok", "Get the lates version of Pyabr ...")
## Download the file ##