예제 #1
0
파일: __init__.py 프로젝트: koberbe/elbe
 def __init__(self, *args, **kargs):
     Application.__init__(self, *args, **kargs)
     self.pm = ProjectManager("/var/cache/elbe")
예제 #2
0
파일: esoap.py 프로젝트: lwalewski/elbe
 def __init__ (self,engine):
     SimpleWSGISoapApp.__init__ (self)
     self.pm = ProjectManager ("/var/cache/elbe")
     SimplePlugin.__init__(self,engine)
     self.subscribe()
예제 #3
0
파일: esoap.py 프로젝트: cmhe/elbe
class ESoap(SimpleWSGISoapApp, SimplePlugin):
    def __init__(self, engine):
        SimpleWSGISoapApp.__init__(self)
        self.pm = ProjectManager("/var/cache/elbe")
        SimplePlugin.__init__(self, engine)
        self.subscribe()

    def stop(self):
        self.pm.stop()

    @soapmethod(String, String, _returns=Boolean)
    @soap_faults
    def login(self, user, passwd):
        s = request.environ['beaker.session']
        s['userid'] = self.pm.db.validate_login(user, passwd)
        s.save()

        return True

    @soapmethod(_returns=Array(String))
    @authenticated_admin
    @soap_faults
    def list_users(self):
        users = self.pm.db.list_users()
        return [u.name for u in users]

    @soapmethod(_returns=Array(SoapProject))
    @authenticated_admin
    @soap_faults
    def list_projects(self):
        projects = self.pm.db.list_projects()
        return [SoapProject(p) for p in projects]

    @soapmethod(String, _returns=Array(SoapFile))
    @authenticated_uid
    @soap_faults
    def get_files(self, uid, builddir):
        files = self.pm.db.get_project_files(builddir)
        return [SoapFile(f) for f in files]

    @soapmethod(String, String, Integer, _returns=String)
    @authenticated_uid
    @soap_faults
    def get_file(self, uid, builddir, filename, part):
        size = 1024 * 1024 * 5
        pos = size * part
        file_name = builddir + "/" + filename
        file_stat = os.stat(file_name)

        if (pos >= file_stat.st_size):
            return "EndOfFile"

        with file(file_name) as fp:
            if not fp:
                return "FileNotFound"
            try:
                fp.seek(pos)
                data = fp.read(size)
                return binascii.b2a_base64(data)
            except:
                return "EndOfFile"

    @soapmethod(String, Integer, _returns=String)
    @authenticated_uid
    @soap_faults
    def get_build_chroot_tarball(self, uid, builddir, part):
        from subprocess import Popen, PIPE

        if not hasattr(self, 'tarball_creation_process'):
            setattr(self, 'tarball_creation_process', {})

        token = uid

        # One external process per token:
        if token not in self.tarball_creation_process:
            self.tarball_creation_process[token] = None

        # If first part was requested but a tarball process is already
        # running, kill it.
        if self.tarball_creation_process[token] and part == 0:
            self.tarball_creation_process[token].kill()
            self.tarball_creation_process[token].wait()
            self.tarball_creation_process[token] = None

        # If no tarball creation process is currently running,
        # create a new one.
        if not self.tarball_creation_process[token]:
            self.tarball_creation_process[token] = (Popen([
                "tar", "-cJ", "--exclude=./tmp/*", "--exclude=./dev/*",
                "--exclude=./run/*", "--exclude=./sys/*", "--exclude=./proc/*",
                "--exclude=./var/cache/*", "-C",
                os.path.join(builddir, "chroot"), "."
            ],
                                                          stdout=PIPE))

        size = 1024 * 1024 * 5

        try:
            data = self.tarball_creation_process[token].stdout.read(size)
            if not data:
                raise Exception()
            return binascii.b2a_base64(data)
        except:
            self.tarball_creation_process[token].kill()
            self.tarball_creation_process[token].wait()
            self.tarball_creation_process[token] = None
            return "EndOfFile"

    @soapmethod(String)
    @authenticated_uid
    @soap_faults
    def build_sysroot(self, uid, builddir):
        self.pm.open_project(uid, builddir)
        self.pm.build_sysroot(uid)

    @soapmethod(String, Boolean, Boolean)
    @authenticated_uid
    @soap_faults
    def build(self, uid, builddir, build_bin, build_src):
        self.pm.open_project(uid, builddir)
        self.pm.build_current_project(uid, build_bin, build_src)

    @soapmethod(String)
    @authenticated_uid
    @soap_faults
    def build_pbuilder(self, uid, builddir):
        self.pm.open_project(uid, builddir)
        self.pm.build_pbuilder(uid)

    @soapmethod(String, String)
    @authenticated_uid
    @soap_faults
    def set_xml(self, uid, builddir, xml):
        self.pm.open_project(uid, builddir)

        with NamedTemporaryFile() as fp:
            fp.write(binascii.a2b_base64(xml))
            fp.flush()
            self.pm.set_current_project_xml(uid, fp.name)

    @soapmethod(String)
    @authenticated_uid
    @soap_faults
    def start_cdrom(self, uid, builddir):
        self.pm.open_project(uid, builddir)

        cdrom_fname = os.path.join(builddir, "uploaded_cdrom.iso")

        # Now write empty File
        fp = open(cdrom_fname, "w")
        fp.close()

    @soapmethod(String, String)
    @authenticated_uid
    @soap_faults
    def append_cdrom(self, uid, builddir, data):
        self.pm.open_project(uid, builddir)

        cdrom_fname = os.path.join(builddir, "uploaded_cdrom.iso")

        # Now append data to cdrom_file
        fp = open(cdrom_fname, "a")
        fp.write(binascii.a2b_base64(data))
        fp.close()

    @soapmethod(String)
    @authenticated_uid
    @soap_faults
    def finish_cdrom(self, uid, builddir):
        self.pm.open_project(uid, builddir)
        self.pm.set_current_project_upload_cdrom(uid)

    @soapmethod(String)
    @authenticated_uid
    @soap_faults
    def start_pdebuild(self, uid, builddir):
        self.pm.open_project(uid, builddir)

        pdebuild_fname = os.path.join(builddir, "current_pdebuild.tar.gz")

        # Now write empty File
        fp = open(pdebuild_fname, "w")
        fp.close()

    @soapmethod(String, String)
    @authenticated_uid
    @soap_faults
    def append_pdebuild(self, uid, builddir, data):
        self.pm.open_project(uid, builddir)

        pdebuild_fname = os.path.join(builddir, "current_pdebuild.tar.gz")

        # Now write empty File
        fp = open(pdebuild_fname, "a")
        fp.write(binascii.a2b_base64(data))
        fp.close()

    @soapmethod(String)
    @authenticated_uid
    @soap_faults
    def finish_pdebuild(self, uid, builddir):
        self.pm.open_project(uid, builddir)
        self.pm.build_current_pdebuild(uid)

    @soapmethod(String)
    @authenticated_uid
    @soap_faults
    def reset_project(self, uid, builddir):
        self.pm.db.reset_project(builddir, True)

    @soapmethod(String)
    @authenticated_uid
    @soap_faults
    def del_project(self, uid, builddir):
        self.pm.del_project(uid, builddir)

    @soapmethod(String, _returns=String)
    @authenticated_uid
    @soap_faults
    def create_project(self, uid, xml):
        with NamedTemporaryFile() as fp:
            fp.write(binascii.a2b_base64(xml))
            fp.flush()
            prjid = self.pm.create_project(uid, fp.name)

        return prjid

    @soapmethod(String, _returns=Boolean)
    @authenticated_uid
    @soap_faults
    def get_project_busy(self, uid, builddir):
        self.pm.open_project(uid, builddir)

        return self.pm.current_project_is_busy(uid)

    @soapmethod()
    @authenticated_uid
    @soap_faults
    def shutdown_initvm(self, uid):
        system("shutdown -h now")
예제 #4
0
파일: esoap.py 프로젝트: lwalewski/elbe
class ESoap (SimpleWSGISoapApp, SimplePlugin):

    def __init__ (self,engine):
        SimpleWSGISoapApp.__init__ (self)
        self.pm = ProjectManager ("/var/cache/elbe")
        SimplePlugin.__init__(self,engine)
        self.subscribe()

    def stop(self):
        self.pm.stop()

    @soapmethod (String, String, _returns=Boolean )
    @soap_faults
    def login(self, user, passwd):
        s = request.environ['beaker.session']
        s['userid'] = self.pm.db.validate_login(user, passwd)
        s.save()

        return True


    @soapmethod (_returns=Array(String))
    @authenticated_admin
    @soap_faults
    def list_users (self):
        users = self.pm.db.list_users ()
        return [u.name for u in users]

    @soapmethod (_returns=Array(SoapProject))
    @authenticated_admin
    @soap_faults
    def list_projects (self):
        projects = self.pm.db.list_projects ()
        return [SoapProject(p) for p in projects]

    @soapmethod (String, _returns=Array(SoapFile))
    @authenticated_uid
    @soap_faults
    def get_files (self, uid, builddir):
        files = self.pm.db.get_project_files (builddir)
        return [SoapFile(f) for f in files]

    @soapmethod (String, String, Integer, _returns=String)
    @authenticated_uid
    @soap_faults
    def get_file (self, uid, builddir, filename, part):
        size = 1024 * 1024 * 5
        pos = size * part
        file_name = builddir + "/" + filename
        file_stat = os.stat (file_name)

        if (pos >= file_stat.st_size):
            return "EndOfFile"

        with file (file_name) as fp:
            if not fp:
                return "FileNotFound"
            try:
                fp.seek (pos)
                data = fp.read (size)
                return binascii.b2a_base64 (data)
            except:
                return "EndOfFile"

    @soapmethod (String)
    @authenticated_uid
    @soap_faults
    def build_sysroot (self, uid, builddir):
        self.pm.open_project (uid, builddir)
        self.pm.build_sysroot (uid)

    @soapmethod (String, Boolean, Boolean)
    @authenticated_uid
    @soap_faults
    def build (self, uid, builddir, build_bin, build_src):
        self.pm.open_project (uid, builddir)
        self.pm.build_current_project (uid, build_bin, build_src)

    @soapmethod (String)
    @authenticated_uid
    @soap_faults
    def build_pbuilder (self, uid, builddir):
        self.pm.open_project (uid, builddir)
        self.pm.build_pbuilder (uid)

    @soapmethod (String, String)
    @authenticated_uid
    @soap_faults
    def set_xml (self, uid, builddir, xml):
        self.pm.open_project (uid, builddir)

        with NamedTemporaryFile() as fp:
            fp.write (binascii.a2b_base64 (xml))
            fp.flush ()
            self.pm.set_current_project_xml (uid, fp.name)

    @soapmethod (String)
    @authenticated_uid
    @soap_faults
    def start_cdrom (self, uid, builddir):
        self.pm.open_project (uid, builddir)

        cdrom_fname = os.path.join (builddir, "uploaded_cdrom.iso")

        # Now write empty File
        fp = open (cdrom_fname, "w")
        fp.close()

    @soapmethod (String, String)
    @authenticated_uid
    @soap_faults
    def append_cdrom (self, uid, builddir, data):
        self.pm.open_project (uid, builddir)

        cdrom_fname = os.path.join (builddir, "uploaded_cdrom.iso")

        # Now append data to cdrom_file
        fp = open (cdrom_fname, "a")
        fp.write (binascii.a2b_base64 (data))
        fp.close()

    @soapmethod (String)
    @authenticated_uid
    @soap_faults
    def finish_cdrom (self, uid, builddir):
        self.pm.open_project (uid, builddir)
        self.pm.set_current_project_upload_cdrom (uid)

    @soapmethod (String)
    @authenticated_uid
    @soap_faults
    def start_pdebuild (self, uid, builddir):
        self.pm.open_project (uid, builddir)

        pdebuild_fname = os.path.join (builddir, "current_pdebuild.tar.gz")

        # Now write empty File
        fp = open (pdebuild_fname, "w")
        fp.close()

    @soapmethod (String, String)
    @authenticated_uid
    @soap_faults
    def append_pdebuild (self, uid, builddir, data):
        self.pm.open_project (uid, builddir)

        pdebuild_fname = os.path.join (builddir, "current_pdebuild.tar.gz")

        # Now write empty File
        fp = open (pdebuild_fname, "a")
        fp.write (binascii.a2b_base64 (data))
        fp.close()

    @soapmethod (String)
    @authenticated_uid
    @soap_faults
    def finish_pdebuild (self, uid, builddir):
        self.pm.open_project (uid, builddir)
        self.pm.build_current_pdebuild (uid)

    @soapmethod (String)
    @authenticated_uid
    @soap_faults
    def reset_project (self, uid, builddir):
        self.pm.db.reset_project (builddir, True)

    @soapmethod (String)
    @authenticated_uid
    @soap_faults
    def del_project (self, uid, builddir):
        self.pm.del_project (uid, builddir)

    @soapmethod (String, _returns=String)
    @authenticated_uid
    @soap_faults
    def create_project (self, uid, xml):
        with NamedTemporaryFile() as fp:
            fp.write (binascii.a2b_base64 (xml))
            fp.flush ()
            prjid = self.pm.create_project (uid, fp.name)

        return prjid

    @soapmethod (String, _returns=Boolean)
    @authenticated_uid
    @soap_faults
    def get_project_busy (self, uid, builddir):
        self.pm.open_project (uid, builddir)

        return self.pm.current_project_is_busy (uid)

    @soapmethod ()
    @authenticated_uid
    @soap_faults
    def shutdown_initvm (self, uid):
        system ("shutdown -h now")
예제 #5
0
파일: esoap.py 프로젝트: cmhe/elbe
class ESoap (SimpleWSGISoapApp, SimplePlugin):

    def __init__ (self,engine):
        SimpleWSGISoapApp.__init__ (self)
        self.pm = ProjectManager ("/var/cache/elbe")
        SimplePlugin.__init__(self,engine)
        self.subscribe()

    def stop(self):
        self.pm.stop()

    @soapmethod (String, String, _returns=Boolean )
    @soap_faults
    def login(self, user, passwd):
        s = request.environ['beaker.session']
        s['userid'] = self.pm.db.validate_login(user, passwd)
        s.save()

        return True


    @soapmethod (_returns=Array(String))
    @authenticated_admin
    @soap_faults
    def list_users (self):
        users = self.pm.db.list_users ()
        return [u.name for u in users]

    @soapmethod (_returns=Array(SoapProject))
    @authenticated_admin
    @soap_faults
    def list_projects (self):
        projects = self.pm.db.list_projects ()
        return [SoapProject(p) for p in projects]

    @soapmethod (String, _returns=Array(SoapFile))
    @authenticated_uid
    @soap_faults
    def get_files (self, uid, builddir):
        files = self.pm.db.get_project_files (builddir)
        return [SoapFile(f) for f in files]

    @soapmethod (String, String, Integer, _returns=String)
    @authenticated_uid
    @soap_faults
    def get_file (self, uid, builddir, filename, part):
        size = 1024 * 1024 * 5
        pos = size * part
        file_name = builddir + "/" + filename
        file_stat = os.stat (file_name)

        if (pos >= file_stat.st_size):
            return "EndOfFile"

        with file (file_name) as fp:
            if not fp:
                return "FileNotFound"
            try:
                fp.seek (pos)
                data = fp.read (size)
                return binascii.b2a_base64 (data)
            except:
                return "EndOfFile"

    @soapmethod (String, Integer, _returns=String)
    @authenticated_uid
    @soap_faults
    def get_build_chroot_tarball (self, uid, builddir, part):
        from subprocess import Popen, PIPE

        if not hasattr(self, 'tarball_creation_process'):
            setattr(self,'tarball_creation_process', {})

        token=uid

        # One external process per token:
        if token not in self.tarball_creation_process:
            self.tarball_creation_process[token] = None

        # If first part was requested but a tarball process is already
        # running, kill it.
        if self.tarball_creation_process[token] and part == 0:
            self.tarball_creation_process[token].kill()
            self.tarball_creation_process[token].wait()
            self.tarball_creation_process[token] = None

        # If no tarball creation process is currently running,
        # create a new one.
        if not self.tarball_creation_process[token]:
            self.tarball_creation_process[token] = (
                      Popen(["tar", "-cJ",
                             "--exclude=./tmp/*",
                             "--exclude=./dev/*",
                             "--exclude=./run/*",
                             "--exclude=./sys/*",
                             "--exclude=./proc/*",
                             "--exclude=./var/cache/*",
                             "-C", os.path.join(builddir,"chroot"), "."],
                             stdout=PIPE))

        size = 1024 * 1024 * 5

        try:
            data = self.tarball_creation_process[token].stdout.read (size)
            if not data:
                raise Exception()
            return binascii.b2a_base64 (data)
        except:
            self.tarball_creation_process[token].kill()
            self.tarball_creation_process[token].wait()
            self.tarball_creation_process[token] = None
            return "EndOfFile"

    @soapmethod (String)
    @authenticated_uid
    @soap_faults
    def build_sysroot (self, uid, builddir):
        self.pm.open_project (uid, builddir)
        self.pm.build_sysroot (uid)

    @soapmethod (String, Boolean, Boolean)
    @authenticated_uid
    @soap_faults
    def build (self, uid, builddir, build_bin, build_src):
        self.pm.open_project (uid, builddir)
        self.pm.build_current_project (uid, build_bin, build_src)

    @soapmethod (String)
    @authenticated_uid
    @soap_faults
    def build_pbuilder (self, uid, builddir):
        self.pm.open_project (uid, builddir)
        self.pm.build_pbuilder (uid)

    @soapmethod (String, String)
    @authenticated_uid
    @soap_faults
    def set_xml (self, uid, builddir, xml):
        self.pm.open_project (uid, builddir)

        with NamedTemporaryFile() as fp:
            fp.write (binascii.a2b_base64 (xml))
            fp.flush ()
            self.pm.set_current_project_xml (uid, fp.name)

    @soapmethod (String)
    @authenticated_uid
    @soap_faults
    def start_cdrom (self, uid, builddir):
        self.pm.open_project (uid, builddir)

        cdrom_fname = os.path.join (builddir, "uploaded_cdrom.iso")

        # Now write empty File
        fp = open (cdrom_fname, "w")
        fp.close()

    @soapmethod (String, String)
    @authenticated_uid
    @soap_faults
    def append_cdrom (self, uid, builddir, data):
        self.pm.open_project (uid, builddir)

        cdrom_fname = os.path.join (builddir, "uploaded_cdrom.iso")

        # Now append data to cdrom_file
        fp = open (cdrom_fname, "a")
        fp.write (binascii.a2b_base64 (data))
        fp.close()

    @soapmethod (String)
    @authenticated_uid
    @soap_faults
    def finish_cdrom (self, uid, builddir):
        self.pm.open_project (uid, builddir)
        self.pm.set_current_project_upload_cdrom (uid)

    @soapmethod (String)
    @authenticated_uid
    @soap_faults
    def start_pdebuild (self, uid, builddir):
        self.pm.open_project (uid, builddir)

        pdebuild_fname = os.path.join (builddir, "current_pdebuild.tar.gz")

        # Now write empty File
        fp = open (pdebuild_fname, "w")
        fp.close()

    @soapmethod (String, String)
    @authenticated_uid
    @soap_faults
    def append_pdebuild (self, uid, builddir, data):
        self.pm.open_project (uid, builddir)

        pdebuild_fname = os.path.join (builddir, "current_pdebuild.tar.gz")

        # Now write empty File
        fp = open (pdebuild_fname, "a")
        fp.write (binascii.a2b_base64 (data))
        fp.close()

    @soapmethod (String)
    @authenticated_uid
    @soap_faults
    def finish_pdebuild (self, uid, builddir):
        self.pm.open_project (uid, builddir)
        self.pm.build_current_pdebuild (uid)

    @soapmethod (String)
    @authenticated_uid
    @soap_faults
    def reset_project (self, uid, builddir):
        self.pm.db.reset_project (builddir, True)

    @soapmethod (String)
    @authenticated_uid
    @soap_faults
    def del_project (self, uid, builddir):
        self.pm.del_project (uid, builddir)

    @soapmethod (String, _returns=String)
    @authenticated_uid
    @soap_faults
    def create_project (self, uid, xml):
        with NamedTemporaryFile() as fp:
            fp.write (binascii.a2b_base64 (xml))
            fp.flush ()
            prjid = self.pm.create_project (uid, fp.name)

        return prjid

    @soapmethod (String, _returns=Boolean)
    @authenticated_uid
    @soap_faults
    def get_project_busy (self, uid, builddir):
        self.pm.open_project (uid, builddir)

        return self.pm.current_project_is_busy (uid)

    @soapmethod ()
    @authenticated_uid
    @soap_faults
    def shutdown_initvm (self, uid):
        system ("shutdown -h now")