예제 #1
0
파일: archive.py 프로젝트: pasandteam/pyabr
def gzip(src, dest):
    su = files.readall("/proc/info/su")
    if permissions.check(files.output(src), "r", su):
        if permissions.check(files.output(dest + ".gz"), "r", su):
            if files.isdir(src):
                if files.isdir(dest + ".gz"):
                    colors.show("libabr.archive.xzip", "fail", dest + ".gz" + ": dest is a directory.")
                else:
                    shutil.make_archive(files.input(dest), "gz", files.input(src))
            elif files.isfile(src):
                colors.show("libabr.archive.gzip", "fail", src + ": source is a file.")
            else:
                colors.show("libabr.archive.gzip", "fail", src + ": source not found.")
        else:
            colors.show("libabr.archive.gzip", "perm", "")
    else:
        colors.show("libabr.archive.gzip", "perm", "")
예제 #2
0
파일: archive.py 프로젝트: pasandteam/pyabr
def zip (src,dest):
    su = files.readall("/proc/info/su") ## Get user data base
    if permissions.check (files.output(src),"r",su): ## Check this user permissions
        if permissions.check (files.output(dest+".zip"),"r",su): ## Check read only permission
            if files.isdir (src): ## Check source dir exists
                if files.isdir (dest+".zip"): ## Check dest dir exists
                    colors.show("libabr.archive.zip", "fail", dest+".zip" + ": dest is a directory.")
                else:
                    shutil.make_archive(files.input(dest),"zip",files.input(src)) ## Create archive
            elif files.isfile (src):
                colors.show("libabr.archive.zip", "fail",src+ ": source is a file.") ## Show error for permissions
            else:
                colors.show("libabr.archive.zip", "fail",src+ ": source not found.")
        else:
            colors.show("libabr.archive.zip", "perm", "")
    else:
        colors.show ("libabr.archive.zip","perm","")
예제 #3
0
파일: file.py 프로젝트: pasandteam/pyabr
def readall(name):
    su = files.readall("/proc/info/su")
    if permissions.check(files.output(name), "r", su):
        if files.isfile(name):
            file = open(files.input(name), "rb")
            check_bin = str(file.read())
            file.close()
            if check_bin.__contains__("\\x00"):
                return check_bin
            else:
                return files.readall(name)
        else:
            colors.show("libabr.file.readall", "fail",
                        name + ": file not found.")
    else:
        colors.show("libabr.file.readall", "perm", "")
예제 #4
0
def download(packname):
    if permissions.check_root(files.readall("/proc/info/su")):
        mirror = files.readall('/app/mirrors/' + packname.lower())

        ## Download the file ##
        url = mirror
        r = requests.get(url, allow_redirects=True)

        ## Check permissions ##
        open(files.input('/app/cache/gets/' + packname.lower() + '.pa'),
             'wb').write(r.content)

        ## Remove temporary ##
        files.remove('/app/cache/gets/' + packname + '.pa')
    else:
        colors.show("libpa.download", "perm", "")
예제 #5
0
def build(name):
    if permissions.check_root(files.readall("/proc/info/su")):
        if not files.isfile(name + "/control/manifest"):
            colors.show("libpa.build", "fail", "cannot create archive package")
            clean()
            sys.exit(0)

        if not files.isdir(name + "/data"): files.mkdir(name + "/data")
        if not files.isdir(name + "/code"): files.mkdir(name + "/code")

        ## Remove cache archives ##
        if files.isdir('/app/cache/archives/code'):
            files.removedirs('/app/cache/archives/code')
        if files.isdir('/app/cache/archives/control'):
            files.removedirs('/app/cache/archives/control')
        if files.isdir('/app/cache/archives/data'):
            files.removedirs('/app/cache/archives/data')

        ## Copy dir ##
        files.copydir(name + '/data', '/app/cache/archives/data')
        files.copydir(name + '/code', '/app/cache/archives/code')
        files.copydir(name + '/control', '/app/cache/archives/control')

        ## Compile codes ##
        if files.isfile("/app/cache/archives/control/compile"):
            listcodes = control.read_list(
                "/app/cache/archives/control/compile")
            for i in listcodes:
                i = i.split(":")
                files.compile("/app/cache/archives/code/" + i[0],
                              "/app/cache/archives/data/" + i[1])

        ## Pack archives ##
        shutil.make_archive(files.input("/app/cache/archives/build/data"),
                            "xztar", files.input('/app/cache/archives/data'))
        shutil.make_archive(files.input("/app/cache/archives/build/control"),
                            "xztar",
                            files.input('/app/cache/archives/control'))
        shutil.make_archive(files.input(name), "zip",
                            files.input("/app/cache/archives/build"))

        files.cut(name + ".zip", name + ".pa")
        ## Unlock the cache ##
    else:
        colors.show("libpa.build", "perm", "")
예제 #6
0
def cat(name, option):

    ## Read files ##
    if option == '' or option == '-r':
        if files.isfile(name):
            if permissions.check(files.output(name), "r",
                                 files.readall("/proc/info/su")):
                file = open(files.input(name), "rb")
                check_bin = str(file.read())
                file.close()
                if check_bin.__contains__("\\x00"):
                    print(check_bin)
                else:
                    print(files.readall(name))
            else:
                colors.show("cat", "perm", "")
        elif files.isdir(name):
            colors.show("cat", "fail", name + ": is a directory.")
        else:
            colors.show("cat", "fail", name + ": file not found.")

    ## Create files ##
    elif option == '-c':
        if files.isdir(name):
            colors.show("cat", "fail", name + ": is a directory.")
        else:
            if permissions.check(files.output(name), "w",
                                 files.readall("/proc/info/su")):
                files.create(name)
            else:
                colors.show("cat", "perm", "")

    ## Write into files ##
    elif option == '-w':
        if files.isdir(name):
            colors.show("cat", "fail", name + ": is a directory.")
        else:
            if permissions.check(files.output(name), "w",
                                 files.readall("/proc/info/su")):

                ## Set EOF
                if cmdln[3:] == []:
                    EOF = 'EOF'
                else:
                    EOF = cmdln[3]

                # WRITE COMMAND LINE

                texts = ''

                while True:
                    cmd = input('> ')
                    if cmd == EOF: break
                    else:
                        if texts == '':
                            texts = cmd
                        else:
                            texts = texts + '\n' + cmd

                ## WRITE INTO FILE
                files.write(cmdln[2], texts)
            else:
                colors.show("cat", "perm", "")

    ## Write into files ##
    elif option == '-a':
        if files.isdir(name):
            colors.show("cat", "fail", name + ": is a directory.")
        else:
            if permissions.check(files.output(name), "w",
                                 files.readall("/proc/info/su")):

                ## Set EOF
                if cmdln[3] == []:
                    EOF = 'EOF'
                else:
                    EOF = cmdln[3]

                # WRITE COMMAND LINE

                texts = ''

                while True:
                    cmd = input('> ')
                    if cmd == EOF:
                        break
                    else:
                        if texts == '':
                            texts = cmd
                        else:
                            texts = texts + '\n' + cmd

                ## WRITE INTO FILE
                files.append(cmdln[2], texts)
            else:
                colors.show("cat", "perm", "")
예제 #7
0
파일: res.py 프로젝트: pasandteam/pyabr
def get(filename):
    model = control.read_record("model", "/etc/gui")  # read model

    if not filename == None:
        filename = filename.split("/")  # @widget:barge

        share = filename[0]
        name = filename[1]

        ## Real Resource ##
        if share.startswith("@widget"):
            if files.isfile("/usr/share/" +
                            share.replace("@widget", "widgets") + "/" + name +
                            ".ui"):
                return files.input("/usr/share/" +
                                   share.replace("@widget", "widgets") + "/" +
                                   name + ".ui")
            else:
                return None

        elif share.startswith("@font"):
            if files.isfile("/usr/share/fonts/" + name + ".ttf"):
                return "/usr/share/fonts/" + name + ".ttf"
            else:
                return None

        elif share.startswith("@background"):
            if files.isfile("/usr/share/backgrounds/" + name + ".svg"):
                return files.input("/usr/share/backgrounds/" + name + ".svg")
            elif files.isfile("/usr/share/backgrounds/" + name + ".png"):
                return files.input("/usr/share/backgrounds/" + name + ".png")
            elif files.isfile("/usr/share/backgrounds/" + name + ".jpg"):
                return files.input("/usr/share/backgrounds/" + name + ".jpg")
            elif files.isfile("/usr/share/backgrounds/" + name + ".jpeg"):
                return files.input("/usr/share/backgrounds/" + name + ".jpeg")
            elif files.isfile("/usr/share/backgrounds/" + name + ".gif"):
                return files.input("/usr/share/backgrounds/" + name + ".gif")
            else:
                return None

        elif share.startswith("@image"):
            if files.isfile("/usr/share/images/" + name + ".svg"):
                return files.input("/usr/share/images/" + name + ".svg")
            elif files.isfile("/usr/share/images/" + name + ".png"):
                return files.input("/usr/share/images/" + name + ".png")
            elif files.isfile("/usr/share/images/" + name + ".jpg"):
                return files.input("/usr/share/images/" + name + ".jpg")
            elif files.isfile("/usr/share/images/" + name + ".jpeg"):
                return files.input("/usr/share/images/" + name + ".jpeg")
            elif files.isfile("/usr/share/images/" + name + ".gif"):
                return files.input("/usr/share/images/" + name + ".gif")
            else:
                return None

        elif share.startswith("@app"):
            if files.isfile("/usr/share/" +
                            share.replace("@app", "applications") + "/" +
                            name + ".desk"):
                return files.input("/usr/share/" +
                                   share.replace("@app", "applications") +
                                   "/" + name + ".desk")
            else:
                return None

        elif share.startswith("@icon"):
            if files.isfile("/usr/share/" + share.replace("@icon", "icons") +
                            "/" + name + ".svg"):
                return files.input("/usr/share/" +
                                   share.replace("@icon", "icons") + "/" +
                                   name + ".svg")
            elif files.isfile("/usr/share/" + share.replace("@icon", "icons") +
                              "/" + name + ".png"):
                return files.input("/usr/share/" +
                                   share.replace("@icon", "icons") + "/" +
                                   name + ".png")
            elif files.isfile("/usr/share/" + share.replace("@icon", "icons") +
                              "/" + name + ".gif"):
                return files.input("/usr/share/" +
                                   share.replace("@icon", "icons") + "/" +
                                   name + ".gif")
            else:
                return None

        elif share.startswith("@string"):
            locale = control.read_record("locale", "/etc/gui")
            id = files.readall("/proc/info/id")

            ## Set default lang ##
            if locale == None: locale = "en"

            ## Get value from string ##
            result = control.read_record(
                id.replace(".desk", "") + "." + name,
                "/usr/share/locales/" + locale + ".locale")

            ## Find default ##
            if result == None:
                result = control.read_record(
                    id.replace(".desk", "") + "." + name,
                    "/usr/share/locales/" + 'en' + ".locale")

            return result

        ## None Resource ##
        else:
            return None
    else:
        return None
예제 #8
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", "")
예제 #9
0
        if files.isfile(argv[1] + ".so"):
            if permissions.check(files.output(argv[1]) + ".so", "x", user):
                ## Set args ##
                sys.argv = argv[1:]

                appname = argv[1]

                sys.path.append(files.parentdir(appname))
                __import__(files.filename(appname))
                sys.path.remove(files.parentdir(appname))
            else:
                colors.show(argv[1], "perm", "")
        elif files.isfile(argv[1]):
            if permissions.check(files.output(argv[1]), "x", user):
                ## command ##
                command = [files.input(argv[1])]

                for i in argv[2:]:
                    command.append(i)

                sub.call(command)
            else:
                colors.show(argv[1], "perm", "")
        elif files.isfile(argv[1] + '.sa'):
            if permissions.check(files.output(argv[1]) + '.sa', "x", user):
                strv = ''
                for i in argv[1:]:
                    strv += i
                core.system('saye ' + strv)
            else:
                colors.show(argv[1], "perm", "")
예제 #10
0
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 ##
url = upgrade_mirror
r = requests.get(url, allow_redirects=True)

## Check permissions ##
open(files.input('/tmp/pyabr.zip'), 'wb').write(r.content)

## Install Upgrades ##
colors.show("", "ok", "Install upgrade packages ...")

## Just download ##
shutil.unpack_archive('/tmp/pyabr.tar.xz', '/tmp/pyabr', 'xztar')

## Unpack backups ##
colors.show("", "ok", "Unpack backup files ...")
files.cut('/app/backups/deskdirs.bak', '/etc/deskdirs')
files.cut('/app/backups/color.bak', '/etc/color')
files.cut('/app/backups/guest.bak', '/etc/guest')
files.cut('/app/backups/gui.bak', '/etc/gui')
files.cut('/app/backups/hostname.bak', '/etc/hostname')
files.cut('/app/backups/interface.bak', '/etc/interface')
예제 #11
0
파일: wget.py 프로젝트: pasandteam/pyabr
#  Pyabr (c) 2020 Pasand team. GNU General Public License v3.0
#
#  Offical website:         http://itpasand.com
#  Telegram or Gap channel: @pyabr
#  Telegram or Gap group:   @pyabr_community
#  Git source:              github.com/pasandteam/pyabr
#
#######################################################################################
import sys, shutil, os, requests
from libnam import files, permissions, colors

# https://www.tutorialspoint.com/downloading-files-from-web-using-python

## Check params ##

if sys.argv[1:] == [] and sys.argv[2:]:
    colors.show('wget', 'fail', 'no inputs.')

## Download ##

colors.show('', 'ok',
            'Download \'' + sys.argv[2] + "\' from (" + sys.argv[1] + ") ...")
url = sys.argv[1]
r = requests.get(url, allow_redirects=True)

## Check permissions ##
if permissions.check(files.output(sys.argv[2]), "w",
                     files.readall("/proc/info/su")):
    open(files.input(sys.argv[2]), 'wb').write(r.content)
else:
    colors.show("wget", "perm", "")