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


Python utils.get_logger函数代码示例

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


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

示例1: _execute

    def _execute(self, options, args):
        """Run the deployment."""
        self.logger = get_logger(CommandGitHubDeploy.name, STDERR_HANDLER)

        # Check if ghp-import is installed
        check_ghp_import_installed()

        # Build before deploying
        build = main(['build'])
        if build != 0:
            self.logger.error('Build failed, not deploying to GitHub')
            return build

        # Clean non-target files
        only_on_output, _ = real_scan_files(self.site)
        for f in only_on_output:
            os.unlink(f)

        # Remove drafts and future posts if requested (Issue #2406)
        undeployed_posts = clean_before_deployment(self.site)
        if undeployed_posts:
            self.logger.notice("Deleted {0} posts due to DEPLOY_* settings".format(len(undeployed_posts)))

        # Commit and push
        self._commit_and_push(options['commit_message'])

        return
开发者ID:andredias,项目名称:nikola,代码行数:27,代码来源:github_deploy.py

示例2: set_site

 def set_site(self, site):
     self.logger = utils.get_logger('bundles', utils.STDERR_HANDLER)
     if webassets is None and site.config['USE_BUNDLES']:
         utils.req_missing(['webassets'], 'USE_BUNDLES', optional=True)
         self.logger.warn('Setting USE_BUNDLES to False.')
         site.config['USE_BUNDLES'] = False
     super(BuildBundles, self).set_site(site)
开发者ID:millenniumhand,项目名称:nikola,代码行数:7,代码来源:bundles.py

示例3: _execute

    def _execute(self, command, args):
        self.logger = get_logger('ping', self.site.loghandlers)

        blog_title = self.site.config['BLOG_TITLE']
        site_url = self.site.config['SITE_URL']

        if sys.version_info[0] == 2:
            import xmlrpclib as ping_xmlclient
            import urllib2 as ping_browser
        elif sys.version_info[0] >= 3:
            import xmlrpc.client as ping_xmlclient
            import urllib.request as ping_browser

        for xmlrpc_service in self.site.config['PING_XMLRPC_SERVICES']:
            self.logger.notice("==> XML-RPC service: {0}".format(xmlrpc_service))

            try:
                ping_xmlclient.ServerProxy(xmlrpc_service).weblogUpdates.ping(blog_title, site_url)
            except ping_xmlclient.ProtocolError as e:
                self.logger.warn("Unsuccessfully pinged service {0}: [{1}] {2}".format(xmlrpc_service, e.errcode, e.errmsg))
            except Exception as e:
                self.logger.warn("Unknown problem while pinging service {0}: {1}".format(xmlrpc_service, e))

        for web_service in self.site.config['PING_GET_SERVICES']:
            self.logger.notice("==> HTTP GET service: {0}".format(web_service))

            try:
                ping_browser.urlopen(web_service).read()
            except Exception as e:
                self.logger.warn("Unknown problem while pinging service {0}: {1}".format(web_service, e))

        self.logger.notice("Pinged all services")
开发者ID:hjacobs,项目名称:srcco.de,代码行数:32,代码来源:ping.py

示例4: _execute

    def _execute(self, options, args):
        """Start test server."""
        self.logger = get_logger("serve", self.site.loghandlers)
        out_dir = self.site.config["OUTPUT_FOLDER"]
        if not os.path.isdir(out_dir):
            self.logger.error("Missing '{0}' folder?".format(out_dir))
        else:
            os.chdir(out_dir)
            if "[" in options["address"]:
                options["address"] = options["address"].strip("[").strip("]")
                ipv6 = True
                OurHTTP = IPv6Server
            elif options["ipv6"]:
                ipv6 = True
                OurHTTP = IPv6Server
            else:
                ipv6 = False
                OurHTTP = HTTPServer

            httpd = OurHTTP((options["address"], options["port"]), OurHTTPRequestHandler)
            sa = httpd.socket.getsockname()
            self.logger.info("Serving HTTP on {0} port {1}...".format(*sa))
            if options["browser"]:
                if ipv6:
                    server_url = "http://[{0}]:{1}/".format(*sa)
                else:
                    server_url = "http://{0}:{1}/".format(*sa)
                self.logger.info("Opening {0} in the default web browser...".format(server_url))
                webbrowser.open(server_url)
            try:
                httpd.serve_forever()
            except KeyboardInterrupt:
                self.logger.info("Server is shutting down.")
                return 130
开发者ID:habilain,项目名称:nikola,代码行数:34,代码来源:serve.py

示例5: _execute

    def _execute(self, command, args):

        self.logger = get_logger(
            CommandGitHubDeploy.name, self.site.loghandlers
        )

        # Check if ghp-import is installed
        check_ghp_import_installed()

        # Build before deploying
        build = main(['build'])
        if build != 0:
            self.logger.error('Build failed, not deploying to GitHub')
            sys.exit(build)

        # Clean non-target files
        l = self._doitargs['cmds'].get_plugin('list')(config=self.config, **self._doitargs)
        only_on_output, _ = real_scan_files(l, self.site)
        for f in only_on_output:
            os.unlink(f)

        # Commit and push
        self._commit_and_push()

        return
开发者ID:Drooids,项目名称:nikola,代码行数:25,代码来源:github_deploy.py

示例6: _execute

    def _execute(self, options, args):
        logger = get_logger('vcs', self.site.loghandlers)
        self.site.scan_posts()

        repo_path = local('.')
        wd = workdir.open(repo_path)

        # See if anything got deleted
        del_paths = []
        flag = False
        for s in wd.status():
            if s.state == 'removed':
                if not flag:
                    logger.info('Found deleted files')
                    flag = True
                logger.info('DEL => {}', s.relpath)
                del_paths.append(s.relpath)

        if flag:
            logger.info('Marking as deleted')
            wd.remove(paths=del_paths)
            wd.commit(message='Deleted Files', paths=del_paths)

        # Collect all paths that should be kept under control
        # Post and page sources
        paths = []
        for lang in self.site.config['TRANSLATIONS']:
            for p in self.site.timeline:
                paths.extend(p.fragment_deps(lang))

        # Files in general
        for k, v in self.site.config['FILES_FOLDERS'].items():
            paths.extend(get_path_list(k))
        for k, v in self.site.config['LISTINGS_FOLDERS'].items():
            paths.extend(get_path_list(k))
        for k, v in self.site.config['GALLERY_FOLDERS'].items():
            paths.extend(get_path_list(k))

        # Themes and plugins
        for p in ['plugins', 'themes']:
            paths.extend(get_path_list(p))

        # The configuration
        paths.extend('conf.py')

        # Add them to the VCS
        paths = list(set(paths))
        wd.add(paths=paths)

        flag = False
        for s in wd.status():
            if s.state == 'added':
                if not flag:
                    logger.info('Found new files')
                    flag = True
                logger.info('NEW => {}', s.relpath)

        logger.info('Committing changes')
        wd.commit(message='Updated files')
开发者ID:ChillarAnand,项目名称:plugins,代码行数:59,代码来源:vcs.py

示例7: _execute

    def _execute(self, options, args):
        """Start test server."""
        self.logger = get_logger('serve')
        out_dir = self.site.config['OUTPUT_FOLDER']
        if not os.path.isdir(out_dir):
            self.logger.error("Missing '{0}' folder?".format(out_dir))
        else:
            self.serve_pidfile = os.path.abspath('nikolaserve.pid')
            os.chdir(out_dir)
            if '[' in options['address']:
                options['address'] = options['address'].strip('[').strip(']')
                ipv6 = True
                OurHTTP = IPv6Server
            elif options['ipv6']:
                ipv6 = True
                OurHTTP = IPv6Server
            else:
                ipv6 = False
                OurHTTP = HTTPServer

            httpd = OurHTTP((options['address'], options['port']),
                            OurHTTPRequestHandler)
            sa = httpd.socket.getsockname()
            self.logger.info("Serving HTTP on {0} port {1}...".format(*sa))
            if options['browser']:
                if ipv6:
                    server_url = "http://[{0}]:{1}/".format(*sa)
                elif sa[0] == '0.0.0.0':
                    server_url = "http://127.0.0.1:{1}/".format(*sa)
                else:
                    server_url = "http://{0}:{1}/".format(*sa)
                self.logger.info("Opening {0} in the default web browser...".format(server_url))
                webbrowser.open(server_url)
            if options['detach']:
                self.detached = True
                OurHTTPRequestHandler.quiet = True
                try:
                    pid = os.fork()
                    if pid == 0:
                        signal.signal(signal.SIGTERM, self.shutdown)
                        httpd.serve_forever()
                    else:
                        with open(self.serve_pidfile, 'w') as fh:
                            fh.write('{0}\n'.format(pid))
                        self.logger.info("Detached with PID {0}. Run `kill {0}` or `kill $(cat nikolaserve.pid)` to stop the server.".format(pid))
                except AttributeError:
                    if os.name == 'nt':
                        self.logger.warning("Detaching is not available on Windows, server is running in the foreground.")
                    else:
                        raise
            else:
                self.detached = False
                try:
                    self.dns_sd = dns_sd(options['port'], (options['ipv6'] or '::' in options['address']))
                    signal.signal(signal.SIGTERM, self.shutdown)
                    httpd.serve_forever()
                except KeyboardInterrupt:
                    self.shutdown()
                    return 130
开发者ID:uli-heller,项目名称:nikola,代码行数:59,代码来源:serve.py

示例8: gen_tasks

    def gen_tasks(self):
        config = self.site.config

        self.logger = utils.get_logger('postcast')

        self.site.scan_posts()
        yield self.group_task()

        for slug in config.get('POSTCASTS', []):
            category = _get_with_default_key(
                config.get('POSTCAST_CATEGORY', {}), slug, '')
            tags = _get_with_default_key(
                config.get('POSTCAST_TAGS', {}), slug, '')
            itunes_explicit = _get_with_default_key(
                config.get('POSTCAST_ITUNES_EXPLICIT', {}), slug, '')
            itunes_image = _get_with_default_key(
                config.get('POSTCAST_ITUNES_IMAGE', {}), slug, '')
            itunes_categories = _get_with_default_key(
                config.get('POSTCAST_ITUNES_CATEGORIES'), slug, '')

            for lang in config['TRANSLATIONS']:
                if category:
                    title = config['CATEGORY_TITLES'][lang].get(category)
                    description = config['CATEGORY_DESCRIPTIONS'][lang].get(category)
                else:
                    title = None
                    description = None

                posts = [
                    post for post in self.site.posts
                    if post.is_translation_available(lang) and
                    (post.meta('category', lang) == category if category else True) and
                    (set(post.tags_for_language(lang)) >= set(tags) if tags else True)
                ]

                feed_deps = [self.site.configuration_filename]
                for post in posts:
                    feed_deps.append(post.source_path)
                    feed_deps.append(self.audio_path(lang=lang, post=post))

                output_path = self.feed_path(slug, lang)

                yield {
                    'basename': self.name,
                    'name': str(output_path),
                    'targets': [output_path],
                    'file_dep': feed_deps,
                    'clean': True,
                    'actions': [(self.render_feed, [slug, posts, output_path], {
                        'description': description,
                        'itunes_categories': itunes_categories,
                        'itunes_explicit': itunes_explicit,
                        'itunes_image': itunes_image,
                        'lang': lang,
                        'title': title,
                    })]
                }
开发者ID:getnikola,项目名称:plugins,代码行数:57,代码来源:postcast.py

示例9: set_site

 def set_site(self, site):
     """Set Nikola site."""
     self.logger = utils.get_logger('bundles')
     if webassets is None and site.config['USE_BUNDLES']:
         utils.req_missing(['webassets'], 'USE_BUNDLES', optional=True)
         self.logger.warn('Setting USE_BUNDLES to False.')
         site.config['USE_BUNDLES'] = False
         site._GLOBAL_CONTEXT['use_bundles'] = False
     super(BuildBundles, self).set_site(site)
开发者ID:uli-heller,项目名称:nikola,代码行数:9,代码来源:bundles.py

示例10: _execute

    def _execute(self, command, args):

        self.logger = get_logger('ping', self.site.loghandlers)

        timestamp_path = os.path.join(self.site.config['CACHE_FOLDER'], 'lastping')
        new_ping = datetime.utcnow()

        try:
            with codecs.open(timestamp_path, 'rb', 'utf8') as inf:
                last_ping = datetime.strptime(inf.read().strip(), "%Y-%m-%dT%H:%M:%S.%f")
        except (IOError, Exception) as e:
            self.logger.debug("Problem when reading `{0}`: {1}".format(timestamp_path, e))
            last_ping = datetime(1970, 1, 1)

        """Limit pings to every 15 minutes to avoid looking like spam"""
        if (timedelta(minutes=15) > new_ping - last_ping):
            self.logger.warn("Pings suppressed. Pinging too often! Only ping when there are new posts! (Max once per 15 minutes.)")
            return 0

        with codecs.open(timestamp_path, 'wb+', 'utf8') as outf:
            outf.write(new_ping.isoformat())

        try:
            blog_title = self.site.config['BLOG_TITLE']()
        except TypeError:
            blog_title = self.site.config['BLOG_TITLE']
        site_url = self.site.config['SITE_URL']

        if sys.version_info[0] == 2:
            import xmlrpclib as ping_xmlclient
            import urllib2 as ping_browser
        elif sys.version_info[0] >= 3:
            import xmlrpc.client as ping_xmlclient
            import urllib.request as ping_browser
        else:
            self.logger.error("Unsupported Python version. Well done!")
            return

        for xmlrpc_service in self.site.config['PING_XMLRPC_SERVICES']:
            self.logger.notice("==> XML-RPC service: {0}".format(xmlrpc_service))

            try:
                ping_xmlclient.ServerProxy(xmlrpc_service).weblogUpdates.ping(blog_title, site_url)
            except ping_xmlclient.ProtocolError as e:
                self.logger.warn("Unsuccessfully pinged service {0}: [{1}] {2}".format(xmlrpc_service, e.errcode, e.errmsg))
            except Exception as e:
                self.logger.warn("Unknown problem while pinging service {0}: {1}".format(xmlrpc_service, e))

        for web_service in self.site.config['PING_GET_SERVICES']:
            self.logger.notice("==> HTTP GET service: {0}".format(web_service))

            try:
                ping_browser.urlopen(web_service).read()
            except Exception as e:
                self.logger.warn("Unknown problem while pinging service {0}: {1}".format(web_service, e))

        self.logger.notice("Pinged all services")
开发者ID:PyUGRM,项目名称:pyugrm-web,代码行数:57,代码来源:ping.py

示例11: _execute

    def _execute(self, command, args):
        self.logger = get_logger('deploy', self.site.loghandlers)
        # Get last successful deploy date
        timestamp_path = os.path.join(self.site.config['CACHE_FOLDER'], 'lastdeploy')
        if self.site.config['COMMENT_SYSTEM_ID'] == 'nikolademo':
            self.logger.warn("\nWARNING WARNING WARNING WARNING\n"
                             "You are deploying using the nikolademo Disqus account.\n"
                             "That means you will not be able to moderate the comments in your own site.\n"
                             "And is probably not what you want to do.\n"
                             "Think about it for 5 seconds, I'll wait :-)\n\n")
            time.sleep(5)

        deploy_drafts = self.site.config.get('DEPLOY_DRAFTS', True)
        deploy_future = self.site.config.get('DEPLOY_FUTURE', False)
        if not (deploy_drafts and deploy_future):
            # Remove drafts and future posts
            out_dir = self.site.config['OUTPUT_FOLDER']
            undeployed_posts = []
            self.site.scan_posts()
            for post in self.site.timeline:
                if (not deploy_drafts and post.is_draft) or \
                   (not deploy_future and post.publish_later):
                    remove_file(os.path.join(out_dir, post.destination_path()))
                    remove_file(os.path.join(out_dir, post.source_path))
                    undeployed_posts.append(post)

        for command in self.site.config['DEPLOY_COMMANDS']:
            self.logger.notice("==> {0}".format(command))
            try:
                subprocess.check_call(command, shell=True)
            except subprocess.CalledProcessError as e:
                self.logger.error('Failed deployment — command {0} '
                                  'returned {1}'.format(e.cmd, e.returncode))
                sys.exit(e.returncode)

        self.logger.notice("Successful deployment")
        if self.site.config['TIMEZONE'] is not None:
            tzinfo = pytz.timezone(self.site.config['TIMEZONE'])
        else:
            tzinfo = pytz.UTC
        try:
            with open(timestamp_path, 'rb') as inf:
                last_deploy = literal_eval(inf.read().strip())
                # this might ignore DST
                last_deploy = last_deploy.replace(tzinfo=tzinfo)
                clean = False
        except Exception:
            last_deploy = datetime(1970, 1, 1).replace(tzinfo=tzinfo)
            clean = True

        new_deploy = datetime.now()
        self._emit_deploy_event(last_deploy, new_deploy, clean, undeployed_posts)

        # Store timestamp of successful deployment
        with codecs.open(timestamp_path, 'wb+', 'utf8') as outf:
            outf.write(repr(new_deploy))
开发者ID:Proteus-tech,项目名称:nikola,代码行数:56,代码来源:deploy.py

示例12: _execute

    def _execute(self, command, args):

        self.logger = get_logger('iarchiver', STDERR_HANDLER)

        """ /robots.txt must be in root, so this use of urljoin() is intentional """
        iatestbot = robotparser.RobotFileParser(urljoin(self.site.config['SITE_URL'], "/robots.txt"))
        iatestbot.read()

        timestamp_path = os.path.join(self.site.config['CACHE_FOLDER'], 'lastiarchive')
        new_iarchivedate = datetime.now(dateutil.tz.tzutc())

        try:
            with codecs.open(timestamp_path, 'rb', 'utf8') as inf:
                last_iarchivedate = datetime.strptime(inf.read().strip(), "%Y-%m-%dT%H:%M:%S.%f%z")
            firstrun = False
        except (IOError, Exception) as e:
            self.logger.debug("Problem when reading `{0}`: {1}".format(timestamp_path, e))
            last_iarchivedate = datetime(1970, 1, 1).replace(tzinfo=dateutil.tz.tzutc())
            firstrun = True

        self.site.scan_posts()

        sent_requests = False
        self.logger.info("Beginning submission of archive requests. This can take some time....")

        for post in self.site.timeline:
            if post.is_draft or post.publish_later:
                continue
            postdate = datetime.strptime(post.formatted_date("%Y-%m-%dT%H:%M:%S"), "%Y-%m-%dT%H:%M:%S")
            postdate_sitetime = self.site.tzinfo.localize(postdate)
            postdate_utc = postdate_sitetime.astimezone(dateutil.tz.tzutc())
            if (firstrun or last_iarchivedate <= postdate_utc):
                post_permalink = post.permalink(absolute=True)
                archival_request = "http://web.archive.org/save/{0}".format(post_permalink)
                if (iatestbot.can_fetch("ia_archiver", post_permalink)):
                    try:
                        """ Intentionally not urlencoded """
                        web_browser.urlopen(archival_request).read()
                        self.logger.info("==> sent archive request for {0}".format(post_permalink))
                    except Exception as e:
                        self.logger.warn("==> unknown problem when archiving {0}: ({1})".format(post_permalink, e))

                    """ Throttle requests """
                    time.sleep(4)
                    sent_requests = True
                else:
                    self.logger.warn("==> /robots.txt directives blocked archiving of ({0})".format(post_permalink))

        """ Record archival time """
        with codecs.open(timestamp_path, 'wb+', 'utf8') as outf:
            outf.write(new_iarchivedate.strftime("%Y-%m-%dT%H:%M:%S.%f%z"))

        if sent_requests:
            self.logger.notice("Archival requests sent to the Internet Archive.")
        else:
            self.logger.notice("Nothing new to archive")
开发者ID:getnikola,项目名称:plugins,代码行数:56,代码来源:iarchiver.py

示例13: set_site

    def set_site(self, site):
        self.config_dependencies = []
        for plugin_info in site.plugin_manager.getPluginsOfCategory("RestExtension"):
            self.config_dependencies.append(plugin_info.name)

        self.logger = get_logger('compile_rest', site.loghandlers)
        if not site.debug:
            self.logger.level = 4

        return super(CompileRestHTML5, self).set_site(site)
开发者ID:ChillarAnand,项目名称:plugins,代码行数:10,代码来源:rest_html5.py

示例14: set_site

    def set_site(self, site):
        super(CompileRest, self).set_site(site)
        self.config_dependencies = []
        for plugin_info in self.get_compiler_extensions():
            self.config_dependencies.append(plugin_info.name)
            plugin_info.plugin_object.short_help = plugin_info.description

        self.logger = get_logger('compile_rest', STDERR_HANDLER)
        if not site.debug:
            self.logger.level = 4
开发者ID:millenniumhand,项目名称:nikola,代码行数:10,代码来源:__init__.py

示例15: _execute

    def _execute(self, options, args):
        """Start test server."""
        self.logger = get_logger('serve', STDERR_HANDLER)
        out_dir = self.site.config['OUTPUT_FOLDER']
        if not os.path.isdir(out_dir):
            self.logger.error("Missing '{0}' folder?".format(out_dir))
        else:
            os.chdir(out_dir)
            if '[' in options['address']:
                options['address'] = options['address'].strip('[').strip(']')
                ipv6 = True
                OurHTTP = IPv6Server
            elif options['ipv6']:
                ipv6 = True
                OurHTTP = IPv6Server
            else:
                ipv6 = False
                OurHTTP = HTTPServer

            httpd = OurHTTP((options['address'], options['port']),
                            OurHTTPRequestHandler)
            sa = httpd.socket.getsockname()
            self.logger.info("Serving HTTP on {0} port {1}...".format(*sa))
            if options['browser']:
                if ipv6:
                    server_url = "http://[{0}]:{1}/".format(*sa)
                else:
                    server_url = "http://{0}:{1}/".format(*sa)
                self.logger.info("Opening {0} in the default web browser...".format(server_url))
                webbrowser.open(server_url)
            if options['detach']:
                OurHTTPRequestHandler.quiet = True
                try:
                    pid = os.fork()
                    if pid == 0:
                        httpd.serve_forever()
                    else:
                        self.logger.info("Detached with PID {0}. Run `kill {0}` to stop the server.".format(pid))
                except AttributeError as e:
                    if os.name == 'nt':
                        self.logger.warning("Detaching is not available on Windows, server is running in the foreground.")
                    else:
                        raise e
            else:
                try:
                    self.dns_sd = dns_sd(options['port'], (options['ipv6'] or '::' in options['address']))
                    httpd.serve_forever()
                except KeyboardInterrupt:
                    self.logger.info("Server is shutting down.")
                    if self.dns_sd:
                        self.dns_sd.Reset()
                    return 130
开发者ID:andredias,项目名称:nikola,代码行数:52,代码来源:serve.py


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