def main(*args): """ Process command line arguments and invoke bot. If args is an empty list, sys.argv is used. :param args: command line arguments :type args: str """ options = {} # Process global args and prepare generator args parser local_args = pywikibot.handle_args(args) genFactory = pagegenerators.GeneratorFactory() # Check whether we're running on Wikibase site or not # FIXME: See T85483 and run() in WikidataBot site = pywikibot.Site() data_site = site.data_repository() use_wikibase = (data_site is not None and data_site.family == site.family and data_site.code == site.code) for arg in local_args: if arg.startswith('-prop-isbn-10:'): options[arg[1:len('-prop-isbn-10')]] = arg[len('-prop-isbn-10:'):] elif arg.startswith('-prop-isbn-13:'): options[arg[1:len('-prop-isbn-13')]] = arg[len('-prop-isbn-13:'):] elif arg.startswith('-') and arg[1:] in ('always', 'to13', 'format'): options[arg[1:]] = True else: genFactory.handle_arg(arg) gen = genFactory.getCombinedGenerator(preload=True) deps = [] if not (has_module('stdnum', version='1.13') or has_module('isbnlib', version='3.9.10')): deps = ["'python-stdnum >= 1.13' or 'isbnlib >= 3.9.10'"] if pywikibot.bot.suggest_help(missing_generator=not gen, missing_dependencies=deps): return if use_wikibase: bot = IsbnWikibaseBot(generator=gen, **options) else: bot = IsbnBot(generator=gen, **options) bot.run()
def setUpClass(cls): """Check whether bs4 module is installed already.""" if not has_module('bs4'): unittest_print('all tests ({module}.{name})\n{doc}.. '.format( module=__name__, doc=cls.__doc__, name=cls.__name__), end='\n') cls.skipTest(cls, 'bs4 not installed') super().setUpClass()
def setUpClass(cls): """Check whether bs4 module is installed already.""" if not has_module('bs4'): unittest_print('all tests ({module}.{name})\n{doc} ... '.format( module=__name__, doc=cls.__doc__, name=cls.__name__), end='') # skipTest cannot be used with Python 2 for setUpClass raise unittest.SkipTest('bs4 not installed') super(BS4TestCase, cls).setUpClass()
def check_script_deps(script_name): """Detect whether all dependencies are installed.""" if script_name in script_deps: for package_name in script_deps[script_name]: if not has_module(package_name): unittest_print( "{} depends on {}, which isn't available".format( script_name, package_name)) return False return True
def main(*args): """ Process command line arguments and invoke bot. If args is an empty list, sys.argv is used. @param args: command line arguments @type args: list of unicode """ options = {} gen = None local_args = pywikibot.handle_args(args) # This factory is responsible for processing command line arguments # that are also used by other scripts and that determine on which pages # to work on. genFactory = pagegenerators.GeneratorFactory(positional_arg_name='page') for arg in local_args: option, sep, value = arg.partition(':') if option == '-xml': filename = value or pywikibot.input( "Please enter the XML dump's filename:") gen = TableXmlDumpPageGenerator(filename) elif option == '-auto': issue_deprecation_warning('The usage of "-auto"', '-always', 1, ArgumentDeprecationWarning) options['always'] = True elif option in ['-always', '-quiet', '-skipwarning']: options[option[1:]] = True else: if option in ['-sql', '-mysqlquery']: if not (has_module('oursql') or has_module('MySQLdb')): raise NotImplementedError( 'Neither "oursql" nor "MySQLdb" library is installed.') if option == '-sql': issue_deprecation_warning('The usage of "-sql"', '-mysqlquery', 1, ArgumentDeprecationWarning) query = value or """ SELECT page_namespace, page_title FROM page JOIN text ON (page_id = old_id) WHERE old_text LIKE '%<table%' """ arg = '-mysqlquery:' + query genFactory.handleArg(arg) if gen: gen = pagegenerators.NamespaceFilterPageGenerator( gen, genFactory.namespaces) else: gen = genFactory.getCombinedGenerator() if gen: if not genFactory.nopreload: gen = pagegenerators.PreloadingGenerator(gen) bot = Table2WikiRobot(generator=gen, **options) bot.run() return True else: suggest_help(missing_generator=True) return False
def main(*args): """ Process command line arguments and invoke bot. If args is an empty list, sys.argv is used. @param args: command line arguments @type args: list of unicode """ options = {} gen = None local_args = pywikibot.handle_args(args) # This factory is responsible for processing command line arguments # that are also used by other scripts and that determine on which pages # to work on. genFactory = pagegenerators.GeneratorFactory(positional_arg_name='page') for arg in local_args: option, sep, value = arg.partition(':') if option == '-xml': filename = value or pywikibot.input( "Please enter the XML dump's filename:") gen = TableXmlDumpPageGenerator(filename) elif option == '-auto': issue_deprecation_warning( 'The usage of "-auto"', '-always', 1, ArgumentDeprecationWarning) options['always'] = True elif option in ['-always', '-quiet', '-skipwarning']: options[option[1:]] = True else: if option in ['-sql', '-mysqlquery']: if not (has_module('oursql') or has_module('MySQLdb')): raise NotImplementedError( 'Neither "oursql" nor "MySQLdb" library is installed.') if option == '-sql': issue_deprecation_warning( 'The usage of "-sql"', '-mysqlquery', 1, ArgumentDeprecationWarning) query = value or """ SELECT page_namespace, page_title FROM page JOIN text ON (page_id = old_id) WHERE old_text LIKE '%<table%' """ arg = '-mysqlquery:' + query genFactory.handleArg(arg) if gen: gen = pagegenerators.NamespaceFilterPageGenerator( gen, genFactory.namespaces) else: gen = genFactory.getCombinedGenerator() if gen: if not genFactory.nopreload: gen = pagegenerators.PreloadingGenerator(gen) bot = Table2WikiRobot(generator=gen, **options) bot.run() return True else: suggest_help(missing_generator=True) return False
def test_when_insufficient_version(self): """Test when the module is older than what we need.""" self.assertFalse(has_module('setuptools', '99999'))
def test_when_missing(self): """Test when the module is unavailable.""" self.assertFalse(has_module('no-such-module'))
def test_when_present(self): """Test when the module is available.""" self.assertTrue(has_module('setuptools')) self.assertTrue(has_module('setuptools', '1.0'))
def setUpModule(): # noqa: N802 """Skip tests if isbn libraries are missing.""" if not (has_module('stdnum', version='1.14') or has_module('isbnlib', version='3.10.3')): raise unittest.SkipTest('neither python-stdnum nor isbnlib available.')
def setUpClass(cls): # noqa: N802 """Skip tests if isbn libraries are missing.""" if not has_module('stdnum', version='1.17'): raise unittest.SkipTest('python-stdnum is not available.') super().setUpClass()