Example #1
0
    def gettimedelta(self, section, option):
        """
        Get option as datetime.timedelta-instance.

        Args: section and option
        """
        return timeparser.parsetimedelta(self.get(section, option))
Example #2
0
 def __call__(self, parser, namespace, values, option_string=None):
     value = ' '.join(values) if isinstance(values, list) else values
     try:
         timedelta = timeparser.parsetimedelta(value)
     except ValueError:
         raise ArgumentError(self, self.ERR % (values, 'timedelta'))
     else:
         self.append(namespace, timedelta)
Example #3
0
 def __call__(self, parser, namespace, values, option_string=None):
     value = ' '.join(values) if isinstance(values, list) else values
     kwords = ('weeks', 'days', 'hours', 'minutes', 'seconds')
     try:
         key = [k for k in kwords if k.startswith(self.dest)][0]
     except IndexError:
         key = 'days'
     try:
         timedelta = timeparser.parsetimedelta(value, key)
     except ValueError:
         raise ArgumentError(self, self.ERR % (value, 'timedelta'))
     else:
         setattr(namespace, self.dest, timedelta)
Example #4
0
def interactive(version_contents, build_number):
    if not prompt("Will this build be mandatory?"):
        # No further modification required.
        return version_contents

    print("Durations can be things like '1 week' or '5 days'.")
    today = datetime.datetime.now().date()
    while True:
        try:
            duration_input = raw_input("How long until until mandatory? ")
            duration = timeparser.parsetimedelta(duration_input)
            mandatory_date = today + duration

            if prompt("Go mandatory on {}?".format(mandatory_date)):
                return update_mandatory(version_contents, mandatory_date,
                                        build_number)
        except EOFError:
            print("")
        except ValueError as e:
            print(e)
Example #5
0
 def test_type(self):
     self.assertIsInstance(timeparser.parsetime('23:44'), datetime.time)
     self.assertIsInstance(timeparser.parsedate('24.3.2013'), datetime.date)
     self.assertIsInstance(timeparser.parsedatetime('24.3.2013,23:44'), datetime.datetime)
     self.assertIsInstance(timeparser.parsetimedelta('24.3.2013,23:44'), datetime.timedelta)
Example #6
0
            # TODO: Python 3 renames raw_input() to input()
            choice = raw_input(prompt + " [y/n] ")
            return choice.lower() == "y"
        except EOFError:
            pass

if not prompt("Will this build be mandatory?"):
    write_version()
    exit()

print("Durations can be things like '1 week' or '5 days'.")
today = datetime.datetime.now().date()
while True:
    try:
        duration_input = raw_input("How long until until mandatory? ")
        duration = timeparser.parsetimedelta(duration_input)
        mandatory_date = today + duration

        if prompt("Go mandatory on {}?".format(mandatory_date)):
            break
    except EOFError:
        print("")
    except ValueError as e:
        print(e)


def replace(match, value):
    contents, replacements = match.subn(value, version_contents)
    if replacements != 1:
        print("Cannot substitute '{}'".format(value))
        exit(1)