Пример #1
0
    def testStoring(self):
        c1 = conf.Conf('salseeg')
        servers = c1.servers
        interval = c1.refreshInterval
        c1.write()

        c2 = conf.Conf('salseeg')
        self.assertEqual(interval, c2.refreshInterval)
        self.assertEqual(servers, c2.servers)
Пример #2
0
    def __init__(self):
        path = os.path.expanduser('~')
        # print path;
        p, user = os.path.split(path)
        # print "user = {}\n".format(user);
        self.needToRebuildMenu = True
        self.user = user
        self.conf = conf.Conf(self.user)
        self.daemon = None
        self.start_deamon()

        self.icons = IconCache()
        # self.ind = appindicator.Indicator("ping-indicator-applet", LOGO, appindicator.CATEGORY_APPLICATION_STATUS)
        self.ind = appindicator.Indicator("ping-indicator-applet", LOGO,
                                          appindicator.CATEGORY_COMMUNICATIONS)
        self.ind.set_status(appindicator.STATUS_ACTIVE)
        self.menu = gtk.Menu()
        sep = gtk.SeparatorMenuItem()
        pref_item = gtk.MenuItem()
        pref_item.add(gtk.Label("Preferences"))
        pref_item.connect("activate", self.show_prefs)
        item = gtk.MenuItem()
        item.add(gtk.Label("exit"))
        item.connect("activate", self.exit)

        self.menu.append(sep)
        self.menu.append(pref_item)
        self.menu.append(item)
        self.menu.show_all()
        self.ind.set_menu(self.menu)
        self.gtkTimer = gtk.timeout_add(UPDATE_TIMEOUT, self.update)
Пример #3
0
    def __init__(self):
        # Threading HTTP-Server
        self.conf = conf.Conf('wiera.conf')

        local_server_manager_port = self.conf.get('local_server_port')
        local_server_manager_ping_interval = self.conf.get('ping_interval')
        applications_port = self.conf.get('applications_port')

        #LocalServerList #not instance
        self.local_server_manager = localServerManager.LocalServerManager(
            local_server_manager_port, local_server_manager_ping_interval)

        #web server
        #		self.web_server = wieraWebUserInterface.WieraWebUserInterface(self, 8080)

        #policy manager
        self.policy_manager = policyManager.PolicyManager()
        self.request_lock = threading.Lock()

        if self.conf.get('ui_command') == True:
            self.user_input_thread = threading.Thread(target=self._ui_handler)
            self.user_input_thread.daemon = True
            self.user_input_thread.start()

        #web server

        #Thrift server
        self.applications_server = threading.Thread(
            target=self._run_applications_server, args=([
                applications_port,
            ]))
        self.applications_server.daemon = True
        self.applications_server.start()
Пример #4
0
class GoogleMap:

    obj_conf = conf.Conf()

    def __init__(self):
        return

    def check_compound_code(self, lat, lng, compound_code):
        # 为啥写这个方法……因为维基百科给出的东京坐标太大了……7700万个点超过了5G存储的限制

        ## 检查是否在范围内并输出样例代码
        # curr_latlon = TiteLation.tile2latlon(self.x, y, self.obj_conf.zoom)
        # next_latlon = TiteLation.tile2latlon(self.x + 1, y + 1, self.obj_conf.zoom)
        # if False is self.obj_googlemap.check_compound_code(curr_latlon['lat'], curr_latlon['lon'], 'Tokyo, Japan') \
        #   and False is self.obj_googlemap.check_compound_code(next_latlon['lat'], next_latlon['lon'], 'Tokyo, Japan'):
        #   continue
        #   # 输出东京范围内的数据
        # print(self.x, y)
        # continue

        s = requests.Session()
        s.mount('https://', HTTPAdapter(max_retries=10))
        ret = (s.get(self.obj_conf.googleMapTileCheckApi.format(
            lat, lng, self.obj_conf.googleMapKey),
                     timeout=(3.05, 27)))
        return -1 is not str(
            ret.json()['plus_code']['compound_code']).find(compound_code)
Пример #5
0
    def _get_advmenu(self):
        items = []
        if conf.Conf().networking:
            items.append(("Networking", "Configure appliance networking"))

        if self.installer.available:
            items.append(("Install", "Install to hard disk"))

        plugin_map = {}

        for path in self.pluginManager.path_map:
            plug = self.pluginManager.path_map[path]
            if os.path.dirname(path) == PLUGIN_PATH:
                if isinstance(plug, plugin.Plugin) and hasattr(
                        plug.module, 'run'):
                    items.append((plug.module_name.capitalize(),
                                  str(plug.module.__doc__)))
                elif isinstance(plug, plugin.PluginDir):
                    items.append(
                        (plug.module_name.capitalize(), plug.description))
                plugin_map[plug.module_name.capitalize()] = plug

        items.append(("Reboot", "Reboot the appliance"))
        items.append(("Shutdown", "Shutdown the appliance"))
        items.append(("Quit", "Quit the configuration console"))

        return items, plugin_map
Пример #6
0
 def _get_public_ipaddr(cls):
     publicip_cmd = conf.Conf().publicip_cmd
     if publicip_cmd:
         try:
             return executil.getoutput(publicip_cmd)
         except executil.ExecError, e:
             pass
Пример #7
0
def main(args):
    #example for running code: python main.py -jid test -confFile ./data/default_scan_only.conf
    print "main.py::main()"
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "-jid", "--jid", help="enter job ID"
    )  #job id to make a folder to store all the data for a specific job
    parser.add_argument(
        "-confFile", "--confFile",
        help="enter the configuration file")  #path to configuration file
    args = parser.parse_args()
    print 'jobId:', args.jid, 'configfile:', args.confFile

    #make a results directory to store job results
    resultsDirName = args.jid
    os.makedirs(resultsDirName)

    #make a file list to store all the files to be moved to the results folder
    fileList = []

    #copy the config file
    cpConfFileName = args.jid + '_in_conf_file'
    cpConfFile = open(cpConfFileName, 'wb')
    with open(args.confFile, 'rb') as handler:
        for line in handler:
            cpConfFile.write(line)
    cpConfFile.close()
    fileList.append(cpConfFileName)

    #make a config object
    confObj = conf.Conf()
    confDict = confObj.read(args.confFile)

    ############
    #Have a PWM file and want to scan it across a fasta file and then apply sequence coverage
    ############
    if confDict['job.type']['type'] == 'motifPwmScanCov':
        print 'motif_pwm scanning and coverage operation'
        motif_pwm_scan_cov.callMotifPwmScanCov(args, confDict, fileList)
        #move files to results folder
        for outFile in fileList:
            shutil.move(outFile, resultsDirName)
        exit()

    ############
    #Have a PWM file and want to scan it across a file only
    ############
    if confDict['job.type']['type'] == 'pwmScan':
        print 'motif pwm scanning only'
        motif_pwm_scan_only.callMotifPwmScanOnly(args, confDict, fileList)
        #move files to results folder
        for outFile in fileList:
            shutil.move(outFile, resultsDirName)
        exit()

    ###############
    #EXIT
    ###############
    exit()
Пример #8
0
    def _get_public_ipaddr(cls):
        publicip_cmd = conf.Conf().publicip_cmd
        if publicip_cmd:
            command = subprocess.run(publicip_cmd, stdout=PIPE)
            if command.returncode == 0:
                return command.stdout

        return None
Пример #9
0
    def _get_public_ipaddr(cls):
        publicip_cmd = conf.Conf().publicip_cmd
        if publicip_cmd:
            command = subprocess.run(shlex.split(publicip_cmd),
                                     stdout=PIPE,
                                     encoding='utf-8')
            if command.returncode == 0:
                return command.stdout.strip()

        return None
Пример #10
0
 def __init__(self, conf_dir, db_conf=dict(), check_conf_change=False, debug=False):
     self._conf_dir = conf_dir
     self._db_conf = dict()
     self._db_conf.update(db_conf)
     self._check_conf_change = check_conf_change
     self._debug = debug
     self._title_pat = re.compile(ur'<title>(.+?)</title>', flags=re.IGNORECASE)
     self._conf = conf.Conf(self._conf_dir, 'page_judge.conf', 'asyn_judge.conf')
     self._conn = None
     self.db_conn()
Пример #11
0
 def file_new_cb(self, action):
     """Start new file of config data"""
     if self.check_dirty():
         return
     self.tree_model.clear()
     self.has_data = False
     self.dirty = False
     self.filename = ""
     self.config_data = conf.Conf()
     self.config_data.setup_defaults()
def lint_files(paths, lint_error, conf=conf.Conf(), printpaths=True):
    def lint_file(path, kind, jsversion):
        def import_script(import_path, jsversion):
            # The user can specify paths using backslashes (such as when
            # linting Windows scripts on a posix environment.
            import_path = import_path.replace('\\', os.sep)
            import_path = os.path.join(os.path.dirname(path), import_path)
            return lint_file(import_path, 'js', jsversion)

        def _lint_error(*args):
            return lint_error(normpath, *args)

        normpath = fs.normpath(path)
        if normpath in lint_cache:
            return lint_cache[normpath]
        if printpaths:
            print normpath
        contents = fs.readfile(path)
        lint_cache[normpath] = _Script()

        script_parts = []
        if kind == 'js':
            script_parts.append((None, jsversion
                                 or conf['default-version'], contents))
        elif kind == 'html':
            assert jsversion is None
            for script in _findhtmlscripts(contents, conf['default-version']):
                # TODO: Warn about foreign languages.
                if not script['jsversion']:
                    continue

                if script['type'] == 'external':
                    other = import_script(script['src'], script['jsversion'])
                    lint_cache[normpath].importscript(other)
                elif script['type'] == 'inline':
                    script_parts.append((script['pos'], script['jsversion'],
                                         script['contents']))
                else:
                    assert False, 'Invalid internal script type %s' % \
                                  script['type']
        else:
            assert False, 'Unsupported file kind: %s' % kind

        _lint_script_parts(script_parts, lint_cache[normpath], _lint_error,
                           conf, import_script)
        return lint_cache[normpath]

    lint_cache = {}
    for path in paths:
        ext = os.path.splitext(path)[1]
        if ext.lower() in ['.htm', '.html']:
            lint_file(path, 'html', None)
        else:
            lint_file(path, 'js', None)
Пример #13
0
    def __init__(self, filename=""):
        gtk.Window.__init__(self)
        self.set_position(gtk.WIN_POS_CENTER)
        self.set_title('Setup CUPSPY printers')
        self.connect('delete-event', self.delete_event_cb)
        self.set_size_request(550, 200)
        vbox = gtk.VBox()
        self.add(vbox)

        self.create_ui()
        vbox.pack_start(self.ui.get_widget('/Menubar'), expand=False)
        vbox.pack_start(self.ui.get_widget('/Toolbar'), expand=False)

        sw = gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        vbox.pack_start(sw)

        self.tree_model = gtk.ListStore(gobject.TYPE_BOOLEAN,
                                        gobject.TYPE_STRING,
                                        gobject.TYPE_STRING)
        self.tree_model.connect('row-inserted', inserted_cb, self)
        self.tree_model.connect('row-deleted', deleted_cb, self)
        self.tree_view = gtk.TreeView(self.tree_model)
        self.tree_view.set_reorderable(True)
        self.tree_view.connect('row-activated', activated_cb, self)
        rend = gtk.CellRendererToggle()
        col = self.tree_view.insert_column_with_attributes(-1,
                                                           "Default",
                                                           rend,
                                                           active=0)
        col.set_resizable(True)
        rend = gtk.CellRendererText()
        col = self.tree_view.insert_column_with_attributes(-1,
                                                           "Name",
                                                           rend,
                                                           text=1)
        col.set_resizable(True)
        rend = gtk.CellRendererText()
        col = self.tree_view.insert_column_with_attributes(-1,
                                                           "Description",
                                                           rend,
                                                           text=2)
        col.set_resizable(True)
        sw.add(self.tree_view)
        status = gtk.Statusbar()
        vbox.pack_end(status, expand=False)
        self.dirty = False
        self.has_data = False
        self.filename = ""
        self.config_data = conf.Conf()
        if len(filename) != 0:
            self.load_file(filename)
        else:
            self.config_data.setup_defaults()
Пример #14
0
 def __init__(self):
     confFilePath = os.path.dirname(__file__) + "/gapp.ini"
     self.conf = conf.Conf(confFilePath)
     if len(sys.argv) > 1:
         if sys.argv[1] == 'stop':
             self.stop()
         elif sys.argv[1] == 'restart':
             self.restart()
         else:
             self.start()
     else:
         self.start()
Пример #15
0
    def __init__(self, title=None, width=60, height=20):
        self.width = width
        self.height = height

        self.console = dialog.Dialog(dialog="dialog")
        self.console.add_persistent_args(["--no-collapse"])
        self.console.add_persistent_args(["--ok-label", "Select"])
        self.console.add_persistent_args(["--cancel-label", "Back"])
        self.console.add_persistent_args(["--colors"])
        if conf.Conf().copy_paste:
            self.console.add_persistent_args(["--no-mouse"])
        if title:
            self.console.add_persistent_args(["--backtitle", title])
Пример #16
0
    def apply_prefs(self, obj):
        buf = self.pref_tree.get_widget("hosts__textview").get_buffer()
        text = buf.get_text(buf.get_start_iter(), buf.get_end_iter())
        scale = self.pref_tree.get_widget("interval__hscale")

        c = conf.Conf(self.user)
        c.set_servers(text)
        c.refreshInterval = int(scale.get_value())
        c.write()

        self.restart_timer(c.refreshInterval)
        self.restart_deamon()

        self.close_prefs(obj)
        self.needToRebuildMenu = True
Пример #17
0
 def conf(self):
     cw = conf.Conf(self.path, self.solver)
     try:
         self.solver = cw.solver
         try:
             f = open(self.path + "/settings/solver", "w")
             f.writelines([
                 self.solver[0] + "\n", self.solver[1] + "\n",
                 self.solver[2]
             ])
             f.close()
         except IsADirectoryError:
             pass
     except AttributeError:
         pass
Пример #18
0
    def _get_default_nic(cls):
        def _validip(ifname):
            ip = ifutil.get_ipconf(ifname)[0]
            if ip and not ip.startswith('169'):
                return True
            return False

        ifname = conf.Conf().default_nic
        if ifname and _validip(ifname):
            return ifname

        for ifname in cls._get_filtered_ifnames():
            if _validip(ifname):
                return ifname

        return None
Пример #19
0
    def _get_filtered_ifnames():
        ifnames = []
        for ifname in netinfo.get_ifnames():
            if ifname.startswith(('lo', 'tap', 'br', 'natbr', 'tun', 'vmnet', 'veth', 'wmaster')):
                continue
            ifnames.append(ifname)

        # handle bridged LXC where br0 is the default outward-facing interface
        defifname = conf.Conf().default_nic
        if defifname and defifname.startswith('br'):
                ifnames.append(defifname)
                bridgedif = executil.getoutput('brctl', 'show', defifname).split('\n')[1].split('\t')[-1]
                ifnames.remove(bridgedif)

        ifnames.sort()
        return ifnames
Пример #20
0
class OpenSearch:

    obj_conf = conf.Conf()
    client = Client(obj_conf.opensearchAccessKeyId,
                    obj_conf.opensearchAccessKeySecret, obj_conf.opensearchAPI)
    index_doc = IndexDoc(client, obj_conf.opensearchAppId)

    def __init__(self):
        return

    def insert(self, parsed_cyber_data):
        # 解析数据
        parsed_items = self.parse(parsed_cyber_data)

        for item in parsed_items:
            # 插入表
            self.index_doc.add(item, self.obj_conf.opensearchTable)
        return

    def parse(self, parsed_cyber_data):
        parsed_items = []
        for i in range(0, self.obj_conf.shard):
            for j in range(0, self.obj_conf.shard):
                loc = str(parsed_cyber_data[i][j]["lon"]) + " " + str(
                    parsed_cyber_data[i][j]["lat"])
                parsed_items.append({
                    "id":
                    loc,
                    "loc":
                    loc,
                    "elevation":
                    int(float(parsed_cyber_data[i][j]["elevation"]) * 100),
                })
        return parsed_items

    def insertDrain(self, points):
        for k in points:
            data = points[k]
            item = {
                "id": str(data['lng']) + " " + str(data['lat']),
                "loc": str(data['lng']) + " " + str(data['lat']),
                "total": data['total'],
                "name": data['name']
            }
            print(self.index_doc.add(item, self.obj_conf.opensearchTable))
        return
Пример #21
0
    def init(self, args):
        logger.info("action: init")

        path = (Path(args.path) if args.path else Path())
        path = path.expanduser().resolve().joinpath("autorerename.conf.ini")

        if path.exists():
            print("It already exists.")
            return EXIT_ERROR

        cf = conf.Conf()
        cf.path = path

        cf.rule_db_path.parent.mkdir(parents=True, exist_ok=True)
        cf.actlog_path.parent.mkdir(parents=True, exist_ok=True)

        conf.save_conf(cf)
        print("Create repositiory at {}".format(cf.path))
Пример #22
0
class Basic:

    obj_conf = conf.Conf()

    def __init__(self):
        return

    @classmethod
    def get_elevation(self, loc_lat, loc_lng):
        req = None
        while req is None:
            try:
                req = requests.get(
                    self.obj_conf.googleMapElevationApi.format(
                        loc_lat, loc_lng, self.obj_conf.googleMapKey))
            except:
                print("Except")
        req_json = req.json()
        return req_json['results'][0]
Пример #23
0
def execute(cmd):
    '''用命令提示符执行命令

    Args:
        cmd: 执行的命令

    Returns:
        执行的结果
    '''

    import conf
    result = ''
    p = subprocess.Popen(cmd,
                         shell=True,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.STDOUT)
    for line in p.stdout.readlines():
        result += line.decode(conf.Conf().get('encoding'))
    return result
Пример #24
0
    def get_suggestions(self, term, maxitems, ranked, checked):
        """ queries sphinx indexer and returns the labels that start with - prefix (or containing - infix) the incomming term """
        """ or False and a (errorcode,error str) tuple """

        # here we ignore maxitems, but term must be present
        if term == None or term == '':
            result = [
            ]  # NOTE: here on error we return empty list - error messages have no meaning here
        else:
            # transform search term for search
            term = term.decode("utf_8")  # convert to unicode
            # connect to DB according to conf.txt
            confobj = conf.Conf()
            params = json.loads(confobj.provideConfParams())
            conn = ast.literal_eval(params['connectionstring'])
            db = MySQLdb.connect(**conn)
            cursor = db.cursor()
            if ranked == 'true':  #do some ranking to results according  to their backlinks
                print "checked:" + checked
                if (checked == '0'):
                    sqlcmd = "SELECT label FROM autosuggest WHERE MATCH(%s) order by howmanyurid desc, apuricount desc limit 0, 2"
                else:
                    sqlcmd = "SELECT label FROM autosuggest WHERE MATCH(%s) and nodeindex=" + checked + "order by howmanyurid desc, apuricount desc limit 0, 2"
            else:
                if (checked == '0'):
                    sqlcmd = "SELECT label FROM alphabetical WHERE MATCH(%s) order by label asc limit 0, 150"
                else:
                    sqlcmd = "SELECT label FROM alphabetical WHERE MATCH(%s) and nodeindex=" + checked + "order by label asc limit 0, 150"
            """replace  error prone chars /,(,)," """
            term = term.replace('(', '\(')
            term = term.replace(')', '\)')
            term = term.replace('"', '\"')
            term = term.replace('/', '\/')
            cursor.execute(sqlcmd, ('*' + term + '*'))
            result = list(cursor.fetchall())
            print "result: ", result
            db.close()
        # as we don't have anything else to do here, we return a succeded defer
        sucdefer = defer.succeed(
            result)  # result will be passed to any callback attached
        # return the defered
        return sucdefer
Пример #25
0
 def __init__( self ):
     self.qapp = None
     self.qtui = None
     self.jobs = {}
     self.threadQueue = queue.Queue()
     self.hotkeyQueue = queue.Queue()
     self.conf = conf.Conf()
     
     self.activeOnHeard = True
     
     
     
     self.kb = Controller()
     
     ## *** all this keyboard stuff should go in a submodule later...
     self.kbListener = pynput.keyboard.Listener(
         on_press=self.kbListenerOnRelease,
         on_release=self.kbListenerOnRelease,    
     )
     self.kbListener.start()
Пример #26
0
    def show_prefs(self, obj):
        self.pref_tree = gtk.glade.XML(UI_DIR + "conf.glade", "dialog1")
        window = self.pref_tree.get_widget("dialog1")
        # window.connect("delete_event", gtk.main_quit)
        c = conf.Conf(self.user)
        data_file = data_exch.Data_Exch(self.user)
        data = data_file.read()
        text = ""
        for host, dalay in data:
            text += host + "\n"

        tw = self.pref_tree.get_widget("hosts__textview")
        buf = tw.get_buffer()
        buf.set_text(text)

        scale = self.pref_tree.get_widget("interval__hscale")
        scale.set_value(c.refreshInterval)

        self.pref_tree.get_widget("cancel__button").connect(
            "clicked", self.close_prefs)
        self.pref_tree.get_widget("ok__button").connect(
            "clicked", self.apply_prefs)
        window.show_all()
Пример #27
0
 def get_provenanceInfo(self):
     """ queries the sphinx indexer and returns various data """
     """ or False and a (errorcode,error str) tuple """
     sqlcmd = ''
     #jsonresult = '{}'
     jsonresult = collections.OrderedDict()
     confobj = conf.Conf()
     params = json.loads(confobj.provideConfParams())
     conn = ast.literal_eval(params['connectionstring'])
     db = MySQLdb.connect(**conn)
     cursor = db.cursor()
     sqlcmd = "select node, howmanyuris from provenance where match(%s) order by howmanyuris desc limit 0, 1000"
     q = 'http:*'
     cursor.execute(sqlcmd, q)
     result = cursor.fetchall()
     totaluris = 0
     if (result != None):
         flagstart = 'true'
         for row in result:
             if (flagstart == 'true'):
                 jsonresult[u"nodes"] = []
                 jsonresult[u"nodesindex"] = []
                 jsonresult[u"howmanyuris"] = []
                 flagstart = 'false'
             jsonresult[u"nodes"].append(row[2])
             jsonresult[u"nodesindex"].append(row[0])
             jsonresult[u"howmanyuris"].append(row[3])
             totaluris += row[3]
         jsonresult[u"totaluris"] = str(totaluris)
     print "Number of rows returned: %d" % cursor.rowcount
     db.close()
     j = json.dumps(jsonresult)
     # as we don't have anything else to do here, we return a succeded defer
     sucdefer = defer.succeed(
         j)  # result will be passed to any callback attached
     # return the defered
     return sucdefer
Пример #28
0
    def read(self):
        c = conf.Conf(self.user)
        if os.path.exists(self.filename):
            t = int(time.time())
            delays = []
            if t - int(os.path.getmtime(self.filename)) < (
                    2 * c.refreshInterval / 1000):
                f = open(self.filename, "r")
                for line in f:
                    parts = line.strip().split(':')
                    if len(parts) > 1:
                        delays.append((parts[0], float(parts[1])))
                f.close()
            else:  # indicating deamon died
                ind = t % 4
                delays.append(("no", 0.1))
                delays.append(("fresh", 0.1))
                delays.append(("data", 0.1))
                delays.append(("found", 0.1))
                host, data = delays[ind]
                delays[ind] = (host, 10000)

            return delays
        return False
Пример #29
0
    def load_file(self, filename):
        """Load up a config file"""

        self.config_data = conf.Conf()
        try:
            self.config_data.parse_conf_file(filename)
            self.filename = filename
            defptr = self.config_data.default_printer()
            plist = self.config_data.list_printers()
            self.tree_model.clear()
            for p in plist:
                isdef = p == defptr
                inf = self.config_data.get_attribute_value(p, 'printer-info')
                if not inf:
                    inf = ""
                self.tree_model.append((isdef, p, inf))
            self.dirty = False
            self.has_data = True
        except conf.ConfError as msg:
            error_dlg(msg.args[0])
            self.filename = ""
            self.config_data.setup_defaults()
            self.dirty = False
            self.has_data = False
Пример #30
0
 def _ifconf_default(self):
     conf.Conf().set_default_nic(self.ifname)
     return "ifconf"