当前位置: 首页>>代码示例>>Python>>正文


Python util.Util类代码示例

本文整理汇总了Python中util.Util的典型用法代码示例。如果您正苦于以下问题:Python Util类的具体用法?Python Util怎么用?Python Util使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Util类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: optimizeSubdirectory

    def optimizeSubdirectory(self, path, callback, new_path, extension = "", minimize = False):
        """optimizes a subdirectory within a directory being optimized

        Arguments:
        path -- path to directory
        callback -- function to run the file through
        new_path -- path to optimized parent directory
        extension -- extension to search for in the directory
        minimize -- whether or not we should minimize the file contents (html)

        Returns:
        void

        """
        subdir_path = new_path + "/" + path.split("/").pop()
        skip = self.prepareDirectory(subdir_path)
        if skip is True:
            return

        for dir_file in Util.getFilesFromDir(path, extension):
            if Util.isDir(dir_file):
                self.optimizeSubdirectory(dir_file, callback, subdir_path, extension, minimize)
                continue

            new_file_path = subdir_path + "/" + Util.getFileName(dir_file)
            self.optimizeFile(dir_file, callback, minimize, new_file_path)
开发者ID:Mondego,项目名称:pyreco,代码行数:26,代码来源:allPythonContent.py

示例2: callback

    def callback(self, cmd, action, target, msg):
        if msg is None:
            self._home.publish_msg(cmd, u"时间格式错误")
            return False, None

        if msg.endswith(u'点') or \
           msg.endswith(u'分'):
            t = Util.gap_for_timestring(msg)
        elif msg.endswith(u"秒"):
            t = int(Util.cn2dig(msg[:-1]))
        elif msg.endswith(u"分钟"):
            t = int(Util.cn2dig(msg[:-2]))*60
        elif msg.endswith(u"小时"):
            t = int(Util.cn2dig(msg[:-2]))*60*60
        else:
            self._home.publish_msg(cmd, u"时间格式错误")
            return False
        if t is None:
            self._home.publish_msg(cmd, u"时间格式错误")
            return False, None
        DEBUG("thread wait for %d sec" % (t, ))
        self._home.publish_msg(cmd, action + target + msg)

        threading.current_thread().waitUtil(t)
        if threading.current_thread().stopped():
            return False
        self._home.setResume(True)
        count = 7
        Sound.play( Res.get_res_path("sound/com_bell") , True, count)
        self._home.setResume(False)
        return True
开发者ID:euwen,项目名称:LEHome,代码行数:31,代码来源:tools.py

示例3: parse_args

def parse_args(args_list):
    log.info("Stetl version = %s" % __version__)

    argparser = argparse.ArgumentParser(description='Invoke Stetl')
    argparser.add_argument('-c ', '--config', type=str, help='ETL config file in .ini format', dest='config_file',
                           required=False)

    argparser.add_argument('-s ', '--section', type=str, help='Section in the config file to execute, default is [etl]',
                           dest='config_section', required=False)

    argparser.add_argument('-a ', '--args', type=str,
                           help='Arguments or .properties files to be substituted for symbolic {argN}s in Stetl config file,\
                                as -a "arg1=foo arg2=bar" and/or -a args.properties, multiple -a options are possible',
                           dest='config_args', required=False, action='append')

    argparser.add_argument('-d ', '--doc', type=str,
                           help='Get component documentation like its configuration parameters, e.g. stetl doc stetl.inputs.fileinput.FileInput',
                           dest='doc_args', required=False)

    args = argparser.parse_args(args_list)

    if args.config_args:
        args_total = dict()
        for arg in args.config_args:
            if os.path.isfile(arg):
                log.info('Found args file at: %s' % arg)
                args_total = Util.merge_two_dicts(args_total, Util.propsfile_to_dict(arg))
            else:
                # Convert string to dict: http://stackoverflow.com/a/1248990
                args_total = Util.merge_two_dicts(args_total, Util.string_to_dict(arg))

        args.config_args = args_total

    return args
开发者ID:fsteggink,项目名称:stetl,代码行数:34,代码来源:main.py

示例4: processMaps

    def processMaps(self):
        """loops through classes and ids to process to determine shorter names to use for them
        and creates a dictionary with these mappings

        Returns:
        void

        """
        # reverse sort so we can figure out the biggest savings
        classes = self.class_counter.items()
        classes.sort(key = itemgetter(1), reverse=True)

        for class_name, savings in classes:
            small_class = "." + VarFactory.getNext("class")

            # adblock extensions may block class "ad" so we should never generate it
            # also if the generated class already exists as a class to be processed
            # we can't use it or bad things will happen
            while small_class == ".ad" or Util.keyInTupleList(small_class, classes):
                small_class = "." + VarFactory.getNext("class")

            self.class_map[class_name] = small_class

        ids = self.id_counter.items()
        ids.sort(key = itemgetter(1), reverse=True)

        for id, savings in ids:
            small_id = "#" + VarFactory.getNext("id")

            # same holds true for ids as classes
            while small_id == "#ad" or Util.keyInTupleList(small_id, ids):
                small_id = "#" + VarFactory.getNext("id")

            self.id_map[id] = small_id
开发者ID:Mondego,项目名称:pyreco,代码行数:34,代码来源:allPythonContent.py

示例5: __init__

	def __init__(self, name, ip, iface, hostname="", loginfo=""):
		"""
		Create a new host object, with the given name, IP specification and interface

		name -- Nickname for the host
		ip -- IP specification for the host or subnet (e.g. "127.0.0.1 10.0.0.0/24")
		iface -- Interface nickname this is connected to (only one!)
		"""
		# verify and store name
		if name == "" and not Util.verify_name(name):
			raise PyromanException("Host '%s' lacking a valid name at %s" \
				% (name, iface, loginfo))
		if Firewall.hosts.has_key(name):
			raise PyromanException("Duplicate host specification: '%s' at %s" % (name, loginfo))
		self.name = name
		# verify and store IPs
		if ip == "":
			raise PyromanException("Host '%s' definition lacking IP address at %s" % (name, loginfo))
		self.ip = Util.splitter.split(ip)
		for i in self.ip:
			if not Util.verify_ipnet(i):
				raise PyromanException("IP specification '%s' invalid for host '%s' at %s" \
					% (i, name, loginfo))
		# verify and store interface
		self.iface = iface
		if iface == "":
			raise PyromanException("Host definition '%s' lacking kernel interfaces at %s" \
				% (name, loginfo))
		# store "real" hostname (which may be longer than nick)
		# this is used for "localhost detection"
		self.hostname = hostname
		# store loginfo
		self.loginfo = loginfo
		# register with firewall
		Firewall.hosts[name] = self
开发者ID:wil,项目名称:pyroman,代码行数:35,代码来源:host.py

示例6: __del__

 def __del__(self):
     Util.trace("destroy DirCheck instance")
     streamRef = self._streamRef
     # Stop / Invalidate / Release
     FSEventStreamStop(streamRef)
     FSEventStreamInvalidate(streamRef)
     FSEventStreamRelease(streamRef)
开发者ID:nyakagawan,项目名称:vfiler,代码行数:7,代码来源:dirCheck.py

示例7: _get_uid

 def _get_uid(cls):
     user_id = Util.get_user_id()
     if not user_id:
         print("welcome, creating id for you.")
         user_id = requests.get(cls.get_user_id_url).text
         Util.set_user_id(user_id)
     return user_id
开发者ID:dineshkumar-cse,项目名称:ShareFile,代码行数:7,代码来源:service_api.py

示例8: main

def main():
    worm = Worm("http://11.11.0.64:8099/", "http://11.11.0.64:4041/stages/", True, False, "Flint")
    # worm = Worm("http://211.69.198.208:8080/", "http://211.69.198.208:8080/history/app-20150722101951-0008/stages/", "Flint")
    # finish_sparks = worm.get_finish_sparks()
    running_spark = worm.get_finish_spark()
    if running_spark != None:
        running_stages = running_spark.get_running_stages()
        finished_stages = running_spark.get_finished_stages()
        stages = []
        for finished_stage in finished_stages:
            stage_dict = {
                "stage_id": finished_stage.get_stage_id(),
                "stage_duration": Util.format_time(finished_stage.get_duration()),
                "submit_time": finished_stage.get_submit_time(),
                "tasks_percent": 100.0,
                "gc_time": round(finished_stage.get_gc_time(), 1),
            }
            stages.append(stage_dict)
        for running_stage in running_stages:
            stage_dict = {
                "stage_id": running_stage.get_stage_id(),
                "stage_duration": Util.format_time(running_stage.get_duration()),
                "submit_time": running_stage.get_submit_time(),
                "tasks_percent": Util.format_tasks_percent(running_stage.get_tasks_percent()),
                "gc_time": round(running_stage.get_gc_time(), 1),
            }
            stages.append(stage_dict)
        # print stages
        format_spark = {}
        format_spark["app_name"] = running_spark.get_app_name()
        format_spark["total_time"] = Util.format_time(running_spark.get_total_time())
        format_spark["status"] = running_spark.get_status()
        format_spark["property"] = running_spark.get_property()
        format_spark["stages"] = stages
        print format_spark
开发者ID:kzx1025,项目名称:SparkMonitor,代码行数:35,代码来源:worm.py

示例9: on_search_enter_key

    def on_search_enter_key(self, entry):
        # find /home/shercoder/ \( ! -regex '.*/\..*' \) | grep "soccer"
        search_terms = entry.get_text()
        is_tag_search = False
        if search_terms.startswith('@'):
            search_terms = search_terms[1:]
            is_tag_search = True
        else:
            search_terms = search_terms.split(' ')

        if entry.get_text():
            allfiles = []
            if is_tag_search:
                results = self._index_manager.search_documents(search_terms)
                for hit in results:
                    allfiles.append((hit['filename'], hit['filepath']))
            else:
                for root, dirs, files in os.walk(HOME):
                    files = [f for f in files if not f[0] == '.']
                    dirs[:] = [d for d in dirs if not d[0] == '.']
                    for term in search_terms:
                        for filename in fnmatch.filter(files, "*{}*".format(term)):
                            allfiles.append((filename, os.path.join(root, filename)))
            self._treeview.get_model().generate_search_tree(allfiles)
        else:
            self._treeview.get_model().generate_tree(HOME)
            Util.clear_notebook(self._notebook)
开发者ID:shercoder,项目名称:ingress,代码行数:27,代码来源:main_window.py

示例10: kernel_version

	def kernel_version(min=None, max=None):
		"""
		Return kernel version or test for a minimum and/or maximum version

		min -- minimal kernel version required
		max -- maximum kernel version required
		"""
		if not Firewall._kernelversion:
			# query iptables version
			kvcmd = subprocess.Popen(Firewall.kernelversioncmd,
				stdout=subprocess.PIPE)
			result = kvcmd.communicate()[0]
			Firewall._kernelversion = result.strip()
			# still no version number? - raise PyromanException(an exception)
			if not Firewall._kernelversion:
				raise Error("Couldn't get kernel version!")
		if not min and not max:
			return Firewall._kernelversion
		if min:
			if Util.compare_versions(Firewall._kernelversion, min) < 0:
				return False
		if max:
			if Util.compare_versions(Firewall._kernelversion, max) > 0:
				return False
		return True
开发者ID:wil,项目名称:pyroman,代码行数:25,代码来源:pyroman.py

示例11: _dumpVariable

 def _dumpVariable( self ):
     Util.trace( "---------------------------" )
     Util.trace( "index:   " + str( self.index_ ) )
     Util.trace( "name:    " + str( self.name_ ) )
     #Util.trace( "ext:     " + str( self.ext_ ) )
     Util.trace( "mtime:   " + str( self.mtime_ ) )
     Util.trace( "bgColor: " + str( self.bgColor_ ) )
开发者ID:nyakagawan,项目名称:vfiler,代码行数:7,代码来源:element.py

示例12: build

    def build(self, is_main=False, is_method=False, is_class=False):
        '''
        Copies the base java file, moves the changes into it and compiles it.
        If an Exception occurs, the change is rolled back.
        '''
        shutil.copyfile(START_FILE, MAIN_FILE)
        self.parse_file(MAIN_FILE)
        
        # Attempt to compile the new change
        try:
            Util.compile_java([MAIN_FILE] + self.full_class_names)
        except Exception as e:
            if verbose_output == True:
                print 'Exception: %s' % e
            else:
                print 'An Exception occurred compiling the program'

            # Determine who caused the exception and remove the code
            if is_main is True:
                self.main_input.pop()
            elif is_method is True:
                self.methods.pop()
                self.method_names.pop()
            elif is_class is True:
                self.classes.pop()
                self.class_names.pop()
                filename = self.full_class_names.pop()
                Util.remove_file(filename)

            return

        if is_main is True:
            self.run()
开发者ID:aeggum,项目名称:JavaConsole,代码行数:33,代码来源:console.py

示例13: post

	def post(self, answerId):
		print 'hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii'
		print answerId
		message = self.get_argument("message")
		userId = self.get_current_user_id()
		answer = Answer.queryByAnswerId(answerId)
		# 异常1 回答不存在
		if not answer :
			self.write(Util.response(None, -1, u'回复不存在'))
			return

		# 请输入评论内容
		if message == "":
			self.write(Util.response(None, -1, u'请输入评论内容'))
			return

		# 不能评论锁定的问题
		question = Question.queryById(answer.question_id)
		if question.lock == 1 :
			self.write(Util.response(None, -1, u'不能评论锁定的问题'))
			return

		# 你没有发表评论的权限(略)
		
		# 插入一条评论
		AnswerComment.addAnswerComment(answerId, userId, message)
		rsm = {'item_id':answerId, 'type_name':'answer'}
		self.write(Util.response(rsm, 1, None))
开发者ID:hellowego,项目名称:auto,代码行数:28,代码来源:questionHandler.py

示例14: update

def update():
    '''
    Sets target's siteurl, blogname, and homepage
    '''
    Util.validate_role()
    config = env.config
    db_table = 'wp_options'
    entries = {
        'siteurl': config['site_url'],
        'blogname': config['site_name'],
        'home': config['site_url']

    }

    with local_tunnel(config['db_port']):
        cnx = mysql.connector.connect(user=config['db_user'],
                                        password=config['db_pass'],
                                        host='127.0.0.1',
                                        port=config['db_port'],
                                        database=config['db_name'])

        cnx.start_transaction()
        cursor = cnx.cursor()

        update_option = ("UPDATE `{db_table}` "
                        "SET `option_value`=%s "
                        "WHERE `option_name` LIKE %s".format(db_table=db_table))

        for key, value in entries.iteritems():
            cursor.execute(update_option, (value, key))

        cnx.commit()
        cnx.close()
开发者ID:cgspeck,项目名称:fabric_press,代码行数:33,代码来源:db.py

示例15: on_post_save

 def on_post_save(self, view):
     file = view.file_name()
     if not (Util.is_scala(file) or Util.is_java(file)):
         return
     env = getEnvironment(view.window())
     if env and env.is_connected() and env.client.analyzer_ready:
         TypeCheckFilesReq([view.file_name()]).run_in(env, async=True)
开发者ID:ensime,项目名称:ensime-sublime,代码行数:7,代码来源:commands.py


注:本文中的util.Util类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。