示例#1
0
文件: workloads.py 项目: OhBaby/reef
def saveWorkload(name, content):
    import tempfile
    wkld_dir = os.path.join(
        config.getSettings("global")["projdir"],
        config.getSettings("workloads")["dir"]
    )

    ensureDir(wkld_dir)

    temp_f = tempfile.mkstemp(
        suffix='.wkld',
        prefix='',
        dir=wkld_dir
    )

    try:
        temp = os.fdopen(temp_f[0], 'wb')
        temp.write(content)
    finally:
        temp.close()

    newWorkload = {
        "name" : name,
        "file" : temp_f[1],
        "actors" : []
    }

    if name in config.getSettings("workloads")["defs"]:
        os.remove(config.getSettings("workloads")["defs"][name]["file"])
    config.getSettings("workloads")["defs"][name] = newWorkload
    config.saveConfig()
def restart(mcedit):
    import config
    import mcplatform
    from pygame import display
    from leveleditor import Settings
    if sys.platform == "win32" and Settings.setWindowPlacement.get():
        (flags, showCmd, ptMin, ptMax,
         rect) = mcplatform.win32gui.GetWindowPlacement(
             display.get_wm_info()['window'])
        X, Y, r, b = rect
        #w = r-X
        #h = b-Y
        if (showCmd == mcplatform.win32con.SW_MINIMIZE
                or showCmd == mcplatform.win32con.SW_SHOWMINIMIZED):
            showCmd = mcplatform.win32con.SW_SHOWNORMAL

        Settings.windowX.set(X)
        Settings.windowY.set(Y)
        Settings.windowShowCmd.set(showCmd)

    config.saveConfig()
    mcedit.editor.renderer.discardAllChunks()
    mcedit.editor.deleteAllCopiedSchematics()
    python = sys.executable
    os.execl(python, python, *sys.argv)
示例#3
0
def checkLang():
    if not config.cfg_language == "english":
        ret_lng = (
            fileexists("lang/tvstreamrecord." + config.cfg_language + ".json")
            and fileexists("lang/dataTables." + config.cfg_language + ".json"))
        if not ret_lng:
            config.cfg_language = "english"
            print("Language not found, reverting to default language")
    else:
        ret_lng = True
    if not config.cfg_locale == "default":
        ret_loc = (fileexists("js/i18n/jquery.ui.datepicker-" +
                              config.cfg_locale + ".js")
                   and fileexists("js/i18n/jquery-ui-timepicker-" +
                                  config.cfg_locale + ".js"))
        if not ret_loc:
            config.cfg_locale = "default"
            print("Locale not found, reverting to default locale")
    else:
        ret_loc = True
    ret_style = (fileexists("css/" + config.cfg_theme))
    if not ret_style:
        config.cfg_theme = "smoothness/jquery-ui-1.10.4.custom.min.css"
        print("Theme not found, reverting to default theme")
    if not (ret_loc and ret_lng and ret_style):
        config.saveConfig()
示例#4
0
def saveSueComponent(component_name, component_file):
    import tempfile
    sue_dir = os.path.join(
        config.getSettings("global")["projdir"],
        config.getSettings("SUE")["dir"]
    )

    ensureDir(sue_dir)

    temp_f = tempfile.mkstemp(
        suffix='.tar.gz',
        prefix='',
        dir=sue_dir
    )

    try:
        temp = os.fdopen(temp_f[0], 'wb')
        temp.write(component_file)
    finally:
        temp.close()

    newSueComponent = {
        "name" : component_name,
        "file" : temp_f[1],
    }

    if component_name in config.getSettings("SUE")["defs"]:
        os.remove(config.getSettings("SUE")["defs"][component_name]["file"])
    config.getSettings("SUE")["defs"][component_name] = newSueComponent

    print config.getSettings("SUE")
    config.saveConfig()
示例#5
0
文件: actors.py 项目: OhBaby/reef
def saveActor(name, type, content):
    import tempfile
    actor_dir = os.path.join(
        config.getSettings("global")["projdir"],
        config.getSettings("actors")["dir"]
    )

    ensureDir(actor_dir)

    temp_f = tempfile.mkstemp(
        suffix='.tar.gz',
        prefix='',
        dir=actor_dir
    )

    try:
        temp = os.fdopen(temp_f[0], 'wb')
        temp.write(content)
    finally:
        temp.close()

    newActor = {
        "name" : name,
        "type" : type,
        "file" : temp_f[1]
    }

    if name in config.getSettings("actors")["defs"]:
        os.remove(config.getSettings("actors")["defs"][name]["file"])
    config.getSettings("actors")["defs"][name] = newActor
    config.saveConfig()
示例#6
0
文件: settings.py 项目: OhBaby/reef
    def POST(request, entity):
        authentication.login(request)
        section = getSection(request['PATH_INFO'])
        # Uncomment below to disallow editing of new sections
        #if not section:
        #    raise restlite.Status, '403 New Section Forbidden'

        # Grab arguments
        import urlparse
        parsed = urlparse.parse_qs(entity, True) # Null value is kept as ''
        used_names = [] # Names used
        new_qs = {} # Values to add
        rem_qs = [] # Values to delete

        for key in parsed:
            # Grab name and extension
            name, ext = splitName(key)
            # If name already used, ignore
            if name in used_names:
                continue
            # If theres no extension ignore
            if ext is None:
                continue
            # If there is no value at all, skip
            if parsed[key] == []:
                continue
            # Otherwise take first value
            q = parsed[key][0]
            # If up for deletion
            if ext is 'r':
                # Check used_names here as we use key when deleting
                # Or parsed name otherwise below
                rem_qs += [name]
                used_names += [name]
            # Adding value
            else:
                # Try to convert to the correct format
                func = funcFor(ext)
                if func is None:
                    raise restlite.Status, "400 Invalid Action"
                try:
                    q = func(q)
                except:
                    raise restlite.Status, "400 Invalid Format"
                new_qs[name] = q
                used_names += [name]

        # All settings are good to go
        settings = config.getSettings(section)
        # Add all new settings
        settings.update(new_qs)
        # Delete all new deletions
        for key in rem_qs:
            try:
                del settings[key]
            except KeyError: pass
        # Make it permanent
        config.saveConfig()
        return request.response(settings)
示例#7
0
文件: startup.py 项目: jelford/reef
def finaliseConfig():
    """Save config and ask it to save on any normal exit."""

    config.saveConfig()
    print "Config written to disk"

    # Set automatic save on close
    atexit.register(config.saveConfig)
示例#8
0
 def saveCustomConfig(self):
     file = QtWidgets.QFileDialog.getSaveFileName(
         caption="Save configuration",
         directory=self.lastDir,
         filter="ini (*.ini);;"
         "cfg (*.cfg);;"
         "All files (*)")[0]
     self.lastDir = (os.sep).join(file.split("/")[:-1])
     config.saveConfig(self, file)
示例#9
0
    def POST(request, entity):
        authentication.login(request)

        import urlparse

        args = urlparse.parse_qs(entity, True)

        # Only accept a single value for any parameter
        for key in args:
            if len(args[key]) > 1:
                raise restlite.Status, "400 Duplicate Arguments"
            args[key] = args[key][0]

        # Check for action
        if "do" not in args:
            raise restlite.Status, "400 Missing Action"

        # Check for workload
        if "workload" not in args:
            raise restlite.Status, "400 Missing Workload"

        # Check for actor
        if "actor" not in args:
            raise restlite.Status, "400 Missing Actor"

        do = args["do"].lower()
        workload = args["workload"]
        actor = args["actor"]

        # Validate workload
        if workload not in config.getSettings("workloads")["defs"]:
            raise restlite.Status, "404 Workload Not Found"

        # Validate actor
        if actor not in config.getSettings("actors")["defs"]:
            raise restlite.Status, "404 Actor Not Found (" + actor + ")"

        workload = config.getSettings("workloads")["defs"][workload]

        try:
            {"add": addActor, "rem": remActor}[do](workload, actor)
        except KeyError:
            raise restlite.Status, "400 Invalid Action"

        config.saveConfig()

        return request.response(workload)
示例#10
0
 def __install(self, install):
     pluginTarget = path.join(const.USER_PLUGIN_PATH, install.install.mname)
     pluginSource = path.join(const.PLUGIN_DOWNLOAD_PATH, install.install.mname, const.PLUGIN_MODULE_PATH)
     mconfTarget = path.join(const.USER_PLUGIN_PATH, install.install.mname+".conf")
     uconfSource = path.join(const.PLUGIN_DOWNLOAD_PATH, install.install.mname, const.PLUGIN_USER_CONFIG_FILE)
     uconfTarget = path.join(const.USER_CONF_PATH, install.install.mname+".conf")
     try:
         if path.exists(pluginTarget):
             print "rm ",rmtree(pluginTarget)
         move(pluginSource, pluginTarget)
         if not path.isfile(uconfTarget):
             move(uconfSource, uconfTarget)
         else:
             saveConfig(uconfTarget, self.__updateuconf(uconfSource, uconfTarget))
         saveConfig(mconfTarget, install)
         rmtree(path.join(const.PLUGIN_DOWNLOAD_PATH, install.install.mname))
     except Exception as e:
         raise( piException( e_piPluginInstallFail, e) )
示例#11
0
def copyToNextMonth(scaffold_home, cfg):
    existing_ym = cfg._month
    # make sure there isn't already a folder for the next month
    year, month = datefuncs.parseYM(cfg._month)
    if year == 0 or month == 0:
        print(f"Unable to parse current year-month from config object; bailing")
        return False
    newYear, newMonth = datefuncs.nextMonth(year, month)
    newYM = datefuncs.getYMStr(newYear, newMonth)
    newMonthDir = os.path.join(scaffold_home, f"{newYM}")
    if os.path.exists(newMonthDir):
        print(f"Directory for next month already exists at {newMonthDir}; bailing")
        return False

    # update the config object
    cfg._month = newYM
    cfg._version = 1

    # update the config object's projects and subprojects
    for prj in cfg._projects.values():
        prj.resetNewMonth()

    # create the new directory and save out the config object
    os.makedirs(newMonthDir)
    saveConfig(scaffold_home, cfg)
    print(f"Saved new config file for month {cfg._month}")

    # copy matches files
    existing_matches = glob.glob(os.path.join(scaffold_home, existing_ym, "matches*.json"))
    for em in existing_matches:
        new_filename = os.path.basename(em)
        new_dst = os.path.join(newMonthDir, new_filename)
        shutil.copyfile(em, new_dst)
        print(f"Copied matches file to {new_dst}")

    # copy findings files
    existing_findings = glob.glob(os.path.join(scaffold_home, existing_ym, "findings*.yaml"))
    for em in existing_findings:
        new_filename = os.path.basename(em)
        new_dst = os.path.join(newMonthDir, new_filename)
        shutil.copyfile(em, new_dst)
        print(f"Copied findings file to {new_dst}")

    return True
示例#12
0
文件: actors.py 项目: jelford/reef
    def saveActor(self, name, type, content):
        """
        Save an actor to a new file and add to defs in the :mod:`config`.

        :param name: Name of the actor to add.
        :type name: ``str``
        :param type: Type of the actor to add. This is expected to be in
                     :data:`ALLOWED_TYPES`.
        :type type: ``str``

        """

        import tempfile
        actor_dir = os.path.join(
            config.getSettings("global")["projdir"],
            config.getSettings("actors")["dir"]
        )

        self.ensureDir(actor_dir)

        temp_f = tempfile.mkstemp(
            suffix='.tar.gz',
            prefix='',
            dir=actor_dir
        )

        try:
            temp = os.fdopen(temp_f[0], 'wb')
            temp.write(content)
        finally:
            temp.close()

        newActor = {
            "name" : name,
            "type" : type,
            "file" : temp_f[1]
        }

        if name in config.getSettings("actors")["defs"]:
            os.remove(config.getSettings("actors")["defs"][name]["file"])
        config.getSettings("actors")["defs"][name] = newActor
        config.saveConfig()
示例#13
0
文件: workloads.py 项目: jelford/reef
def saveWorkload(name, content):
    """
    Save a workload to a new file and add it to the naming list.

    :param name: The name of the workload to save.
    :type name: ``str``
    :param content: The content to place in the workload file.
    :type content: ``str``

    """

    import tempfile
    wkld_dir = os.path.join(
        config.getSettings("global")["projdir"],
        config.getSettings("workloads")["dir"]
    )

    ensureDir(wkld_dir)

    temp_f = tempfile.mkstemp(
        suffix='.wkld',
        prefix='',
        dir=wkld_dir
    )

    try:
        temp = os.fdopen(temp_f[0], 'wb')
        temp.write(content)
    finally:
        temp.close()

    newWorkload = {
        "name" : name,
        "file" : temp_f[1],
        "actors" : []
    }

    if name in config.getSettings("workloads")["defs"]:
        os.remove(config.getSettings("workloads")["defs"][name]["file"])
    config.getSettings("workloads")["defs"][name] = newWorkload
    config.saveConfig()
示例#14
0
def checkLang():
    if not config.cfg_language == "english":
        ret_lng = ( fileexists("lang/tvstreamrecord." + config.cfg_language + ".json") and fileexists("lang/dataTables." + config.cfg_language + ".json") )
        if not ret_lng:
            config.cfg_language = "english"
            print ("Language not found, reverting to default language")
    else:
        ret_lng = True
    if not config.cfg_locale == "default":
        ret_loc = ( fileexists("js/i18n/jquery.ui.datepicker-" + config.cfg_locale + ".js") and fileexists("js/i18n/jquery-ui-timepicker-" + config.cfg_locale + ".js" ) )
        if not ret_loc:
            config.cfg_locale = "default"
            print ("Locale not found, reverting to default locale")
    else:
        ret_loc = True
    ret_style = ( fileexists("css/" + config.cfg_theme) )
    if not ret_style:
        config.cfg_theme = "smoothness/jquery-ui-1.10.4.custom.min.css"
        print ("Theme not found, reverting to default theme")
    if not (ret_loc and ret_lng and ret_style):
        config.saveConfig()
示例#15
0
def restart(mcedit):
    import config
    import mcplatform
    from pygame import display
    from leveleditor import Settings
    if sys.platform == "win32" and Settings.setWindowPlacement.get():
        (flags, showCmd, ptMin, ptMax, rect) = mcplatform.win32gui.GetWindowPlacement(
            display.get_wm_info()['window'])
        X, Y, r, b = rect
        #w = r-X
        #h = b-Y
        if (showCmd == mcplatform.win32con.SW_MINIMIZE or
                    showCmd == mcplatform.win32con.SW_SHOWMINIMIZED):
            showCmd = mcplatform.win32con.SW_SHOWNORMAL

        Settings.windowX.set(X)
        Settings.windowY.set(Y)
        Settings.windowShowCmd.set(showCmd)

    config.saveConfig()
    mcedit.editor.renderer.discardAllChunks()
    mcedit.editor.deleteAllCopiedSchematics()
    python = sys.executable
    os.execl(python, python, * sys.argv)
    def __init__(self):
        #
        QtGui.QDialog.__init__(self)
        self.setupUi(self)
        self.i18n()
        if os.path.isfile(const.EVIRE_CONF):
            self.conf = loadConfig(const.EVIRE_CONF)
            if not self.conf:
                QMessage(self.msg["m_loadFail"], QtGui.QMessageBox.Critical, False, False, const.EVIRE_CONF)
            else:
                self.__update()
        else:
            self.__setDefaults()
            if not saveConfig(const.EVIRE_CONF, self.conf):
                QMessage(self.msg["m_saveFail"], QtGui.QMessageBox.Critical, False, False, const.EVIRE_CONF)


        QtCore.QObject.connect(self.pluginIndexEdit,  QtCore.SIGNAL("textChanged ()"),  self.on_changed)
示例#17
0
def zoom_p():
    zoom = request.forms.zoom
    config.cfg_grab_zoom = zoom
    config.saveConfig()
    return "null"
示例#18
0
def doNextThingForProject(scaffold_home, cfg, fdServer, prj, sp_only):
    # if GitHub project, go to subprojects
    if prj._repotype == ProjectRepoType.GITHUB:
        did_something = False
        for sp in prj._subprojects.values():
            if sp_only == "" or sp_only == sp._name:
                retval = True
                while retval:
                    retval = doNextThingForSubproject(scaffold_home, cfg,
                                                      fdServer, prj, sp)
                    updateProjectPostSubproject(cfg, prj)
                    saveConfig(scaffold_home, cfg)
                    if retval:
                        did_something = True
        return did_something

    # if GITHUB_SHARED project, check state to decide when to go to subprojects
    elif prj._repotype == ProjectRepoType.GITHUB_SHARED:
        did_something = False
        retval_prj = True
        while retval_prj:
            if prj._status == Status.START:
                # get repo listing at project level and see if we're good
                retval_prj = doRepoListingForProject(cfg, prj)
                saveConfig(scaffold_home, cfg)
                if retval_prj:
                    did_something = True
            # elif prj._status == Status.GOTCODE:
            #     # upload code to Fossology server
            #     retval_prj = doUploadCodeForProject(cfg, fdServer, prj)
            #     updateProjectStatusToSubprojectMin(cfg, prj)
            #     saveConfig(scaffold_home, cfg)
            #     if retval_prj:
            #         did_something = True
            else:
                retval_sp_all = False
                for sp in prj._subprojects.values():
                    if sp_only == "" or sp_only == sp._name:
                        retval = True
                        while retval:
                            retval = doNextThingForSubproject(
                                scaffold_home, cfg, fdServer, prj, sp)
                            updateProjectPostSubproject(cfg, prj)
                            saveConfig(scaffold_home, cfg)
                            if retval:
                                did_something = True
                                retval_sp_all = True
                if not retval_sp_all:
                    break
        return did_something

    elif prj._repotype == ProjectRepoType.GERRIT:
        did_something = False
        retval_prj = True
        while retval_prj:
            if prj._status == Status.START:
                # get repo listing at project level and see if we're good
                retval_prj = doRepoListingForGerritProject(cfg, prj)
                updateProjectStatusToSubprojectMin(cfg, prj)
                saveConfig(scaffold_home, cfg)
                if retval_prj:
                    did_something = True
            # elif prj._status == Status.GOTCODE:
            #     # upload code to Fossology server
            #     retval_prj = doUploadCodeForProject(cfg, fdServer, prj)
            #     updateProjectStatusToSubprojectMin(cfg, prj)
            #     saveConfig(scaffold_home, cfg)
            #     if retval_prj:
            #         did_something = True
            else:
                retval_sp_all = False
                for sp in prj._subprojects.values():
                    if sp_only == "" or sp_only == sp._name:
                        retval = True
                        while retval:
                            retval = doNextThingForGerritSubproject(
                                scaffold_home, cfg, fdServer, prj, sp)
                            updateProjectPostSubproject(cfg, prj)
                            saveConfig(scaffold_home, cfg)
                            if retval:
                                did_something = True
                                retval_sp_all = True
                if not retval_sp_all:
                    break
        return did_something

    else:
        print(f"Invalid project repotype for {prj._name}: {prj._repotype}")
        return False
示例#19
0
            caption="Select configuration to load",
            directory=self.lastDir,
            filter="BDL config files (*.ini);;"
            "Other config files (*.bdl *.cfg);;"
            "All files (*)")[0]
        try:
            self.lastDir = (os.sep).join(file.split("/")[:-1])
        except:
            pass
        config.loadConfig(self, file)

    def openAboutDialog(self):
        aboutDialog = QtWidgets.QDialog()
        aboutDialog.setWindowModality(1)
        aboutUi = window_about.Ui_aboutDialog()
        aboutUi.setupUi(aboutDialog)
        aboutDialog.exec()

bdl = BDLInstance()  # create empty bdl instance

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    BDLMainWindow = QtWidgets.QMainWindow()
    ui = window_main.Ui_BDLMainWindow()
    ui.setupUi(BDLMainWindow)
    bdl.setupBDL(ui, BDLMainWindow)  # setup bdl instance
    BDLMainWindow.show()
    response = app.exec_()
    config.saveConfig(bdl)  # save config on exit
    sys.exit(response)
示例#20
0
文件: settings.py 项目: jelford/reef
    def POST(self, request, entity):
        """
        Update a section of the settings.

        Any part of the requested address after the handler's base address will
        be taken as a section name inside the settings. Any parameters are
        assumed to be in the POST entity and url encoded.

        A request can take any number of the following parameters:

        To set a setting:

        :param <setname>_<type>: The value to set this setting to.

        where ``<type>`` is one of:

        * ``"s"`` for string
        * ``"i"`` for integer
        * ``"d"`` for double

        and ``<setname>`` is the name of the setting to set.

        To remove a setting:

        :param <setname>_r: No value

        Only the first occurence of each ``<setname>`` is observed.

        :returns: JSON representation of the settings section.
        :rtype: ``json``
        :raises: :exc:`restlite.Status` 400 if there is a parameter with an
                 invalid action in the name (the bit after the ``"_"``).

                 :exc:`restlite.Status` 400 if the value of a parameter cannot
                 be parsed with the type given.

        """

        authentication.login(request)
        section = getSection(request['PATH_INFO'])
        # Uncomment below to disallow editing of new sections
        #if not section:
        #    raise restlite.Status, '403 New Section Forbidden'

        # Grab arguments
        import urlparse
        parsed = urlparse.parse_qs(entity, True) # Null value is kept as ''
        used_names = [] # Names used
        new_qs = {} # Values to add
        rem_qs = [] # Values to delete

        for key in parsed:
            # Grab name and extension
            name, ext = splitName(key)
            # If name already used, ignore
            if name in used_names:
                continue
            # If theres no extension ignore
            if ext is None:
                continue
            # If there is no value at all, skip
            if parsed[key] == []:
                continue
            # Otherwise take first value
            q = parsed[key][0]
            # If up for deletion
            if ext is 'r':
                # Check used_names here as we use key when deleting
                # Or parsed name otherwise below
                rem_qs += [name]
                used_names += [name]
            # Adding value
            else:
                # Try to convert to the correct format
                func = funcFor(ext)
                if func is None:
                    raise restlite.Status, "400 Invalid Action"
                try:
                    q = func(q)
                except:
                    raise restlite.Status, "400 Invalid Format"
                new_qs[name] = q
                used_names += [name]

        # All settings are good to go
        settings = config.getSettings(section)
        # Add all new settings
        settings.update(new_qs)
        # Delete all new deletions
        for key in rem_qs:
            try:
                del settings[key]
            except KeyError: pass
        # Make it permanent
        config.saveConfig()
        return request.response(settings)
示例#21
0
def zoom_p():
    zoom = request.forms.zoom
    config.cfg_grab_zoom = zoom
    config.saveConfig()
    return "null"
示例#22
0
 def save(self):
     return(saveConfig(os.path.join(const.USER_CONF_PATH, self.mconf.install.mname+".conf"), self.conf))
示例#23
0
            ran_command = True
            saveBackupConfig(SCAFFOLD_HOME, cfg)

            # set up fossdriver server connection
            fossdriverrc_path = os.path.join(str(Path.home()), ".fossdriver",
                                             "fossdriverrc.json")
            fdServer = fossdriverSetup(fossdriverrc_path)
            if not fdServer:
                print(f"Unable to connect to Fossology server with fossdriver")
                sys.exit(1)

            # run commands
            doNextThing(SCAFFOLD_HOME, cfg, fdServer, prj_only, sp_only)

            # save modified config file
            saveConfig(SCAFFOLD_HOME, cfg)

        elif command == "ws":
            ran_command = True
            if prj_only == "" or sp_only == "":
                print(f"ws command requires specifying project and subproject")
                sys.exit(1)

            # run WS agent manually if between ZIPPEDCODE and CLEARED state
            # does not modify the config file
            runManualWSAgent(cfg, prj_only, sp_only)

        elif command == "clear":
            ran_command = True
            saveBackupConfig(SCAFFOLD_HOME, cfg)
 def on_saveButton_clicked(self):
     self.conf.plugins.indexurls = unicode(self.pluginIndexEdit.toPlainText()).splitlines()
     if not saveConfig(const.EVIRE_CONF, self.conf):
         QMessage(self.msg["m_saveFail"], QtGui.QMessageBox.Critical, False, False, const.EVIRE_CONF)
     else:
         self.saveButton.setEnabled(False)
示例#25
0
 def done(self):
     self.changesNum = 0
     self.changes = {}
     config.saveConfig()
     self.dismiss()
示例#26
0
文件: startup.py 项目: OhBaby/reef
myserver.getServer().setup()

print "Now you can log on to the server with the following credentials:"
print ""
print "Location: http://localhost:" + str(config.getSettings("server")["port"])
if authentication.active():
    print "User: "******"Password: <You should know>"
print ""
print "If I displayed the password back to you then the small amount of security during the input would be wasted."
print "(You can just read it in the config file though, that's a problem.)"

show_break()

config.saveConfig()
print "Config written to disk"

# Set automatic save on close
atexit.register(config.saveConfig)

show_break()

print "Starting server...press CTRL+C to stop."

# This lets the server be stopped with CTRL+C
# As it runs to finish, exit handlers are called
try:
    myserver.getServer().start()
except KeyboardInterrupt: pass
示例#27
0
    def POST(self, request, entity):
        """
        (Un)assign actors (from/)to workloads.

        The parameters listed are part of the url encoded ``entity``.

        :param do: What to do, either ``"add"`` or ``"rem"`` to add or remove
                   respectively
        :param workload: The name of the workload to affect.
        :param actor: The name of the actor to add or remove.
        :raises: :exc:`restlite.Status` 400 if a parameter is given multiple
                 times.

                 :exc:`restlite.Status` 400 if a parameter is missing.

                 :exc:`restlite.Status` 404 if the actor or workload does
                 not exist.

                 :exc:`restlite.Status` 400 if the action (``do``) is invalid.

                 :exc:`restlite.Status` 409 if the action cannot be completed
                 do to the state of currently attached workloads.
        :returns: The JSON representation of the workload.

        """

        authentication.login(request)

        import urlparse
        args = urlparse.parse_qs(entity, True)

        # Only accept a single value for any parameter
        for key in args:
            if len(args[key]) > 1:
                raise restlite.Status, "400 Duplicate Arguments"
            args[key] = args[key][0]

        # Check for action
        if "do" not in args:
            raise restlite.Status, "400 Missing Action"

        # Check for workload
        if "workload" not in args:
            raise restlite.Status, "400 Missing Workload"

        # Check for actor
        if "actor" not in args:
            raise restlite.Status, "400 Missing Actor"

        do = args["do"].lower()
        workload = args["workload"]
        actor = args["actor"]

        # Validate workload
        if workload not in config.getSettings("workloads")["defs"]:
            raise restlite.Status, "404 Workload Not Found"

        # Validate actor
        if actor not in config.getSettings("actors")["defs"]:
            raise restlite.Status, "404 Actor Not Found (" +actor+ ")"

        workload = config.getSettings("workloads")["defs"][workload]

        try:
            {
                "add" : self.addActor,
                "rem" : self.remActor,
            }[do](workload, actor)
        except KeyError:
            raise restlite.Status, "400 Invalid Action"            

        config.saveConfig()

        return request.response(workload)