def read(self): if not self.initially_read: predefined_profiles = self.profiles else: predefined_profiles = () self.profiles = ProfileList(DefaultProfile(self.fields.name_value_dict)) # TODO: remove static options static_options, profiles = self.backend_instance.read() for field_name, value in static_options.iteritems(): setattr(self, field_name, value) active_profile = 0 for profile in flatten((profiles, predefined_profiles)): position = profile.pop('position') self.profiles.insert(position, profile, overwrite=True) if profile.pop('selected', False): active_profile = position self.use_profile(active_profile) self.initially_read = True
def days_in_month(year, month): """ Returns how many days the given month has. """ monthdays = calendar.monthcalendar(year, month) return len(filter(lambda x: x > 0, flatten(monthdays)))