当前位置: 首页>>代码示例>>Python>>正文


Python Utils.getRecord方法代码示例

本文整理汇总了Python中utils.Utils.getRecord方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.getRecord方法的具体用法?Python Utils.getRecord怎么用?Python Utils.getRecord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utils.Utils的用法示例。


在下文中一共展示了Utils.getRecord方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: print_course

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import getRecord [as 别名]
def print_course(course_num, subject):
    util = Utils()
    record_list = util.getRecord(course_num, use_subject=subject, return_all=True)
    if record_list == None:
        return
    course_name = ''
    for record in record_list: 
        if record.get_id().strip() != '':
            course_name = record.get_title()
            os.system("./list.py -i " + record.get_path() + " -c 1 -f '^" + course_num + "' -d -r 10 -b 3")
开发者ID:wowdd1,项目名称:xlinkBook,代码行数:12,代码来源:about.py

示例2: search

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import getRecord [as 别名]
def search(keyword, engin, search_keyword = False):
    url = ''
    if search_keyword == False:
        utils = Utils()
        record = utils.getRecord(keyword, use_subject)
        url = record.get_url().strip()
        keyword = record.get_title().strip()

    if search_video:
        engin_list = ['youtube', 'coursera', 'edx', 'googlevideo', 'chaoxing', 'youku', 'tudou', 'videolectures']
        for e in engin_list:
            openWeb(e, keyword, url)
    else:
        openWeb(engin, keyword, url)
开发者ID:fahimkhan,项目名称:slma.link,代码行数:16,代码来源:goto.py

示例3: Bookmark

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import getRecord [as 别名]
class Bookmark(BaseExtension):

    rounter = {'' : '',\
               '' : ''}
    raw_data = ''
    jobj_list = []
    tag = Tag()
    def __init__(self):
        BaseExtension.__init__(self)
        self.utils = Utils()
        self.loadBookmark()
        self.form_dict = None

    def existChild(self, pid):
        return self.raw_data.lower().find('"parentId":"' + pid + '"') != -1

    def loadBookmark(self):
        if os.path.exists('extensions/bookmark/data/chrome_bookmarks.json'):
            f = open('extensions/bookmark/data/chrome_bookmarks.json', 'rU')
            self.raw_data = f.read()
            self.jobj_list = json.loads(self.raw_data)
            f.close()

    def updateBookmark(self):
        if os.path.exists(Config.bookmark_file_path):
            subprocess.check_output("mv " + Config.bookmark_file_path + " extensions/bookmark/data/chrome_bookmarks.json", shell=True)
            self.loadBookmark()

    def getAlias(self, rID, rTitle, file, nocache):
        alias = ''
        use_cache = not nocache
        record = None

        if rID.startswith('loop-h-'):
            file = file[0 : file.find('db/')] + 'extensions/history/data/' + file[file.rfind('/') + 1 :] + '-history'
            print file
            record = self.utils.getRecord(rTitle, path=file, matchType=2, use_cache=use_cache, accurate=False)
            #print record.line
        elif rID.startswith('loop-hc-'):
            file = file[0 : file.find('db/')] + 'extensions/content/data/' + file[file.rfind('/') + 1 :] + '-history-content'
            print file
            record = self.utils.getRecord(rTitle, path=file, matchType=2, use_cache=use_cache)
        elif rTitle.startswith('library/'):
            record = self.utils.crossref2Record(rTitle.replace('==', '->'))
        else:
            record = self.utils.getRecord(rID.strip(), path=file, log=True, use_cache=use_cache)
        if record != None and record.get_id().strip() != '':
            ret = self.utils.reflection_call('record', 'WrapRecord', 'get_tag_content', record.line, {'tag' : 'alias'})
            if ret != None:
                alias = ret.strip()
                print 'alias:' + alias

        if alias.find(',') != -1:
            return alias.split(',')
        elif alias != '':
            return [alias]
        else:
            return []

    def needBR(self):
        if self.form_dict['column'] != '1' and self.form_dict.has_key('extension_count') and int(self.form_dict['extension_count']) > 12:
            return True
        if self.form_dict['column'] == '3' and int(self.form_dict['extension_count']) > 10:
            return True
        return False

    def excute(self, form_dict):
        self.form_dict = form_dict
        divID = form_dict['divID'].encode('utf8')
        nocache = True
        if form_dict.has_key('nocache'):
            nocache = form_dict['nocache'].encode('utf8')
        rID = form_dict['rID'].encode('utf8')

        fileName = form_dict['fileName'].encode('utf8')

        originFileName = form_dict['originFileName']
        
        rTitle = form_dict['rTitle'].encode('utf8').replace('%20', ' ')

        alias = self.getAlias(rID.strip(), rTitle, originFileName, nocache)

        if rTitle.startswith('library/'):
            rTitle = rTitle.replace('==', '->')

            if rTitle.find('->') != -1:
                rTitle = rTitle[rTitle.find('->') + 2 :]
            else:
                rTitle = rTitle[rTitle.find('#') + 1 :]

        print divID
        '''
        if divID.find('-cloud-') != -1:
            html = ''
            cloud_bookmark = self.genWebsiteHtml(rTitle, form_dict['originFileName'])
            if cloud_bookmark.find('<li>') != -1:
                html += 'cloud bookmark(' + rTitle + '):<br>' + cloud_bookmark
            else:
                html = ''
            return html
#.........这里部分代码省略.........
开发者ID:wowdd1,项目名称:xlinkBook,代码行数:103,代码来源:bookmark.py

示例4: Exclusive

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import getRecord [as 别名]
class Exclusive(BaseExtension):

    def __init__(self):
        BaseExtension.__init__(self)
        self.utils = Utils()
        self.kg = KnowledgeGraph()

    def excute(self, form_dict):
        rID = form_dict['rID'].strip()
        title = form_dict['rTitle'].replace('%20', ' ').strip()
        #fileName = form_dict['fileName']
        url = form_dict['url'].strip()
        fileName = form_dict['originFileName']
        print fileName
        if rID.startswith('loop-h'):
            historyPath = os.getcwd() + '/extensions/history/data/' + fileName[fileName.rfind('/') + 1 :] + '-history' 
            print historyPath
            r = self.utils.getRecord(title, path=historyPath, matchType=2, use_cache=False, accurate=False)
        else:
            r = self.utils.getRecord(rID, path=fileName)

        if r != None and r.get_id().strip() != '':

            if rID.startswith('loop-h'):
                title = title.replace('%20', ' ')
                desc = r.get_describe() + ' ' + self.kg.getCrossref(title, ' '.join(Config.exclusive_crossref_path))
                record = Record('custom-exclusive-' + rID + ' | '+ title + ' | ' + url + ' | ' + desc)
                localUrl = self.utils.output2Disk([record], 'exclusive', 'exclusive', append=Config.exclusive_append_mode)

            else:
                db = fileName[fileName.find('db/') + 3 : fileName.rfind('/')] + '/'
                key = fileName[fileName.rfind('/') + 1 :]
                print db + ' ' + key
                #return 'http://' + Config.ip_adress + '/?db=' + db + '&key=' + key + '&filter=' + title.replace('...', '') + '&column=1'
                localUrl = 'http://' + Config.ip_adress + '/?db=' + db + '&key=' + key + '&filter=' + rID + '&column=1&enginType='  + Config.recommend_engin_type

            localUrl = localUrl + '&crossrefQuery=""'
            return self.getUrl(r.get_url(), localUrl)
        else:
            title = title.replace('%20', ' ')
            desc = 'engintype:' + title + ' '
            desc += 'localdb:' + title + ' '
            desc += self.kg.getCrossref(title, ' '.join(Config.exclusive_crossref_path))
            record = Record('custom-exclusive-' + rID + ' | '+ title + ' | ' + url + ' | ' + desc)
            localUrl = self.utils.output2Disk([record], 'exclusive', 'exclusive', append=Config.exclusive_append_mode)
            localUrl = localUrl + '&crossrefQuery=""'
            return self.getUrl(url, localUrl)

        #if fileName.find("/custom") != -1:
        #    fileName = form_dict['originFileName']
        #if form_dict.has_key('fileName') and form_dict['fileName'] != '':
        #    fileName = form_dict['fileName']

    def getUrl(self, url, localUrl):
        for k, v in Config.exclusive_default_tab.items():
            if url.find(k) != -1:
                localUrl += '&extension=' + v
                break
        return localUrl  

    def check(self, form_dict):
	    column = str(form_dict['column']).strip()
        #print 'exclusive check column ' + column
	    return True
开发者ID:wowdd1,项目名称:xlinkBook,代码行数:66,代码来源:exclusive.py

示例5: Filefinder

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import getRecord [as 别名]
class Filefinder(BaseExtension):
    form_dict = None
    def __init__(self):
        BaseExtension.__init__(self)
        self.utils = Utils()


    def excute(self, form_dict):
        self.form_dict = form_dict
        rTitle = form_dict['rTitle'].encode('utf8').replace('%20', ' ').strip()
        if rTitle.strip() == '' or len(rTitle.strip()) < 3:
            return ''
        rID = form_dict['rID']
        fileName = form_dict['fileName'].encode('utf8')
        originFileName = form_dict['originFileName'].encode('utf8')
        url = ''
        if form_dict.has_key('url'):
            url = form_dict['url'].replace('#space', ' ')
        nocache = True
        if form_dict.has_key('nocache'):
            nocache = form_dict['nocache'].encode('utf8')
        use_cache = nocache == False
        html = ''
        record = None
        if rID.startswith('loop-h-'):
            path = originFileName[0 : originFileName.find('db')] + 'extensions/history/data/' + originFileName[originFileName.rfind('/') + 1 :] + '-history'
            print path
            record = self.utils.getRecord(rTitle, path=path, log=True, use_cache=False, matchType=2, accurate=False)
        elif rID.startswith('loop-hc-'):
            path = fileName[0 : fileName.find('db')] + 'extensions/content/data/' + fileName[fileName.rfind('/') + 1 :] + '-history-content'
            print path
            record = self.utils.getRecord(rTitle, path=path, log=True, use_cache=False, matchType=2, accurate=False)

        elif rTitle.startswith('library/'):
            record = self.utils.crossref2Record(rTitle.replace('==', '->'))
            rTitle = record.get_title().strip()

            print record.line
        else:
            record = self.utils.getRecord(rID.strip(), path=form_dict['fileName'], log=True, use_cache=use_cache)


        aliasList = self.getAliasList(record)
        divID = form_dict['divID'].encode('utf8')

        if divID.find('-dbfile-') != -1:
            #keywords = aliasList + [rTitle.replace('%20', ' ')]
            keyword = rTitle.replace('%20', ' ').strip()
            dbFileList = self.genFileList(self.getMatchFiles2(keyword, [form_dict['originFileName'][form_dict['originFileName'].find('db/') :], form_dict['fileName'][form_dict['fileName'].find('db/') :]], 'db'))
            if dbFileList != '':
                html += 'matched db files(' + str(keyword) + '):<br>' + dbFileList
            return html


        if form_dict.has_key('selection') and form_dict['selection'] != '':
            rTitle = form_dict['selection'].strip()
        
        localFiles = self.genFileList(self.getMatchFiles(rTitle.strip(), url=url).split('\n'), divID=divID, rID=rID, url=url, higtLightText=rTitle.strip())
        #print localFiles
        if localFiles != '':
            if form_dict.has_key('extension_count') and int(form_dict['extension_count']) > 12:
                html += '<br>'
            html += localFiles

        
        count = 0
        if self.isDir(url) == False:
            for alias in aliasList:
                #print alias
                count += 1
                result = self.genFileList(self.getMatchFiles(alias.strip()).split('\n'),divID=divID + '-alias-' + str(count), rID=rID, higtLightText=alias.lower().strip())
                if result != '':
                    html += '<br>' + alias + ':<br>' + result

        if fileName.find('exclusive') != -1:
            keyword = rTitle.replace('%20', ' ').strip()
            dbFileList = self.genFileList(self.getMatchFiles2(keyword, [], 'db/library'))
            if dbFileList != '':
                html += 'matched library files(' + str(keyword) + '):<br>' + dbFileList

        for netdisk in Config.filefinder_netdisk_engin:

            html += '<div class="ref"><br>Search ' + netdisk + '<br>' + self.utils.toSmartLink(rTitle, engin=netdisk, showText='<font size="2">' + rTitle.replace('%20', ' ') + '</font>', rid=self.form_dict['rID'], library=self.form_dict['originFileName'], module='filefinder') + ' '
            count = 1
            for alias in aliasList:
                count += 1
                html += self.utils.toSmartLink(alias.strip(), engin=netdisk, showText=str('<font size="2">' + alias + '</font>'), rid=self.form_dict['rID'], library=self.form_dict['originFileName'], module='filefinder') + ' '
                #html += '&nbsp;'
            html += '</div>'
        if rID.startswith('loop') == False:
            
            fileDivID = divID + '-dbfile-' + str(random.randint(0, 1000))
            fileLinkID = divID + '-dbfile-a-' + str(random.randint(0, 1000))

            html += '<div id="' + fileDivID + '" class="ref">'

            if len(aliasList) == 0:
                script = "var postArgs = {name : 'filefinder', rID : '" + rID + "', rTitle : '" + rTitle +"', check: 'false', fileName : '" + fileName + "', divID : '" + fileDivID + "', originFileName : '" + form_dict['originFileName'] + "'};";
                script += "$('#' + '" + fileDivID +"').load('/extensions', postArgs, function(data) { });$('#' + '" + fileDivID +"').html('Loading...');"
                html += '<a id="' + fileLinkID + '" href="javascript:void(0);" onclick="' + script + '" style="font-size:12pt;">Search Local DB</a><br> '
#.........这里部分代码省略.........
开发者ID:wowdd1,项目名称:xlinkBook,代码行数:103,代码来源:filefinder.py

示例6: History

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import getRecord [as 别名]
class History(BaseExtension):

    raw_data = ''
    jobj_list = []
    tag = Tag()

    """docstring for History"""
    def __init__(self):
        BaseExtension.__init__(self)
        self.utils = Utils()
        #self.loadHistory()
        self.form_dict = None
        self.divID = ''

    def loadHistory(self):
        self.updateHistory()
        if os.path.exists('extensions/history/data/chrome_history.json'):
            f = open('extensions/history/data/chrome_history.json', 'rU')
            self.raw_data = f.read()
            self.jobj_list = json.loads(self.raw_data)
            f.close()

    def updateHistory(self):
        if os.path.exists(Config.history_file_path):
            subprocess.check_output("mv " + Config.history_file_path + " extensions/history/data/chrome_history.json", shell=True)
            self.loadHistory()

    def getAlias(self, rID, file, nocache):
        alias = ''
        use_cache = nocache == False
        record = self.utils.getRecord(rID.strip(), path=file, log=True, use_cache=use_cache)
        if record != None and record.get_id().strip() != '':
            ret = self.utils.reflection_call('record', 'WrapRecord', 'get_tag_content', record.line, {'tag' : 'alias'})
            if ret != None:
                alias = ret.strip()
                #print 'alias:' + alias

        if alias.find(',') != -1:
            return record, alias.split(',')
        elif alias != '':
            return record, [alias]
        else:
            return record, []

    def needBR(self):
        return self.form_dict['column'] != '1' and self.form_dict.has_key('extension_count') and int(self.form_dict['extension_count']) > 12
             
    def getDeleteButton(self, divID, historyFile, url):
        deleteScript = "$.post('/exec', {command : 'deleteRow', fileName : '" + historyFile + "', key : '" + url + "'}, function(data){" + "var target=document.getElementById('" + divID.replace('-history', '') + '-nav-history' + "');hidendiv_2('" + divID + "');navTopic(target,'" + divID.replace('-history', '') + "','" + divID.replace('-history', '') + '-nav-' + "',9);" + "});"
        deleteButton = '&nbsp;<a target="_blank" href="javascript:void(0);" onclick="' + deleteScript + '" style="color:#999966; font-size: 10pt;"><image src="' + Config.website_icons['delete'] + '" width="14" height="12"></image></a>'    
        return deleteButton

    def getClickCount(self, record):
        if record.line.find('clickcount:') != -1:
            return self.utils.reflection_call('record', 'WrapRecord', 'get_tag_content', record.line, {'tag' : 'clickcount'}).strip()
        else:
            return '1'




    def genQuickAccessSyncButton(self, rid, quickAccessHistoryFile, divID, objID):

        script = "$.post('/syncQuickAccess', {rid : '" + rid + "', fileName : '" + quickAccessHistoryFile + "'},function(data) { "

        script += "refreshTab2('" + divID + "', '" + objID + "', 'history');"

        script += "});"

        html = '<a target="_blank" href="javascript:void(0);" onclick="' + script + '">' + self.utils.getIconHtml('', 'sync') + '</a>'

        return html

    def getRefreshID(self, divID, text):
        if text == Config.history_quick_access_name:
            return 'td-' + divID.replace('history', 'a-qa-')

        else:
            return 'td-' + divID.replace('history', 'a-')

    def excute(self, form_dict):

        self.form_dict = form_dict
        

        if form_dict.has_key('command'):
            return self.excuteCommand(form_dict);
        else:
            #print '---excute---'
            print form_dict
            nocache = True

            if form_dict.has_key('nocache'):
                nocache = form_dict['nocache'].encode('utf8')
            rTitle = form_dict['rTitle'].encode('utf8').replace('%20', ' ').strip()
            fileName = form_dict['fileName'].strip()

            if rTitle.startswith('library'):
                rTitle = rTitle.replace('==', '->')
                fileName = rTitle[0 : rTitle.find('#')]
#.........这里部分代码省略.........
开发者ID:wowdd1,项目名称:xlinkBook,代码行数:103,代码来源:history.py

示例7: Reference

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import getRecord [as 别名]

#.........这里部分代码省略.........
        obj = sp.find('span', class_='stat view-count')
        views = ''
        font_size = 0
        if obj != None:
            views = sp.find('span', class_='stat view-count').text.strip().strip()
            views = views[0 : views.find(' ')]
            font_size = len(views.replace(',', ''))
        if font_size - 2 > 0:
	        font_size -= 2
        title += '<font size="' + str(font_size) + '" color="rgb(212, 51, 51)">' + views + '</font> views'
        return self.utils.removeDoubleSpace(title)

    def check(self, form_dict):
        fileName = form_dict['fileName'].encode('utf8')
        rID = form_dict['rID'].encode('utf8')
        url = form_dict['url'].encode('utf8')
        if url == '':
            return False
        self.loadReference(self.formatFileName(fileName), rID)
        if self.record_reference.has_key(rID) or fileName.find('papers') != -1 or form_dict['url'] != '' and form_dict['url'].startswith('http'):
            return True
        return False
                

    def genReferenceHtml2(self, alist, divid, defaultLinks, rID):
        return self.genMetadataHtml2(alist, divid, defaultLinks, rID)
    
    def genMetadataHtml2(self, alist, ref_divID, defaultLinks, rID):
            self.html = '<div class="ref"><ol>'
            count = 0
            for r in alist:
                if self.passItem(r[0], r[1]):
                    continue
                count += 1
                ref_divID += '-' + str(count)
                linkID = 'a-' + ref_divID[ref_divID.find('-') + 1 :]
                appendID = str(count)
                if rID.startswith('loop'):
                    appendID = rID[rID.rfind('-') + 1 :].replace('R', '.') + '.' + str(count) 
                    self.html += '<li><span>' + appendID + '.</span>'
                    if len(appendID) >= 5:
                        self.html += '<br/>'
                    appendID = appendID.replace('.','R')
                else:
                    self.html += '<li><span>' + str(count) + '.</span>'
                script = self.utils.genMoreEnginScript(linkID, ref_divID, "loop-" + rID.replace(' ', '-') + '-' + str(appendID), r[0], r[1], '-', hidenEnginSection=Config.reference_hiden_engin_section)
                if r[1] != '':
                    self.html += '<p>' + self.utils.enhancedLink(r[1], self.utils.formatTitle(r[0], Config.reference_smart_link_br_len), module='reference', rid=rID, library=self.form_dict['originFileName'])
                else:
                    self.html += '<p>' + self.utils.toSmartLink(r[0], Config.reference_smart_link_br_len, module='reference', rid=rID, library=self.form_dict['originFileName'])
                #self.html += self.utils.getDefaultEnginHtml(r[0], defaultLinks)
                if script != "":
                    self.html += self.utils.genMoreEnginHtml(linkID, script.replace("'", '"'), '...', ref_divID, '', False);
                #title = a.text.strip()
                self.html += '</p></li>'
            return self.html + "</ol></div>"


    def genReferenceHtml(self, rID, ref_divID):
        return self.genMetadataHtml(rID, ref_divID)

    def genMetadataHtml(self, key, ref_divID):
        if self.record_reference.has_key(key):
            self.html = '<div class="ref"><br><ol>'
            if self.form_dict['column'] == '1':
                self.html = '<div class="ref"><ol>'
            count = 0
            for r in self.record_reference[key]:
                count += 1
                ref_divID += '-' + str(count)
                linkID = 'a-' + ref_divID[ref_divID.find('-') + 1 :]
                appendID = str(count)
                script = self.utils.genMoreEnginScript(linkID, ref_divID, "loop-" + key.replace(' ', '-') + '-' + str(appendID), self.utils.clearHtmlTag(r.get_title().strip()), r.get_url().strip(), '-', hidenEnginSection=Config.reference_hiden_engin_section)

                self.html += '<li><span>' + str(count) + '.</span>'
                self.html += '<p>' + self.genMetadataLink(r.get_title().strip(), r.get_url().strip(), rID=key)
                if script != "":
                    self.html += self.utils.genMoreEnginHtml(linkID, script.replace("'", '"'), '...', ref_divID, '', False);
                self.html += '</p></li>'
            return self.html + "</ol></div>"
        else:
            return ''


    def genMetadataLink(self, title, url, rID=''):
        if url.find('[') != -1:
            ft = url.replace('[', '').replace(']', '').strip()
            r = self.utils.getRecord(ft, '','', False, False)
            key = r.get_path()[r.get_path().find(default_subject) + len(default_subject) + 1 :]
            url = 'http://' + Config.ip_adress + '?db=' + default_subject + '/&key=' + key + '&filter=' + ft  + '&desc=true'

        return self.genMetadataLinkEx(title, url, rID=rID)


    def genMetadataLinkEx(self, title, url, rID=''):
        if title.find('<a>') != -1:
            title = title.replace('<a>', '<a target="_blank" href="' + url + '">')
        else:
            title = self.utils.enhancedLink(url, self.utils.formatTitle(title, Config.reference_smart_link_br_len), module='reference', rid=rID, library=self.form_dict['originFileName'])
        return title
开发者ID:wowdd1,项目名称:xlinkBook,代码行数:104,代码来源:reference.py

示例8: Edit

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import getRecord [as 别名]

#.........这里部分代码省略.........
        originFileName = form_dict['originFileName'].strip()
        divID = form_dict['divID']

        if divID.find('-history-') != -1 and divID.find('-content-') != -1:
            fileName = fileName[fileName.rfind('/') + 1 :]
            fileName = os.getcwd() + '/extensions/content/data/' + fileName + '-history-content'
        elif divID.find('-content-') != -1 and divID.find('-edit') != -1:
            originFileName = originFileName[originFileName.rfind('/') + 1 :]
            fileName = os.getcwd() + '/extensions/content/data/' + originFileName + '-content'


        library = form_dict['fileName']

        if form_dict.has_key('textContent'):
            textContent = form_dict['textContent']

            if rID.startswith('loop-h-') or rID.find('plugin') != -1:
                editedData = ''
                textContent = self.textFormatConvert(textContent)

                textContent = textContent.replace(',\n', '+')
                textContent = self.utils.removeDoubleSpace(textContent)
                textContent = textContent.replace(', ', '+')
                textContent = textContent.replace(',', '+')
                textContent = textContent.replace('\n', '')
                editedData = rTitle + '(' + textContent + ')'
                print 'editedData--->' + editedData

                #return 

                historyRecord = None
                r = None
                print rID
                r, historyRecord = self.getRecordByHistory(rID, rTitle, fileName)

                if rID.find('plugin') != -1 and historyRecord == None:
                    pid = rID.replace('custom-plugin-', '')
                    if pid.find('-pg') != -1:
                        pid = pid[0 : pid.find('-pg')]
                    r = self.utils.getRecord(pid, path=fileName, use_cache=False)

                #print historyRecord.line
                #return 'error'

                if r != None:
                    editRID = r.get_id().strip()
                    resourceType = ''
                    if historyRecord != None and editedData.find('category(') == -1:
                        resourceType = self.utils.reflection_call('record', 'WrapRecord', 'get_tag_content', historyRecord.line, {'tag' : 'category'})
                        if resourceType != None:
                            resourceType = resourceType.strip()

                    print 'editRID-->' + editRID
                    if rID.find(editRID) != -1:
                        newData = r.edit_desc_field2(self.utils, r, resourceType, rTitle, editedData, self.tag.get_tag_list(library), library=library)

                        if newData != '':

                            #print '--->' + newData
                            result = self.editRecord(editRID, self.utils.removeDoubleSpace(newData), originFileName, library=library, resourceType=resourceType, divID=divID)


                            return result

                return 'error'
            
开发者ID:wowdd1,项目名称:xlinkBook,代码行数:69,代码来源:edit.py

示例9: Pathways

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import getRecord [as 别名]
class Pathways(BaseExtension):

    def __init__(self):
	BaseExtension.__init__(self)
	self.utils = Utils()

    def excute(self, form_dict):
        fileName = form_dict['fileName'].encode('utf8')
        column = form_dict['column']
        url = form_dict['url'].encode('utf8')
        #if fileName.endswith('-library') and url.find(Config.ip_adress) != -1:

        print url

        #print form_dict
        if form_dict.has_key('crossrefQuery') and form_dict['crossrefQuery'].strip() != '':
            query = form_dict['crossrefQuery']
            if query.startswith('db/') == False:
                query = 'db/' + query
            if query.find('/filter') != -1:
                query = query.replace('/filter', '&filter')
            if query.find('filter=') == -1:
                query = query + '&filter=%s'

            record = self.utils.getRecord(form_dict['rID'], path=fileName, use_cache=False)

            queryText = form_dict['rTitle']
            if record != None and record.line.find('alias:') != -1:
                alias = self.utils.reflection_call('record', 'WrapRecord', 'get_tag_content', record.line, {'tag' : 'alias'})
                if alias != None:
                    queryText = queryText + '[or]' + alias.replace(', ', '[or]').strip()

            if query.find('%s') != -1:
                query = query.replace('%s', queryText)
            print 'query-->' + query
            fileName = query
        else:

            if url.find(Config.ip_adress) != -1:
                fileName = url[url.find('db=') + 3 :]
                fileName = 'db/' + fileName
                fileName = fileName.replace('&key=', '')
                if fileName.find('&column') != -1:
                    fileName = fileName[0 : fileName.find('&column')]
                print fileName
        if fileName.find('db/') != -1:
            width = '530'
            height = '600'
            if column == '1':
                width = '1400'
                height = '600'
            elif column == '2':
                width = '700'
                height = '600'

            fileName = fileName[fileName.find('db/') + 3 :]
            db = fileName[0 : fileName.rfind('/') + 1]
            key = fileName[fileName.rfind('/') + 1 : ]
            if key == '':
                key = '?'
            src = "http://" + Config.ip_adress + '/?db=' + db + '&key=' + key + '&nosearchbox=true&column=1'
            print src
            return '<iframe width="' + width + '" height="' + height + '" frameborder="0"  src="' + src + '"></iframe>' 
        return 'nothing'

    def check(self, form_dict):
        #print form_dict
        originFileName = form_dict['originFileName'].encode('utf8')
        fileName = form_dict['fileName'].encode('utf8')
        url = form_dict['url'].encode('utf8')
        print fileName
        return (form_dict.has_key('crossrefQuery') and form_dict['crossrefQuery'] != '') or (originFileName != fileName and fileName.endswith('-library') == False) or url.find(Config.ip_adress) != -1
开发者ID:wowdd1,项目名称:xlinkBook,代码行数:74,代码来源:pathways.py

示例10: KnowledgeGraph

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import getRecord [as 别名]
class KnowledgeGraph(object):

  kg_cache = {}
  """docstring for KnowageGraph"""
  def __init__(self):
    super(KnowledgeGraph, self).__init__()
    self.webservice = BaseWebservice()
    self.utils = Utils()

  
  def getKnowledgeGraphCache(self, keyword):
    if self.kg_cache.has_key(keyword):
        return self.kg_cache[keyword]
    else:
        return ''
        
  def getKnowledgeGraph(self, keyword, resourceType, path, rID, fileName):
      if self.kg_cache.has_key(keyword):
          return self.kg_cache[keyword]
      knowledgeGraph = ''
      #crossref = self.getCrossref(keyword, path)

      #if crossref != '':
      #    knowledgeGraph += crossref + ' '

      print rID + ' ' + fileName
      record = Record('')
      if os.path.exists(fileName) and rID != '':
          record = self.utils.getRecord(rID, path=fileName)
      if record != None and record.get_id().strip() == rID:
          for tag in ['instructors', 'keyword']:
              result = self.webservice.callWebservice(tag, record, keyword, resourceType)
              #print instructors
              if result != None and len(result) > 0:
                  knowledgeGraph += tag +':' + ', '.join(result).strip() + ' '
      self.kg_cache[keyword] = knowledgeGraph
      print knowledgeGraph
      return knowledgeGraph
   
  def getCrossref(self, keyword, path='db/library'):
      cmd = 'grep -riE "' + keyword + '" ' + path
      print cmd
      output = ''
      try:
          output = subprocess.check_output(cmd, shell=True)
      except Exception as e:
          return ''
      adict = {}
      titleDict = {}
      for line in output.split('\n'):
          fileName = line[0 : line.find(':')].strip().replace('//', '/')
          firstIndex = line.find('|')
          rID = line[line.find(':') + 1 : firstIndex].strip().replace(' ', '%20')
          title = line[firstIndex + 1 : line.find('|', firstIndex + 1)].strip()
          if title != '':
              if title.find(',') != -1:
                  title = title.replace(',', '')
              if title.find('+') != -1:
                  title = title[0 : title.find('+')]
              if title.find('#') != -1:
                  title = title[0 : title.find('#')]
              if titleDict.has_key(title):
                  continue
              if adict.has_key(fileName):
                  adict[fileName].append(title)
              else:
                  adict[fileName] = [title]
              titleDict[title] = title
      result = ''
      print '---getCrossref---'
      for k, v in adict.items():
          #print k + ' #' + '#'.join(v)
          prefix = ''
          if k.startswith('db/'):
              prefix = k[3:]
          ft = '+'.join(v).strip()
          if ft.endswith('+'):
              ft = ft[0 : len(ft) - 2]
          result += prefix + '#' + ft
          if k != adict.items()[len(adict) - 1][0]:
              result += ', '

      
      if result != '':
          result = 'crossref:' + result
      print result
      return result
开发者ID:wowdd1,项目名称:xlinkBook,代码行数:89,代码来源:knowledgegraph.py

示例11: Content

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import getRecord [as 别名]
class Content(BaseExtension):

    record_content = {}

    datafile_content = {}
    optional_content = {}

    form_dict = None
    tag = Tag()
   

    def __init__(self):
        BaseExtension.__init__(self)
        self.utils = Utils()
        self.data_dir = 'extensions/content/data/'
        self.data_type = 'content'
        self.contentref = ''


    def loadContent(self, rID, name, content, cache=False):
	print 'rid :' + rID
	print ' loadContent filename:' + name
        if len(content) != 0 and content.has_key(rID) and cache:
            return True
        #else:
        #    content = {}

        if os.path.exists(name) and os.path.isfile(name):
            f = open(name, 'rU')
            all_lines = f.readlines()
            content[rID] = []
            for line in all_lines:
		line = line.strip()
                record = ContentRecord(line)
                if line.startswith('#') or record.get_parentid() == None:
                    continue
                if record.get_title().strip() == '':
                    continue
                key = record.get_parentid().strip()
                if key != rID:
                    continue
                if content.has_key(key):
                    content[key].append(record)
                else:
                    content[key] = [record]
            return True

        return False

        #for (k, v) in self.record_content.items():
        #    print k

    def buildRecordContent(self, rID, fileName, cache=False, rTitle=''):
        print 'buildRecordContent'
        oritinId = rID
        if rID.find('-tag-') != -1:
            rID = rID[0 : rID.find('-tag-')]
        isDescField = False
        searchID = rID
        if rID.startswith('loop-hc'):
            if rTitle.find('==') != -1:
                rTitle = rTitle[rTitle.find('==') + 2 :].replace('%20', ' ')
            idPart = rTitle.replace(' ', '-').lower()
            searchID = rID.replace('loop-hc-', '').replace('-' + idPart , '')
            isDescField = True
        if rTitle.startswith('library/'):
            fileName = 'db/' + rTitle[0:rTitle.find('#')]
            rTitle = rTitle[rTitle.find('#') + 1  : rTitle.find('==')].replace('%20', ' ')

        print rID
        print rID + ' ' + fileName + ' ' + rTitle

        r = self.utils.getRecord(searchID, path=fileName)

        desc = ''
        if r == None:
            return {}

        desc = r.get_describe()
        if isDescField:
            desc = r.get_desc_field2(self.utils, rTitle, self.tag.tag_list, toDesc=True)
            print '---->' + desc
            #rID = oritinId
        descDict = self.utils.toDescDict(desc, fileName[fileName.rfind('/') + 1 :])
        print 'ok-----' + r.get_id()
        print descDict
        content = {}

        topID = rID.strip() 
        count1 = 0
        count2 = 0
        content = {}
        for k , v in descDict.items():
            print k  + ' ' + v

            #desc = self.utils.valueText2Desc(v)

            count1 += 1
            count2 = 0
            nID = topID + '-tag-' + str(count1) 
#.........这里部分代码省略.........
开发者ID:wowdd1,项目名称:xlinkBook,代码行数:103,代码来源:content.py


注:本文中的utils.Utils.getRecord方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。