Example #1
0
def main(req_files=[], verbose=False, outdated=False, latest=False, verbatim=False, print_only=False):
    """
        Process a list of requirements to determine how out of date they are.
    """
    requirements = []
    for req_file in req_files:
        requirements.extend(parse_req_file(req_file, verbatim=verbatim))
        req_file.close()

    total_time_delta = 0

    if USE_PIPROT_IO:
        only_requirements = {}
        for req, version in requirements:
            if req:
                only_requirements[req] = version
        release_data = bulk_get_version_and_release_dates(only_requirements)
    else:
        release_data = None

    for req, version in requirements:
        if print_only:
            if req:
                print("{}=={}".format(req, version))
            else:
                print(version)
        elif verbatim and not req:
            sys.stdout.write(version)
        elif req:
            latest_version, latest_release_date = get_version_and_release_date(req, verbose=verbose, release_data=release_data)
            specified_version, specified_release_date = get_version_and_release_date(req, version, verbose=verbose, release_data=release_data)

            if latest_release_date and specified_release_date:
                time_delta = (latest_release_date - specified_release_date).days
                total_time_delta = total_time_delta + time_delta

                if verbose:
                    if time_delta > 0:
                        print('{} ({}) is {} days out of date. Latest is {}'.format(req, version, time_delta, latest_version))
                    elif not outdated:
                        print('{} ({}) is up to date'.format(req, version))

                if latest and latest_version != specified_version:
                    print('{}=={} # Updated from {}'.format(req, latest_version, specified_version))
                elif verbatim and latest_version != specified_version:
                    print('{}=={} # Latest {}'.format(req, specified_version, latest_version))
                elif verbatim:
                    print('{}=={}'.format(req, specified_version))
            elif verbatim:
                print('{}=={} # Error checking latest version'.format(req, version))

    if verbatim:
        verbatim = "# Generated with piprot {}\n# ".format(VERSION)
    else:
        verbatim = ""
    if total_time_delta > 0:
        print("{}Your requirements are {} days out of date".format(verbatim, total_time_delta))
    else:
        print("{}Looks like you've been keeping up to date, time for a delicious beverage!".format(verbatim))
Example #2
0
 def test_fresh_package(self):
     v1, r1 = get_version_and_release_date('request')
     v2, r2 = get_version_and_release_date('request', v1)
     self.assertEqual(v1, v2)
     self.assertEqual(r1, r2)
Example #3
0
 def test_rotten_package(self):
     v1, r1 = get_version_and_release_date('requests', '1.1.0')
     v2, r2 = get_version_and_release_date('request')
     self.assertNotEqual(v1, v2)
     self.assertNotEqual(r1, r2)
Example #4
0
 def test_pytz_package(self):
     v1, r1 = get_version_and_release_date('pytz', '2015.4')
     v2, r1 = get_version_and_release_date('pytz', '2010l')
     self.assertTrue(v2 < v1)
Example #5
0
 def test_bad_version_number(self):
     v1, r1 = get_version_and_release_date('unidecode', '0.4.21')
     v1, r1 = get_version_and_release_date('unidecode', '0.04.21')
Example #6
0
 def test_bad_version_number(self):
     v1, r1 = get_version_and_release_date('unidecode', '0.4.21')
     v1, r1 = get_version_and_release_date('unidecode', '0.04.21')