<commit_before>import logging
import os.path

import internetarchive

from terroroftinytown.tracker.bootstrap import Bootstrap


logger = logging.getLogger(__name__)


class IAUploaderBootstrap(Bootstrap):
    def setup_args(self):
        super().setup_args()
        self.arg_parser.add_argument('directory')
        self.arg_parser.add_argument('--title', required=True)
        self.arg_parser.add_argument('--identifier', required=True)

    def start(self, args=None):
        super().start(args=args)

        directory = self.args.directory

        if not os.path.isdir(directory):
            raise Exception('Path is not a directory')

        contents = [os.path.join(directory, filename)
                    for filename in os.listdir(directory)]

        for filename in contents:
            if not os.path.isfile(filename):
                raise Exception('{} is not a file'.format(filename))

        identifier = self.args.identifier
        title = self.args.title
        collection = self.config['iaexporter']['collection']
        access_key = self.config['iaexporter']['access_key']
        secret_key = self.config['iaexporter']['secret_key']
        description = self.config['iaexporter']['description']

        assert identifier
        assert title
        assert collection
        assert access_key
        assert secret_key
        assert description

        item = internetarchive.get_item(identifier)
        metadata = dict(
            title=title,
            collection=collection,
            mediatype='software',
            subject='urlteam;terroroftinytown',
            description=description,
        )

        logger.info('Begin upload %s %s.', identifier, contents)

        item.upload(contents, metadata=metadata, verify=True, verbose=True,
                    access_key=access_key, secret_key=secret_key, retries=10)

        logger.info('Done upload.')

<commit_msg>release.iaupload: Abstract code into baseuploader<commit_after>import logging

import internetarchive

from terroroftinytown.release.baseuploader import BaseUploaderBootstrap


logger = logging.getLogger(__name__)


class IAUploaderBootstrap(BaseUploaderBootstrap):
    def upload(self):
        item = internetarchive.get_item(self.identifier)
        metadata = dict(
            title=self.title,
            collection=self.collection,
            mediatype='software',
            subject='urlteam;terroroftinytown',
            description=self.description,
        )

        logger.info('Begin upload %s %s.', self.identifier, self.filenames)

        item.upload(self.filenames, metadata=metadata,
                    verify=True, verbose=True,
                    access_key=self.access_key, secret_key=self.secret_key,
                    retries=10)

        logger.info('Done upload.')


{'fraction_non_alphanumeric': 0.09712867777383906, 'fraction_numerical': 0.0014179369018078695, 'mean_word_length': 2.5857687420584496, 'pattern_counts': {'":': 0, '<': 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': '5984671', 'n_tokens_mistral': 755, 'n_tokens_neox': 722, 'n_words': 147}