<commit_before>#!/usr/bin/python
import os, sys, json

package_directory = os.environ.get('DUSERVER_PACKAGE_DIR')
if package_directory is None:
    print("Requires $DUSERVER_PACKAGE_DIR to be set to the package directory")
    exit()

base_url = os.environ.get('DUSERVER_PACKAGE_BASE_URL')
if base_url is None:
    print("Requires $DUSERVER_PACKAGE_BASE_URL to be set to the base url.")
    exit()

try:
    files = os.listdir(package_directory)
except OSError:
    print('Not a valid directory.')
    exit()

packages = {}
for filename in files:
    # Chop off the segment after the last period and split on '-'
    package_parts = '.'.join(filename.split(".")[:-1]).split("-")
    # Extract version string
    version = package_parts.pop()
    # Extract module string
    module = '-'.join(package_parts)

    # If both strings are non-empty
    if module and version:
        # Create package index
        packages[module] = packages.get(module, [])
        packages[module].append(
            {"version": version, "src": "%s/%s" % (base_url, filename)})

# Write each package index to their respective files
for module in packages:
    open('%s/%s.json' % (package_directory, module), 'w').write(
        json.dumps(packages[module]))<commit_msg>Added sorting to the list<commit_after>#!/usr/bin/python
import os, sys, json
from distutils.version import StrictVersion

package_directory = os.environ.get('DUSERVER_PACKAGE_DIR')
if package_directory is None:
    print("Requires $DUSERVER_PACKAGE_DIR to be set to the package directory")
    exit()

base_url = os.environ.get('DUSERVER_PACKAGE_BASE_URL')
if base_url is None:
    print("Requires $DUSERVER_PACKAGE_BASE_URL to be set to the base url.")
    exit()

try:
    files = os.listdir(package_directory)
except OSError:
    print('Not a valid directory.')
    exit()

packages = {}
for filename in files:
    # Chop off the segment after the last period and split on '-'
    package_parts = '.'.join(filename.split(".")[:-1]).split("-")
    # Extract version string
    version = package_parts.pop()
    # Extract module string
    module = '-'.join(package_parts)

    # If both strings are non-empty
    if module and version:
        try:
            version = StrictVersion(version)
        except ValueError:
            continue
        # Create package index
        packages[module] = packages.get(module, [])
        packages[module].append(
            {"version": str(version), "src": "%s/%s" % (base_url, filename)})

# Write each package index to their respective files
for module in packages:
    # Order the packages on their version label
    package_list = sorted(packages[module], key=lambda x:
            StrictVersion(x['version']))
    # Write the index file
    open('%s/%s.json' % (package_directory, module), 'w').write(
        json.dumps(package_list))
{'fraction_non_alphanumeric': 0.11967617036254839, 'fraction_numerical': 0.0007039774727208729, 'mean_word_length': 3.3858024691358026, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1034716', 'n_tokens_mistral': 858, 'n_tokens_neox': 859, 'n_words': 255}