def getSMW_WikiUser(wikiId="smw"): ''' get semantic media wiki users for SemanticMediawiki.org and openresearch.org ''' iniFile = WikiUser.iniFilePath(wikiId) wikiUser = None if not os.path.isfile(iniFile): wikiDict = None if wikiId == "smw": wikiDict = { "wikiId": wikiId, "url": "https://www.semantic-mediawiki.org", "scriptPath": "/w", "version": "MediaWiki 1.31.7" } if wikiId == "or": wikiDict = { "wikiId": wikiId, "url": "https://www.openresearch.org", "scriptPath": "/mediawiki/", "version": "MediaWiki 1.31.1" } if wikiDict is None: raise Exception("%s missing for wikiId %s" % (iniFile, wikiId)) else: wikiUser = WikiUser.ofDict(wikiDict, lenient=True) if getpass.getuser() == "travis": wikiUser.save() else: wikiUser = WikiUser.ofWikiId(wikiId, lenient=True) return wikiUser
def getSMW_WikiUser(wikiId="cr"): ''' get semantic media wiki users for SemanticMediawiki.org and openresearch.org ''' iniFile = WikiUser.iniFilePath(wikiId) wikiUser = None if not os.path.isfile(iniFile): wikiDict = None if wikiId == "smwcopy": wikiDict = { "wikiId": wikiId, "email": "*****@*****.**", "url": "http://smw.bitplan.com", "scriptPath": "", "version": "MediaWiki 1.35.0" } elif wikiId == "cr": wikiDict = { "wikiId": wikiId, "email": "*****@*****.**", "url": "http://cr.bitplan.com", "scriptPath": "", "version": "MediaWiki 1.33.4" } elif wikiId == "smw": wikiDict = { "wikiId": wikiId, "email": "*****@*****.**", "url": "https://www.semantic-mediawiki.org", "scriptPath": "/w", "version": "MediaWiki 1.31.7" } elif wikiId == "or": wikiDict = { "wikiId": wikiId, "email": "*****@*****.**", "url": "https://www.openresearch.org", "scriptPath": "/mediawiki/", "version": "MediaWiki 1.31.1" } elif wikiId == 'wiki': wikiDict = { "wikiId": wikiId, "email": "*****@*****.**", "url": "http://wiki.bitplan.com", "scriptPath": "", "version": "MediaWiki 1.27.3" } if wikiDict is None: raise Exception("%s missing for wikiId %s" % (iniFile, wikiId)) else: wikiUser = WikiUser.ofDict(wikiDict, lenient=True) user = getpass.getuser() print("user is: %s" % user) # check the continuous integration users if user == "travis" or user == "runner": wikiUser.save() else: wikiUser = WikiUser.ofWikiId(wikiId, lenient=True) return wikiUser
def getSMW_Wiki(wikiId="or"): iniFile = WikiUser.iniFilePath(wikiId) if not os.path.isfile(iniFile): wikiUser = OpenResearch.createWikiUser(wikiId) wikiUser.save() wikibot = WikiBot.ofWikiUser(wikiUser) else: wikibot = WikiBot.ofWikiId(wikiId, lenient=True) return wikibot
def checkFamily(self): ''' check if a family file exists and if not create it ''' iniFile = WikiUser.iniFilePath(self.wikiUser.wikiId) famfile = iniFile.replace(".ini", ".py") if not isfile(famfile): print("creating family file %s" % famfile) template = '''# -*- coding: utf-8 -*- from pywikibot import family class Family(family.Family): name = '%s' langs = { 'en': '%s', } def scriptpath(self, code): return '%s' def isPublic(self): return %s def version(self, code): return "%s" # The MediaWiki version used. Very important in most cases. (contrary to documentation) def protocol(self, code): return '%s' ''' mw_version = self.wikiUser.version.lower().replace( "mediawiki ", "") ispublic = 'False' if self.wikiUser.user is not None else 'True' code = template % (self.family, self.netloc, self.scriptPath, ispublic, mw_version, self.scheme) with open(famfile, "w") as py_file: py_file.write(code) config2.register_family_file(self.family, famfile) if self.wikiUser.user: config2.usernames[self.family]['en'] = self.wikiUser.user #config2.authenticate[self.netloc] = (self.user,self.getPassword()) self.site = pywikibot.Site('en', self.family) if self.wikiUser.user is not None: # needs patch as outlined in https://phabricator.wikimedia.org/T248471 #self.site.login(password=self.wikiUser.getPassword()) lm = LoginManager(password=self.wikiUser.getPassword(), site=self.site, user=self.wikiUser.user) lm.login()
def getSMW_WikiUser(wikiId="smw"): ''' get semantic media wiki users for SemanticMediawiki.org and openresearch.org ''' iniFile = WikiUser.iniFilePath(wikiId) wikiUser = None if not os.path.isfile(iniFile): wikiDict = None if wikiId == "smwcopy": wikiDict = { "wikiId": wikiId, "email": "*****@*****.**", "url": "http://smw.bitplan.com", "scriptPath": "", "version": "MediaWiki 1.35.0" } if wikiId == "smw": wikiDict = { "wikiId": wikiId, "email": "*****@*****.**", "url": "https://www.semantic-mediawiki.org", "scriptPath": "/w", "version": "MediaWiki 1.31.7" } if wikiId == "or": wikiDict = { "wikiId": wikiId, "email": "*****@*****.**", "url": "https://www.openresearch.org", "scriptPath": "/mediawiki/", "version": "MediaWiki 1.31.1" } if wikiDict is None: raise Exception("%s missing for wikiId %s" % (iniFile, wikiId)) else: wikiUser = WikiUser.ofDict(wikiDict, lenient=True) if TestWikiUser.inPublicCI(): wikiUser.save() else: wikiUser = WikiUser.ofWikiId(wikiId, lenient=True) return wikiUser
def checkIniFile(wikiId:str,save=None): ''' check the ini file for the given wikiId Args: wikiId(str): the wiki id of the wiki to check save(bool): True if a new ini file should be created e.g. for test purposes if not set save is True if we are running in a public continuous integration environment ''' if save is None: save=Wiki.inPublicCI() iniFile = WikiUser.iniFilePath(wikiId) if not os.path.isfile(iniFile): wikiDict = None if wikiId == "wiki": wikiDict = {"wikiId": wikiId, "email": "*****@*****.**", "url": "https://wiki.bitplan.com", "scriptPath": "/", "version": "MediaWiki 1.35.1"} if wikiDict is None: raise Exception(f"wikiId {wikiId} is not configured in $HOME.mediawiki-japi") else: wikiUser = WikiUser.ofDict(wikiDict, lenient=True) if save: wikiUser.save() pass