def main(): usage = "Usage: %prog [-c CONFIG] [-a CLASSIFIERS] [-u URL] [-o OUTPUT_DIRECTORY] [FILE...]" description = ("Generate a Maven repository based on a file (or files) containing " "a list of artifacts. Each list file must contain a single artifact " "per line in the format groupId:artifactId:fileType:<classifier>:version " "The example artifact list contains more information. Another usage is " "to provide Artifact List Generator configuration file. There is also " "sample configuration file in examples.") cliOptParser = optparse.OptionParser(usage=usage, description=description) cliOptParser.add_option( '-c', '--config', dest='config', help='Configuration file to use for generation of an artifact list for the repository builder' ) cliOptParser.add_option( '-u', '--url', default='http://repo1.maven.org/maven2/', help='Comma-separated list of URLs of the remote repositories from which artifacts ' 'are downloaded. It is used along with artifact list files when no config file ' 'is specified.' ) cliOptParser.add_option( '-o', '--output', default='local-maven-repository/maven-repository', help='Local output directory for the new repository' ) cliOptParser.add_option( '-a', '--classifiers', default='sources', help='Comma-separated list of additional classifiers to download. It is possible to use "__all__" to ' 'request all available classifiers (works only when artifact list is generated from config). There ' 'can be a type specified with each classifiers separated by colon, e.g. sources:jar. The old way ' 'of separation of classifiers by colon is deprecated' ) cliOptParser.add_option( '-s', '--checksummode', default=ChecksumMode.generate, choices=(ChecksumMode.generate, ChecksumMode.download, ChecksumMode.check), help='Mode of dealing with MD5 and SHA1 checksums. Possible choices are: ' 'generate - generate the checksums (default) ' 'download - download the checksums if available, if not, generate them ' 'check - check if downloaded and generated checksums are equal' ) cliOptParser.add_option( '-x', '--excludedtypes', default='zip:ear:war:tar:gz:tar.gz:bz2:tar.bz2:7z:tar.7z', help='Colon-separated list of filetypes to exclude. Defaults to ' 'zip:ear:war:tar:gz:tar.gz:bz2:tar.bz2:7z:tar.7z.' ) cliOptParser.add_option( '-w', '--whitelist', help='Name of a file containing GATCV patterns allowing usage of stars or regular expressions when enclosed ' 'in "r/pattern/". It can force inclusion of artifacts with excluded types.' ) cliOptParser.add_option( "-O", '--reportdir', dest="reportdir", default=None, help='Dir where to generate the repository analysis report. If not specified no report will be generated.' ) cliOptParser.add_option( '-l', '--loglevel', default='info', help='Set the level of log output. Can be set to debug, info, warning, error, or critical' ) cliOptParser.add_option( '-L', '--logfile', help='Set the file in which the log output should be written.' ) (options, args) = cliOptParser.parse_args() # Set the log level maven_repo_util.setLogLevel(options.loglevel, options.logfile) # generate lists of artifacts from configuration and the fetch them each list from it's repo artifactList = artifact_list_generator.generateArtifactList(options, args) artifact_downloader.fetchArtifactLists(artifactList, options.output, options.checksummode) logging.info('Generating missing checksums...') generateChecksums(options.output) logging.info('Repository created in directory: %s', options.output) #cleanup maven_repo_util.cleanTempDir()
def main(): usage = "Usage: %prog [-c CONFIG] [-a CLASSIFIERS] [-u URL] [-o OUTPUT_DIRECTORY] [FILE...]" description = ("Generate a Maven repository based on a file (or files) containing " "a list of artifacts. Each list file must contain a single artifact " "per line in the format groupId:artifactId:fileType:<classifier>:version " "The example artifact list contains more information. Another usage is " "to provide Artifact List Generator configuration file. There is also " "sample configuration file in examples.") # TODO: pkocandr - use argparse instead of optparse, which is deprecated since python 2.7 cliOptParser = optparse.OptionParser(usage=usage, description=description) cliOptParser.add_option( '-c', '--config', dest='config', help='Configuration file to use for generation of an artifact list for the repository builder' ) cliOptParser.add_option( '-u', '--url', default='http://repo1.maven.org/maven2/', help='URL of the remote repository from which artifacts are downloaded. ' 'It is used along with artifact list files when no config file is specified.' ) cliOptParser.add_option( '-o', '--output', default='local-maven-repository', help='Local output directory for the new repository' ) cliOptParser.add_option( '-a', '--classifiers', default='sources', help='Colon-separated list of additional classifiers to download. It is ' 'possible to use "__all__" to request all available classifiers ' '(works only when artifact list is generated from config).' ) cliOptParser.add_option( '-s', '--checksummode', default=ChecksumMode.generate, choices=(ChecksumMode.generate, ChecksumMode.download, ChecksumMode.check), help='Mode of dealing with MD5 and SHA1 checksums. Possible choices are: ' 'generate - generate the checksums (default) ' 'download - download the checksums if available, if not, generate them ' 'check - check if downloaded and generated checksums are equal' ) cliOptParser.add_option( '-x', '--excludedtypes', default='zip:ear:war:tar:gz:tar.gz:bz2:tar.bz2:7z:tar.7z', help='Colon-separated list of filetypes to exclude. Defaults to ' 'zip:ear:war:tar:gz:tar.gz:bz2:tar.bz2:7z:tar.7z.' ) cliOptParser.add_option( '-l', '--loglevel', default='info', help='Set the level of log output. Can be set to debug, info, warning, error, or critical' ) cliOptParser.add_option( '-L', '--logfile', help='Set the file in which the log output should be written.' ) (options, args) = cliOptParser.parse_args() # Set the log level maven_repo_util.setLogLevel(options.loglevel, options.logfile) if not options.classifiers or options.classifiers == '__all__': classifiers = [] else: classifiers = options.classifiers.split(":") if not options.excludedtypes: excludedtypes = [] else: excludedtypes = options.excludedtypes.split(":") if options.config is None: if len(args) < 1: logging.error('Missing required command line argument: path to artifact list file') sys.exit(usage) # Read the list(s) of dependencies from the specified files artifacts = [] for filename in args: if not os.path.isfile(filename): logging.warning('Dependency list file does not exist, skipping: %s', filename) continue logging.info('Reading artifact list from file: %s', filename) depListFile = open(filename) try: dependencyListLines = depListFile.readlines() artifacts.extend(depListToArtifactList(dependencyListLines)) except IOError as e: logging.exception('Unable to read file %s: %s', filename, str(e)) sys.exit(1) finally: depListFile.close() fetchArtifacts(options.url, options.output, artifacts, classifiers, excludedtypes, options.checksummode) else: # generate lists of artifacts from configuration and the fetch them each list from it's repo artifactList = artifact_list_generator.generateArtifactList(options) for repoUrl in artifactList.keys(): artifacts = artifactList[repoUrl] fetchArtifacts(repoUrl, options.output, artifacts, classifiers, excludedtypes, options.checksummode) logging.info('Generating missing checksums...') generateChecksums(options.output) logging.info('Repository created in directory: %s', options.output) #cleanup maven_repo_util.cleanTempDir()
def main(): usage = "Usage: %prog [-c CONFIG] [-a CLASSIFIERS] [-u URL] [-o OUTPUT_DIRECTORY] [FILE...]" description = ( "Generate a Maven repository based on a file (or files) containing " "a list of artifacts. Each list file must contain a single artifact " "per line in the format groupId:artifactId:fileType:<classifier>:version " "The example artifact list contains more information. Another usage is " "to provide Artifact List Generator configuration file. There is also " "sample configuration file in examples.") # TODO: pkocandr - use argparse instead of optparse, which is deprecated since python 2.7 cliOptParser = optparse.OptionParser(usage=usage, description=description) cliOptParser.add_option( '-c', '--config', dest='config', help= 'Configuration file to use for generation of an artifact list for the repository builder' ) cliOptParser.add_option( '-u', '--url', default='http://repo1.maven.org/maven2/', help='URL of the remote repository from which artifacts are downloaded. ' 'It is used along with artifact list files when no config file is specified.' ) cliOptParser.add_option( '-o', '--output', default='local-maven-repository', help='Local output directory for the new repository') cliOptParser.add_option( '-a', '--classifiers', default='sources', help='Colon-separated list of additional classifiers to download. It is ' 'possible to use "__all__" to request all available classifiers ' '(works only when artifact list is generated from config).') cliOptParser.add_option( '-s', '--checksummode', default=ChecksumMode.generate, choices=(ChecksumMode.generate, ChecksumMode.download, ChecksumMode.check), help= 'Mode of dealing with MD5 and SHA1 checksums. Possible choices are: ' 'generate - generate the checksums (default) ' 'download - download the checksums if available, if not, generate them ' 'check - check if downloaded and generated checksums are equal') cliOptParser.add_option( '-x', '--excludedtypes', default='zip:ear:war:tar:gz:tar.gz:bz2:tar.bz2:7z:tar.7z', help='Colon-separated list of filetypes to exclude. Defaults to ' 'zip:ear:war:tar:gz:tar.gz:bz2:tar.bz2:7z:tar.7z.') cliOptParser.add_option( '-l', '--loglevel', default='info', help= 'Set the level of log output. Can be set to debug, info, warning, error, or critical' ) cliOptParser.add_option( '-L', '--logfile', help='Set the file in which the log output should be written.') (options, args) = cliOptParser.parse_args() # Set the log level maven_repo_util.setLogLevel(options.loglevel, options.logfile) if not options.classifiers or options.classifiers == '__all__': classifiers = [] else: classifiers = options.classifiers.split(":") if not options.excludedtypes: excludedtypes = [] else: excludedtypes = options.excludedtypes.split(":") if options.config is None: if len(args) < 1: logging.error( 'Missing required command line argument: path to artifact list file' ) sys.exit(usage) # Read the list(s) of dependencies from the specified files artifacts = [] for filename in args: if not os.path.isfile(filename): logging.warning( 'Dependency list file does not exist, skipping: %s', filename) continue logging.info('Reading artifact list from file: %s', filename) depListFile = open(filename) try: dependencyListLines = depListFile.readlines() artifacts.extend(depListToArtifactList(dependencyListLines)) except IOError as e: logging.exception('Unable to read file %s: %s', filename, str(e)) sys.exit(1) finally: depListFile.close() fetchArtifacts(options.url, options.output, artifacts, classifiers, excludedtypes, options.checksummode) else: # generate lists of artifacts from configuration and the fetch them each list from it's repo artifactList = artifact_list_generator.generateArtifactList(options) for repoUrl in artifactList.keys(): artifacts = artifactList[repoUrl] fetchArtifacts(repoUrl, options.output, artifacts, classifiers, excludedtypes, options.checksummode) logging.info('Generating missing checksums...') generateChecksums(options.output) logging.info('Repository created in directory: %s', options.output) #cleanup maven_repo_util.cleanTempDir()