Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
    def testWikiUser(self):
        '''
        test the wiki user handling
        '''
        if getpass.getuser() == "travis":
            return
        wikiUsers = WikiUser.getWikiUsers()
        for wikiUser in wikiUsers.values():
            print(wikiUser)

        testUser = WikiUser.ofWikiId("test")
        print(testUser)
        pass
Ejemplo n.º 4
0
    def testWikiUser(self):
        '''
        test the wiki user handling
        '''
        if TestWikiUser.inPublicCI(): return
        wikiUsers = WikiUser.getWikiUsers()
        for wikiUser in wikiUsers.values():
            if self.debug:
                print(wikiUser)

        testUser = WikiUser.ofWikiId("test")
        if self.debug:
            print(testUser)
        self.assertEqual("http://test.bitplan.com", testUser.getWikiUrl())
        pass
 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
Ejemplo n.º 6
0
 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 createWikiUser(wikiId="or"):
     wikiDict = {
         "wikiId": wikiId,
         "user": "",
         "email": "",
         "url": "https://www.openresearch.org",
         "scriptPath": "/mediawiki/",
         "version": "MediaWiki 1.31.1"
     }
     wikiUser = WikiUser.ofDict(wikiDict, lenient=True)
     wikiUser.save()
     return wikiUser
Ejemplo n.º 8
0
 def getSMW(self,
            wikiId='orth',
            url='https://confident.dbis.rwth-aachen.de'):
     smw = None
     wikiclient = None
     wusers = WikiUser.getWikiUsers()
     if 'test' in wusers:
         wuser = wusers[wikiId]
         if wuser.url.startswith(url):
             wikiclient = WikiClient.ofWikiUser(wuser)
             smw = SMWClient(wikiclient.getSite())
     return smw, wikiclient
Ejemplo n.º 9
0
 def testCommandLine(self):
     '''
     test command line handling
     '''
     fd, path = tempfile.mkstemp(".ini")
     password = "******"
     try:
         if (fd):
             args = [
                 "--url", "http://wiki.doe.com", "-u", "john", "-e",
                 "*****@*****.**", "-w", "doe", "-s", "", "-v",
                 "MediaWiki 1.35.0", "-p", password, "-f", path, '-y'
             ]
             wikibot.wikiuser.main(args)
     finally:
         if self.debug:
             print(open(path, 'r').read())
         props = WikiUser.readPropertyFile(path)
         rUser = WikiUser.ofDict(props, encrypted=True)
         self.assertEqual(password, rUser.getPassword())
         os.remove(path)
Ejemplo n.º 10
0
 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
Ejemplo n.º 11
0
 def getBots(limit=None, name=None, valueExpr=None):
     bots = {}
     wikiUsers = WikiUser.getWikiUsers().values()
     for wikiUser in wikiUsers:
         selected = True
         if name is not None:
             value = wikiUser.__dict__[name]
             found = re.search(valueExpr, value)
             selected = found is not None
         if selected:
             wikibot = WikiBot(wikiUser)
             bots[wikiUser.wikiId] = wikibot
             if limit is not None and len(bots) >= limit:
                 break
     return bots
Ejemplo n.º 12
0
    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()
Ejemplo n.º 13
0
 def wikis(self) -> str:
     '''
     render the wikis table
     
     Returns:
         str: the html code for the table of wikis
     '''
     wikiUsers = WikiUser.getWikiUsers()
     dictList = []
     for wikiUser in wikiUsers.values():
         url="%s%s/" % (wikiUser.url,wikiUser.scriptPath)
         wikiBackup=WikiBackup(wikiUser)
         dictList.append({
             'wikiId': Link(url,wikiUser.wikiId),
             'url': Link(wikiUser.url,wikiUser.url),
             'scriptPath':wikiUser.scriptPath,
             'version':wikiUser.version,
             'backup': "✅" if wikiBackup.exists() else "❌",
             'git': Icon("github",32) if wikiBackup.hasGit() else ""
         })
     menuList=self.adminMenuList("Wikis")      
     html = render_template("tableview.html", menuList=menuList,title="Wikis", dictList=dictList)
     return html    
Ejemplo n.º 14
0
 def ofWikiId(wikiId):
     wikiUser = WikiUser.ofWikiId(wikiId)
     wikibot = WikiBot(wikiUser)
     return wikibot
Ejemplo n.º 15
0
 def getClients():
     clients = {}
     for wikiUser in WikiUser.getWikiUsers().values():
         wikiClient = WikiClient(wikiUser)
         clients[wikiUser.wikiId] = wikiClient
     return clients
Ejemplo n.º 16
0
 def ofWikiId(wikiId,lenient=True,debug=False):
     wikiUser=WikiUser.ofWikiId(wikiId,lenient=lenient)
     wikibot=WikiClient(wikiUser,debug=debug)
     return wikibot
Ejemplo n.º 17
0
 def ofWikiId(wikiId, lenient=True):
     wikiUser = WikiUser.ofWikiId(wikiId, lenient=lenient)
     wikibot = WikiBot(wikiUser)
     return wikibot
Ejemplo n.º 18
0
 def __init__(self, host=None, port=8334, debug=False):
     '''
     constructor
     '''
     scriptdir = os.path.dirname(os.path.abspath(__file__))
     template_folder=scriptdir + '/../templates'
     if host is None:
         host=socket.gethostname()
     super().__init__(host=host,port=port,debug=debug,template_folder=template_folder,explainTemplateLoading=True)
     
     self.sseBluePrint=SSE_BluePrint(self.app,'sse')
     self.loginBluePrint=LoginBluePrint(self.app,'login',welcome="home")
     # server specific configurations
     link=Link("http://www.bitplan.com",title="BITPlan GmbH")
     self.copyRight=Copyright(period="2020-2022",link=link)
     self.scandir=DMSStorage.getScanDir()
     self.wikiUsers=WikiUser.getWikiUsers()
     self.sqlDB=DMSStorage.getSqlDB()
     self.am=ArchiveManager.getInstance()
     self.fm=FolderManager.getInstance()
     self.dm=DocumentManager.getInstance()
     self.archivesByName,_dup=self.am.getLookup("name")
     
     @self.app.route('/')
     def homeroute():
         return self.home()
     
     @self.app.route('/files')
     @self.app.route('/files/<path:path>')
     def files(path='.'):
         return self.files(path)
     
     @self.app.route('/scandir')
     def showScanDirectory():
         return self.watchDir()
     
     @self.app.route('/archives/getFoldersAndFiles/<name>')
     def getFoldersAndFiles(name:str):
         return self.getFoldersAndFiles(name)
      
     @self.app.route('/archives/refresh')
     def refreshArchives():
         return self.refreshArchives()
      
     @self.app.route('/archives')
     def showArchives():
         return self.showArchives()
     
     @self.app.route('/archive/<name>')
     def showArchive(name:str):
         return self.showArchive(name)
     
     @self.app.route('/folders')
     def showFolders():
         return self.showFolders()
     
     @self.app.route('/folder/<archiveName>/<path:folderPath>/refresh')
     def refreshFolder(archiveName:str=None,folderPath=None):
         return self.refreshFolder(archiveName,f"/{folderPath}")
     
     @self.app.route('/folder/<archiveName>/<path:folderPath>')
     def showFolder(archiveName:str=None,folderPath=None):
         return self.showFolder(archiveName,f"/{folderPath}")
     
     @self.app.route('/documents')
     def showDocuments():
         return self.showDocuments()
     
     @self.app.route('/delete/<path:path>')
     def delete(path=None):
         return self.delete(path)
     
     @self.app.route('/upload/<path:path>',methods=['GET', 'POST'])
     def upload(path=None):
         return self.upload(path)