ExtensionCrawler/cdnjs-crawler

86 lines
2.6 KiB
Python
Executable File

#!/usr/bin/env python3.5
#
# Copyright (C) 2016,2017 The University of Sheffield, UK
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
""" Tool for obtaining md5/sha1/sha256 hashes for all files available
at CDNJS.com."""
import getopt
import logging
import sys
from ExtensionCrawler.cdnjs import (update_jslib_archive, update_md5_map_file,
update_sha1_map_file)
from ExtensionCrawler.config import (const_log_format, const_basedir)
# Script should run with python 3.4 or 3.5
assert sys.version_info >= (3, 4) and sys.version_info < (3, 6)
def helpmsg():
"""Print help message."""
print("cdnjs-crawler [OPTION]")
print(" -h print this help text")
print(" -s silent (no log messages)")
print(" -f force full download (default: update of json files)")
print(" -c delete outdated (no longer available) libraries")
print(" -a=<DIR> archive directory")
def main(argv):
"""Main function of the extension crawler."""
basedir = const_basedir()
verbose = True
force = False
clean = False
try:
opts, args = getopt.getopt(argv, "hsed:a:o:w",
["date=", "archive=", "output="])
except getopt.GetoptError:
helpmsg()
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
helpmsg()
sys.exit()
elif opt in ("-a", "--archive"):
basedir = arg
elif opt == '-s':
verbose = False
elif opt == '-f':
force = True
elif opt == '-c':
clean = True
if verbose:
loglevel = logging.INFO
else:
loglevel = logging.WARNING
logger = logging.getLogger()
ch = logging.StreamHandler(sys.stdout)
ch.setFormatter(logging.Formatter(const_log_format()))
logger.addHandler(ch)
logger.setLevel(loglevel)
update_jslib_archive(force, clean, basedir)
update_sha1_map_file(basedir)
update_md5_map_file(basedir)
if __name__ == "__main__":
main(sys.argv[1:])