コード例 #1
0
ファイル: scrivener.py プロジェクト: raypou/flashbake
 def init(self, config):
     self.get_count = self._get_count_python
     if self.use_textutil:
         if flashbake.executable_available("textutil"):
             self.get_count = self._get_count_textutil
         else:
             logging.warn("unable to find textutil, will use python " "wordcount calculation")
コード例 #2
0
 def init(self, config):
     self.get_count = self._get_count_python
     if self.use_textutil:
         if flashbake.executable_available('textutil'):
             self.get_count = self._get_count_textutil
         else:
             logging.warn("unable to find textutil, will use python "
                          "wordcount calculation")
コード例 #3
0
ファイル: uptime.py プロジェクト: sahwar/flashbake
    def __run_uptime(self):
        """ For OSes that don't provide procfs, then try to use the updtime command.
        
            Thanks to Tony Giunta for this contribution. """
        if not flashbake.executable_available('uptime'):
            return None

        # Try to capture output of 'uptime' command,
        # if not found, catch OSError, log and return None
        try:
            output = Popen("uptime", stdout=PIPE).communicate()[0].split()
        except OSError:
            logging.warn("Can't find 'uptime' command in $PATH")
            return None

        # Parse uptime output string
        # if len == 10 or 11, uptime is less than a day
        if len(output) in [10, 11]:
            days = "00"
            hours_and_minutes = output[2].strip(",")
        elif len(output) == 12:
            days = output[2]
            hours_and_minutes = output[4].strip(",")
        else:
            return None

        # If time is exactly x hours/mins, no ":" in "hours_and_minutes"
        # and the interpreter will throw a ValueError
        try:
            hours, minutes = hours_and_minutes.split(":")
        except ValueError:
            if output[3].startswith("hr"):
                hours = hours_and_minutes
                minutes = "00"
            elif output[3].startwwith("min"):
                hours = "00"
                minutes = hours_and_minutes
            else:
                return None

        # Build up output string, might require Python 2.5+
        uptime = (days + (" day, " if days == "1" else " days, ") + hours +
                  (" hour, " if hours == "1" else " hours, ") + minutes +
                  (" minute" if minutes == "1" else " minutes"))

        return uptime
コード例 #4
0
ファイル: uptime.py プロジェクト: MaxMillion/flashbake
    def __run_uptime(self):
        """ For OSes that don't provide procfs, then try to use the updtime command.
        
            Thanks to Tony Giunta for this contribution. """
        if not flashbake.executable_available('uptime'):
            return None

        # Try to capture output of 'uptime' command, 
        # if not found, catch OSError, log and return None
        try:
            output = Popen("uptime", stdout=PIPE).communicate()[0].split()
        except OSError:
            logging.warn("Can't find 'uptime' command in $PATH")
            return None

        # Parse uptime output string
        # if len == 10 or 11, uptime is less than a day
        if len(output) in [10, 11]:
            days = "00"
            hours_and_minutes = output[2].strip(",")
        elif len(output) == 12:
            days = output[2]
            hours_and_minutes = output[4].strip(",")
        else:
            return None

        # If time is exactly x hours/mins, no ":" in "hours_and_minutes" 
        # and the interpreter will throw a ValueError
        try:
            hours, minutes = hours_and_minutes.split(":")
        except ValueError:
            if output[3].startswith("hr"):
                hours = hours_and_minutes
                minutes = "00"
            elif output[3].startwwith("min"):
                hours = "00"
                minutes = hours_and_minutes
            else:
                return None

        # Build up output string, might require Python 2.5+
        uptime = (days + (" day, " if days == "1" else " days, ") + 
                hours + (" hour, " if hours == "1" else " hours, ") + 
                minutes + (" minute" if minutes == "1" else " minutes"))

        return uptime
コード例 #5
0
ファイル: scrivener.py プロジェクト: sahwar/flashbake
 def init(self, config):
     if not flashbake.executable_available('textutil'):
         raise PluginError(
             PLUGIN_ERRORS.ignorable_error, self.plugin_spec,
             'Could not find command, textutil.')  #@UndefinedVariable
コード例 #6
0
ファイル: scrivener.py プロジェクト: abachman/flashbake
 def init(self, config):
     if not flashbake.executable_available('textutil'):
         raise PluginError(PLUGIN_ERRORS.ignorable_error, self.plugin_spec, 'Could not find command, textutil.') #@UndefinedVariable