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


Python NSDate.dateWithString_方法代码示例

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


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

示例1: predicate_info_object

# 需要导入模块: from Foundation import NSDate [as 别名]
# 或者: from Foundation.NSDate import dateWithString_ [as 别名]
def predicate_info_object():
    '''Returns our info object used for predicate comparisons'''
    info_object = {}
    machine = getMachineFacts()
    info_object.update(machine)
    info_object.update(get_conditions())
    # use our start time for "current" date (if we have it)
    # and add the timezone offset to it so we can compare
    # UTC dates as though they were local dates.
    info_object['date'] = add_tzoffset_to_date(
        NSDate.dateWithString_(
            reports.report.get('StartTime', reports.format_time())))
    # split os version into components for easier predicate comparison
    os_vers = machine['os_vers']
    os_vers = os_vers + '.0.0'
    info_object['os_vers_major'] = int(os_vers.split('.')[0])
    info_object['os_vers_minor'] = int(os_vers.split('.')[1])
    info_object['os_vers_patch'] = int(os_vers.split('.')[2])
    # get last build number component for easier predicate comparison
    build = machine['os_build_number']
    info_object['os_build_last_component'] = pkgutils.MunkiLooseVersion(
        build).version[-1]
    if 'Book' in machine.get('machine_model', ''):
        info_object['machine_type'] = 'laptop'
    else:
        info_object['machine_type'] = 'desktop'
    return info_object
开发者ID:alexander-riss,项目名称:munki,代码行数:29,代码来源:info.py

示例2: software_updates_available

# 需要导入模块: from Foundation import NSDate [as 别名]
# 或者: from Foundation.NSDate import dateWithString_ [as 别名]
    def software_updates_available(
            self, force_check=False, suppress_check=False):
        """Checks for available Apple Software Updates, trying not to hit the
        SUS more than needed.

        Args:
          force_check: Boolean. If True, forces a softwareupdate run.
          suppress_check: Boolean. If True, skips a softwareupdate run.
        Returns:
          Integer. Count of available Apple updates.
        """
        success = True
        if suppress_check:
            # don't check at all --
            # typically because we are doing a logout install
            # just return any AppleUpdates info we already have
            if not os.path.exists(self.apple_updates_plist):
                return 0
            try:
                plist = FoundationPlist.readPlist(self.apple_updates_plist)
            except FoundationPlist.FoundationPlistException:
                plist = {}
            return len(plist.get('AppleUpdates', []))
        if force_check:
            # typically because user initiated the check from
            # Managed Software Update.app
            success = self.check_for_software_updates(force_check=True)
        else:
            # have we checked recently?  Don't want to check with
            # Apple Software Update server too frequently
            now = NSDate.new()
            next_su_check = now
            last_su_check_string = prefs.pref(
                'LastAppleSoftwareUpdateCheck')
            if last_su_check_string:
                try:
                    last_su_check = NSDate.dateWithString_(
                        last_su_check_string)
                    # dateWithString_ returns None if invalid date string.
                    if not last_su_check:
                        raise ValueError
                    interval = 24 * 60 * 60
                    # only force check every 24 hours.
                    next_su_check = last_su_check.dateByAddingTimeInterval_(
                        interval)
                except (ValueError, TypeError):
                    pass
            if now.timeIntervalSinceDate_(next_su_check) >= 0:
                success = self.check_for_software_updates(force_check=True)
            else:
                success = self.check_for_software_updates(force_check=False)
        display.display_debug1(
            'CheckForSoftwareUpdates result: %s' % success)
        if success:
            count = self.write_appleupdates_file()
        else:
            self.clear_apple_update_info()
            return 0
        return count
开发者ID:munki,项目名称:munki,代码行数:61,代码来源:au.py

示例3: convert_date_string_to_nsdate

# 需要导入模块: from Foundation import NSDate [as 别名]
# 或者: from Foundation.NSDate import dateWithString_ [as 别名]
def convert_date_string_to_nsdate(datetime_string):
    '''Converts a string in the "2013-04-25T20:00:00Z" format or
    "2013-04-25 20:00:00 +0000" format to an NSDate'''
    nsdate_format = '%Y-%m-%dT%H:%M:%SZ'
    iso_format = '%Y-%m-%d %H:%M:%S +0000'
    fallback_format = '%Y-%m-%d %H:%M:%S'
    try:
        tobj = time.strptime(datetime_string, nsdate_format)
    except ValueError:
        try:
            tobj = time.strptime(datetime_string, iso_format)
        except ValueError:
            try:
                tobj = time.strptime(datetime_string, fallback_format)
            except ValueError:
                return None
    iso_date_string = time.strftime(iso_format, tobj)
    return NSDate.dateWithString_(iso_date_string)
开发者ID:munki,项目名称:munki,代码行数:20,代码来源:pkginfolib.py

示例4: appleSoftwareUpdatesAvailable

# 需要导入模块: from Foundation import NSDate [as 别名]
# 或者: from Foundation.NSDate import dateWithString_ [as 别名]
def appleSoftwareUpdatesAvailable(forcecheck=False, suppresscheck=False):
    '''Checks for available Apple Software Updates, trying not to hit the SUS
    more than needed'''
    if suppresscheck:
        # typically because we're doing a logout install; if
        # there are no waiting Apple Updates we shouldn't
        # trigger a check for them.
        pass
    elif forcecheck:
        # typically because user initiated the check from
        # Managed Software Update.app
        unused_retcode = checkForSoftwareUpdates(forcecheck=True)
    else:
        # have we checked recently?  Don't want to check with
        # Apple Software Update server too frequently
        now = NSDate.new()
        nextSUcheck = now
        lastSUcheckString = munkicommon.pref('LastAppleSoftwareUpdateCheck')
        if lastSUcheckString:
            try:
                lastSUcheck = NSDate.dateWithString_(lastSUcheckString)
                interval = 24 * 60 * 60
                nextSUcheck = lastSUcheck.dateByAddingTimeInterval_(interval)
            except (ValueError, TypeError):
                pass
        if now.timeIntervalSinceDate_(nextSUcheck) >= 0:
            unused_retcode = checkForSoftwareUpdates(forcecheck=True)
        else:
            unused_retcode = checkForSoftwareUpdates(forcecheck=False)


    if writeAppleUpdatesFile():
        displayAppleUpdateInfo()
        return True
    else:
        return False
开发者ID:zdw,项目名称:munki,代码行数:38,代码来源:appleupdates.py

示例5: print

# 需要导入模块: from Foundation import NSDate [as 别名]
# 或者: from Foundation.NSDate import dateWithString_ [as 别名]
for cal in store.calendars():
    if cal._.title == "Work":
        event = CalEvent.event()
        event._.calendar = cal
        event._.title = "WWDC 2009"
        event._.notes = textwrap.dedent('''\
                This June, the center of the Mac universe will be at Moscone
                West in downtown San Francisco, as developers and IT
                professionals from around the globe come together for the
                Apple Worldwide Developers Conference.

                Don't miss this opportunity to connect with Apple engineers,
                get a firsthand look at the latest technology, and spend a
                week getting the kind of inspiration you won't find anywhere
                else.
                ''')
        event._.url = NSURL.URLWithString_('http://www.apple.com/wwdc/')
        event._.location = "Moscone West, San Francisco, CA, USA"
        event._.isAllDay = True
        start = NSDate.dateWithString_("2009-06-8 00:00:00 +0600")
        stop = NSDate.dateWithString_("2009-06-12 23:59:59 +0600")
        event._.startDate = start
        event._.endDate = stop
        res, err = store.saveEvent_span_error_(event, 0, None)
        if not res:
            print("Adding WWDC failed", err.localizedDescription())
        break

else:
    print("Cannot find the right calendar")
开发者ID:benoit-pierre,项目名称:pyobjc,代码行数:32,代码来源:add_wwdc_to_calendar.py


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