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


Python Configuration.refresh方法代码示例

本文整理汇总了Python中Configuration.Configuration.refresh方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.refresh方法的具体用法?Python Configuration.refresh怎么用?Python Configuration.refresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Configuration.Configuration的用法示例。


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

示例1: YoutubeDownloader

# 需要导入模块: from Configuration import Configuration [as 别名]
# 或者: from Configuration.Configuration import refresh [as 别名]
class YoutubeDownloader(multiprocessing.Process):
 
    def __init__(self, work_queue, result_queue):
        global doDebug
 
        # base class initialization
        multiprocessing.Process.__init__(self)
 
        self.name = os.path.basename(os.path.abspath("."))
        self.__config = Configuration(self.name)
        # job management stuff
        self.work_queue = work_queue
        self.result_queue = result_queue
        self.kill_received = False

    def run(self):
        global doDebug
        while not self.kill_received:
            if doDebug:
                print "check for next url"
            try:
                url = self.work_queue.get()
                self.__config.refresh()
                videos_directory = self.__config.get('Configuration', 'videos_directory')
                self.useFormat = self.__config.get('Download Options', 'useFormat')
                self.videoFormat = self.__config.get('Download Options', 'videoFormat')
                self.maxVideoFormat = self.__config.get('Download Options', 'maxVideoFormat')
                self.useAuthentication = self.__config.get('Download Options', 'useAuthentication')
                self.userName = self.__config.get('Download Options', 'userName')
                self.userPassword = self.__config.get('Download Options', 'userPassword')
                self.ignoreErrors = self.__config.get('Download Options', 'ignoreErrors')
                self.resumeDownload = self.__config.get('Download Options', 'resumeDownload')
                self.noOverwrites = self.__config.get('Download Options', 'noOverwrites')
                self.useTitle = self.__config.get('Download Options', 'useTitle')

                if not videos_directory:
                    p = subprocess.Popen(["xdg-user-dir","VIDEOS"],stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=False)
                    directoryName, errors = p.communicate()
                    directoryName=directoryName.rstrip()
                    videos_directory = os.path.abspath(directoryName)

                if not (videos_directory == os.path.abspath('.')):
                    os.chdir(videos_directory)
                if doDebug:
                    print "current video directory is: "+os.path.abspath('.')
                retcode = self.main(url)
            except Queue.Empty:
                time.sleep(1)

    def debug(self):
        global doDebug
        doDebug = True

    def main(self,url):
        global doDebug
        if doDebug:
            print "In main URL is: "+url
	parser, opts, args = parseOpts()
        #Need to set user options from config file if we can
        if self.useFormat == '0':
            opts.format = youtube.videoFormats.get(self.videoFormat)
        elif self.useFormat == '1':
            opts.format_limit = youtube.videoFormats.get(self.maxVideoFormat)
        if self.useAuthentication == '1':
            opts.username = self.userName
            opts.password = self.userPassword
        opts.continue_dl = self.resumeDownload
        opts.ignoreerrors = self.ignoreErrors
        opts.nooverwrites = self.noOverwrites
        opts.usetitle = self.useTitle

	# Open appropriate CookieJar
	if opts.cookiefile is None:
		jar = cookielib.CookieJar()
	else:
		try:
			jar = cookielib.MozillaCookieJar(opts.cookiefile)
			if os.path.isfile(opts.cookiefile) and os.access(opts.cookiefile, os.R_OK):
				jar.load()
		except (IOError, OSError), err:
                        time.sleep(1)

	# Dump user agent
	if opts.dump_user_agent:
		print std_headers['User-Agent']

	# Batch file verification
	batchurls = []
	if opts.batchfile is not None:
		try:
			if opts.batchfile == '-':
				batchfd = sys.stdin
			else:
				batchfd = open(opts.batchfile, 'r')
			batchurls = batchfd.readlines()
			batchurls = [x.strip() for x in batchurls]
			batchurls = [x for x in batchurls if len(x) > 0 and not re.search(r'^[#/;]', x)]
		except IOError:
                        time.s;eep(1)
	all_urls = batchurls
#.........这里部分代码省略.........
开发者ID:Awkee,项目名称:cairo-dock-plug-ins-extras,代码行数:103,代码来源:myYoutubeDownloader.py


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