2017-01-23 18:54:32 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import glob
|
|
|
|
import re
|
2017-01-27 22:31:21 +00:00
|
|
|
import requests
|
2017-01-28 01:12:50 +00:00
|
|
|
from time import sleep
|
|
|
|
from random import randint
|
2017-01-27 22:31:21 +00:00
|
|
|
from datetime import datetime, timezone
|
2017-01-28 12:52:18 +00:00
|
|
|
from ExtensionCrawler.discover import *
|
|
|
|
from ExtensionCrawler.archive import *
|
|
|
|
from ExtensionCrawler.util import *
|
2017-01-28 13:12:47 +00:00
|
|
|
from ExtensionCrawler.discover import *
|
2017-01-28 11:59:53 +00:00
|
|
|
import dateutil
|
|
|
|
import dateutil.parser
|
2017-01-23 18:54:32 +00:00
|
|
|
|
2017-01-28 01:25:24 +00:00
|
|
|
|
|
|
|
def log_summary(verbose, res):
|
|
|
|
total = len(res)
|
|
|
|
success = len(list(filter(lambda x: x.is_ok(), res)))
|
2017-01-28 00:51:21 +00:00
|
|
|
not_authorized = len(list(filter(lambda x: x.not_authorized(), res)))
|
2017-01-28 01:25:24 +00:00
|
|
|
has_exception = len(list(filter(lambda x: x.has_exception(), res)))
|
|
|
|
raised_ddos = len(list(filter(lambda x: x.raised_google_ddos(), res)))
|
|
|
|
not_in_store = len(list(filter(lambda x: x.not_in_store(), res)))
|
2017-01-28 12:21:52 +00:00
|
|
|
not_modified = len(list(filter(lambda x: x.not_modified(), res)))
|
2017-01-28 00:21:37 +00:00
|
|
|
log(verbose, "\n")
|
|
|
|
log(verbose, "Summary:\n")
|
2017-01-28 01:25:24 +00:00
|
|
|
log(verbose, " Updated {} out of {} extensions successfully\n".format(
|
|
|
|
str(success), str(total)))
|
2017-01-28 13:15:05 +00:00
|
|
|
log(verbose,
|
|
|
|
" Not authorized: {}\n".format(str(not_authorized)))
|
2017-01-28 12:21:52 +00:00
|
|
|
log(verbose, " Raised Google DDOS: {}\n".format(str(raised_ddos)))
|
2017-01-28 13:12:47 +00:00
|
|
|
log(verbose, " Not modified archives: {}\n".format(str(not_modified)))
|
2017-01-28 12:21:52 +00:00
|
|
|
log(verbose, " Extensions not in store: {}\n".format(str(not_in_store)))
|
2017-01-28 13:15:05 +00:00
|
|
|
log(verbose,
|
|
|
|
" Unknown exception: {}\n".format(str(has_exception)))
|
2017-01-28 01:25:24 +00:00
|
|
|
|
2017-01-26 03:53:16 +00:00
|
|
|
|
2017-01-23 18:54:32 +00:00
|
|
|
def main():
|
2017-01-25 19:43:10 +00:00
|
|
|
basedir = "."
|
2017-01-26 03:53:16 +00:00
|
|
|
archive_dir = os.path.join(basedir, "archive")
|
|
|
|
conf_dir = os.path.join(basedir, "conf")
|
2017-01-24 22:04:34 +00:00
|
|
|
verbose = True
|
2017-01-26 03:53:16 +00:00
|
|
|
skip_discovery = True
|
2017-01-23 18:54:32 +00:00
|
|
|
|
2017-01-27 23:16:48 +00:00
|
|
|
log(verbose, "Configuration:\n")
|
|
|
|
log(verbose, " Base dir: {}\n".format(basedir))
|
|
|
|
log(verbose, " Archive dir: {}\n".format(archive_dir))
|
|
|
|
log(verbose, " Conf. dir: {}\n".format(conf_dir))
|
|
|
|
log(verbose, " Skip discovery: {}\n".format(skip_discovery))
|
2017-01-28 01:00:23 +00:00
|
|
|
log(verbose, "\n".format(skip_discovery))
|
2017-01-27 22:31:21 +00:00
|
|
|
|
2017-01-26 03:53:16 +00:00
|
|
|
forum_ext_ids = get_forum_ext_ids(conf_dir, verbose)
|
|
|
|
existing_ids = get_existing_ids(archive_dir, verbose)
|
|
|
|
known_ids = list(set(existing_ids) | set(forum_ext_ids))
|
|
|
|
new_ids = []
|
|
|
|
if not skip_discovery:
|
|
|
|
new_ids = get_new_ids(verbose, known_ids)
|
|
|
|
|
2017-01-28 01:25:24 +00:00
|
|
|
res = update_extensions(archive_dir, verbose, forum_ext_ids, existing_ids,
|
|
|
|
new_ids)
|
2017-01-23 18:54:32 +00:00
|
|
|
|
2017-01-28 00:21:37 +00:00
|
|
|
log_summary(verbose, res)
|
2017-01-23 18:54:32 +00:00
|
|
|
|
2017-01-28 01:25:24 +00:00
|
|
|
|
2017-01-23 18:54:32 +00:00
|
|
|
main()
|