# # Collective Knowledge # # See CK LICENSE.txt for licensing details. # See CK COPYRIGHT.txt for copyright details. # # Developer: Grigori Fursin # cfg={} # Will be updated by CK (meta description of this module) work={} # Will be updated by CK (temporal data) ck=None # Will be updated by CK (initialized CK kernel) # Local settings import shutil import os import json # LaTex tokens tokens=[ {"key":'%CK_TEX={', "end":"}", "id":250, "html1":'',"html2":"", "remove":"no"}, {"key":'%CK_ABSTRACT={', "end":"}", "id":250, "html1":'',"html2":"", "remove":"no"}, {"key":'%CK={', "end":"}", "id":100, "html1":'',"html2":"", "remove":"yes"}, {"key":'%CK_HTML={', "end":"}", "id":150, "html1":'',"html2":"", "remove":"no"}, {"key":'%CK_URL={', "end":"}", "id":198, "html1":'',"html2":"", "remove":"no"}, {"key":'%CK_IMG={', "end":"}", "id":199, "html1":'',"html2":"", "remove":"no"}, {"key":'%CK_INTERACTIVE_GRAPH_PASSIVE={', "end":"}", "id":298, "html1":'',"html2":"", "remove":"no"}, {"key":'%CK_INTERACTIVE_GRAPH={', "end":"}", "id":299, "html1":'',"html2":"", "remove":"no"}, {"key":'\\%', "id":500, "html1":'%'}, {"key":'\n\n', "id":60, "html1":'\n

'}, {"key":'\\&', "id":105, "html1":"&"}, {"key":'\\ ', "id":105, "html1":" "}, {"key":'\\{', "id":105, "html1":"{"}, {"key":'\\}', "id":105, "html1":"}"}, {"key":'\\clearpage', "id":105, "html1":"

"}, {"key":'\\newpage', "id":105, "html1":"

"}, {"key":'\\_', "id":105, "html1":"_"}, {"key":'\\$', "id":105, "html1":'$'}, {"key":'\\newline', "id":105, "html1":'\n'}, {"key":'\\label{', "end":"}", "id":10, "html1":'',"html2":"", "remove":"no"}, {"key":'\\section{', "end":"}", "id":80, "html1":"\n\n

","html2":"

\n"}, {"key":'\\subsection{', "end":"}", "id":81, "html1":"\n\n

","html2":"

\n"}, {"key":'\\subsubsection{', "end":"}", "id":82, "html1":"\n\n

","html2":"

\n"}, {"key":'\\emph{', "end":"}", "id":3, "html1":"","html2":""}, {"key":'\\textbf{', "end":"}", "id":3, "html1":"","html2":""}, {"key":'\\textit{', "end":"}", "id":3, "html1":"","html2":""}, {"key":'\\texttt{', "end":"}", "id":3, "html1":"
","html2":"
"}, {"key":'\\url{', "end":"}", "id":333, "html1":"","html2":""}, {"key":'\\href{', "end":"}", "id":334, "html1":"","html2":""}, {"key":'{\\bf', "end":"}", "id":3, "html1":"","html2":""}, {"key":'{\\it', "end":"}", "id":3, "html1":"","html2":""}, {"key":'{\\tt', "end":"}", "id":3, "html1":"","html2":""}, {"key":'~', "end":"", "id":4, "html1":" ","html2":""}, {"key":'\\item', "id":49, "html1":'\n
  • \n'}, {"key":'\\begin{itemize}', "id":43, "html1":'\n\n'}, {"key":'\\begin{flushleft}', "id":43, "html1":'\n'}, {"key":'\\end{flushleft}', "id":44, "html1":'\n'}, {"key":'\\begin{verbatim}', "id":43, "html1":'\n
    '},
            {"key":'\\end{verbatim}', "id":44, "html1":'
    \n'}, {"key":'\\begin{lstlisting', "end":"]", "id":43, "html1":'\n
    ', "remove":"yes"},
            {"key":'\\end{lstlisting}', "id":44, "html1":'
    \n'}, {"key":'\\caption{', "end":"}", "id":20, "html1":'
    ',"html2":"

    \n"}, {"key":'\\centering', "id":90, "html1":""}, {"key":'\\includegraphics', "end":"}", "id":30, "html1":'',"html2":"", "remove":"yes"}, {"key":'\\begin{table', "end":"]", "id":555, "html1":'
    \n',"html2":"", "remove":"no"}, {"key":'\\end{table}', "id":49, "html1":'
    \n'}, {"key":'\\end{table*}', "id":49, "html1":'\n'}, {"key":'\\begin{figure', "end":"]", "id":554, "html1":'\n
    \n',"html2":"", "remove":"no"}, {"key":'\\end{figure}', "id":49, "html1":'
    \n'}, {"key":'\\end{figure*}', "id":50, "html1":'\n'}, {"key":'\\input{', "end":"}", "id":44, "html1":'',"html2":"", "remove":"yes"}, {"key":'{\\center', "end":"}", "id":44, "html1":'
    \n',"html2":"
    \n", "remove":"no"}, {"key":'\\begin{center}', "end":"\\end{center}", "id":44, "html1":'
    \n',"html2":"

    \n", "remove":"no"}, {"key":'\\cite{', "end":"}", "id":300, "html1":"[","html2":"]"}, {"key":'\\ref{', "end":"}", "id":600, "html1":"","html2":""}, {"key":'{\\small', "end":"}", "id":3, "html1":"","html2":""}, {"key":'\\vspace{', "end":"}", "id":950, "html1":"
    ","html2":"","remove":"yes"}, {"key":'%', "end":"\n", "id":1000, "html1":"","html2":"", "remove":"yes"}, {"key":'\\footnote{', "end":"}", "id":1111, "html1":"","html2":"", "remove":"yes"}, ] # ============================================================================ def init(i): return {'return':0} ############################################################################## # generate title def generate(i): """ Generating "low-hanging fruit" research topics and papers ;) Input: { data_uoa - data with topic template (repo_uoa) - repository (html) - if 'yes', force html } Output: { return - return code >0 if error string - generated title } """ import random o=i.get('out','') html=False if i.get('html','')=='yes': html=True on='' if html: on='

    ' txt='' x='This is a beta version of a research topic generator!' if html: x=''+x+'' txt+=x+'\n' txt+=on+'\n' txt+='Academic promotion is still often based on a total number of publications'+'\n' txt+='rather than novelty, usefulness, statistical meaningfulness, availability of code and data,'+'\n' txt+='and reproducibility of experimental results.'+'\n' txt+=on+'\n' txt+='Therefore, some years ago, we decided to help some of our academic colleagues and created this customizable '+'\n' x='' x+='Collective Knowledge module' txt+=x+' to automatically generate research topics in computer engineering'+'\n' txt+='(useful for grant proposals, PhD/MS theses, "low hanging fruit" and incremental articles).'+'\n' txt+=on+'\n' txt+='We hope it will be very appreciated by the academic community ;) !\n' txt+='It should make all reviewers and readers even more happy\n' txt+='when trying to process all those numerous exciting publications!\n' txt+='We also found that it is even possible to predict which papers will be published\n' txt+='within next few years (our observations for the past decade are surprisingly correct)!\n' du=i.get('data_uoa','') if du=='': du='template-joke' # if du=='': # return {'return':1,'error':'data_uoa is not defined'} dr=i.get('repo_uoa','') ii={'module_uoa':work['self_module_uoa'], 'action':'load', 'data_uoa':du} if dr!='': ii['repo_uoa']=dr r=ck.access(ii) if r['return']>0: return r d=r['dict'].get('template_for_generator',[]) # Generating topic s='' selected=False swn=False for q in d: t=q.get('text','') p=q.get('probability','') if p=='': p=1.0 p=float(p) c=q.get('choice',[]) # Check if select with next and previous was not selected: if swn: swn=False if not selected: continue xswn=q.get('select_with_next','') if xswn=='yes': swn=True # Check to select selected=False x=float(random.randint(0,1000))/1000 if x0: l=random.randint(0,ll-1) s+=c[l] txt+=on+'\n' x='Generated topic:' if html: x=''+x+'' txt+=x+'\n' txt+=on+'\n' if html: txt+='' x=s if html: x=''+s+'' txt+=' '+x+'\n' if html: txt+='' x1='wiki' if html: x1=''+x1+'' else: x1+=' (cknowledge.org/reproducibility)' x2='open-source framework and repository' if html: x2=''+x2+'' else: x2+=' (github.com/ctuning/ck)' x3='new publication model' if html: x3=''+x3+'' else: x3+=' (hal.inria.fr/hal-01006563)' if html: txt+=on+'\n' txt+='Simply restart this module to generate next exciting topic\n' txt+='or alternatively check out our '+x1+', '+x2+', and '+x3+' to enable systematic, collaborative and reproducible R&D.\n\n' txt+='
    \n' txt+='You can even automate generation of these topics from CMD using our CK framework:
    \n' txt+='  > ck pull repo:ck-dissemination --url=https://github.com/gfursin/ck-dissemination.git
    \n' txt+='  > ck generate dissemination.publication:template-joke
    \n' txt+='

    \n' txt+='Powered by Collective Knowledge, (C)opyright ' txt+='' txt+='Grigori Fursin' txt+='' txt+=', 2012-2015\n' txt+='\n' # Output if not JSON if o!='json' and o!='json_file': ck.out(txt) r={'return':0} if html: r['html']=txt else: r['string']=s return r ############################################################################## # viewing entry as html # TBD: should redirect to module:report ? def html_viewer(i): """ Input: { data_uoa url_base url_pull url_pull_tmp tmp_data_uoa url_wiki html_share form_name - current form name (all_params) } Output: { return - return code = 0, if successful > 0, if error (error) - error text if return > 0 html - generated HTML raw - if 'yes', output in CK raw format show_top - if 'yes', include CK top header with QR-code } """ import os h='' raw='no' top='no' duoa=i['data_uoa'] burl=i['url_base'] purl=i['url_pull'] wurl=i.get('url_wiki','') tpurl=i['url_pull_tmp'] tpuoa=i['tmp_data_uoa'] ap=i.get('all_params',{}) ruoa=ap.get('ck_top_repo','') muoa=ap.get('ck_top_module','') cparams=ap.get('graph_params','') # current graph params hshare=i.get('html_share','') form_name=i['form_name'] form_submit='document.'+form_name+'.submit();' if duoa!='': # Load entry rx=ck.access({'action':'load', 'module_uoa':work['self_module_uid'], 'data_uoa':duoa}) if rx['return']>0: return rx pp=rx['path'] dd=rx['dict'] duid=rx['data_uid'] if dd.get('live','')!='yes': raw='yes' else: title=dd.get('title','') authors=dd.get('authors',[]) affs=dd.get('affiliations',{}) cauthor=dd.get('cor_author_email','') when=dd.get('when','') where=dd.get('where','') where_url=dd.get('where_url','') if where!='' and where_url!='': where=''+where+'' appeared=where if when!='': if appeared!='': appeared+=', ' appeared+=when h+='
    \n' h+='
    '+title+'
    ' if appeared!='': h+='
    \n' h+='\n' h+=appeared+'\n' h+='\n' if len(authors)!='': h+='
    \n' h+='
    \n' h+='\n' x='' for a in authors: name=a.get('name','') aff=a.get('affiliation','') url=a.get('url','') if ck.is_uid(name): # Name is UID, load entry r=ck.access({'action':'load', 'module_uoa':cfg['module_deps']['person'], 'data_uoa':name}) if r['return']>0: return r ad=r['dict'] name=ad.get('name','') name=name.replace(' ',' ') if url!='': name=''+name+'' if x!='': x+=', ' x+=name+' '+aff+'' h+=x+'
    \n' h+='
    \n' if len(affs)>0: h+='
    \n' h+='\n' x='' for a in sorted(affs, key=int): af=affs[str(a)] name=af.get('name','').replace(' ',' ') if x!='': x+=', ' x+=''+str(a)+' '+name h+=x+'
    \n' h+='
    \n' h+='
    \n' if len(cauthor)>0: h+='
    \n' h+='\n' h+='Corresponding author: '+cauthor+'\n' h+='\n' if hshare!='': h+='
    \n' h+=hshare h+='
    \n' h+='
    ' # if wurl!='' and dd.get('skip_wiki_discussion','')!='yes': # h+='[ Discussion wiki (comments, reproducibility, etc.) ]' h+='
    \n' h+='
    \n' h+='
    \n' h+='
    \n' # Checking template t=dd.get('template','') if t!='': h+='\n' px=os.path.join(pp,t) th='' if os.path.isfile(px): rx=ck.load_text_file({'text_file':px}) if rx['return']>0: return rx th=rx['string'] th=th.replace('$#ck_root_url#$', burl) h+=th h+=' 0, if error (error) - error text if return > 0 } """ doc=i['doc'] ck.out('') ck.out('Loading document '+doc+' ...') r=ck.load_text_file({'text_file':doc}) if r['return']>0: return r s_orig=r['string'] l=s_orig.split('\n') ll=len(l) ck.out('') ck.out('Processing document ...') changed=False cur_ck='' detected=False j=0 while j0: return r ii=r['dict'] action=ii['action'] cid=ii.get('cid','') tp=ii.get('type','path') ck.out('') r=ck.access(ii) if r['return']>0: return r sub=r.get('substitute',{}) # Substituting for k in sub: v='%'+k j1=j while j10: if tp=='path': k1=ss.find('{') if k1>0 and ss.rfind('}')>0: k2=ss.rfind('}') s1=ss[:k1+1] s2=ss[k2:] else: s1='' s2=ss[js:] l[j1]=s1+sub[k]+s2 elif tp=='textlet': j1+=1 l[j1]=sub[k] j1+=1 while j1=0: break del(l[j1]) ll=len(l) changed=True j1+=1 if sx.startswith('%CK={'): cur_ck=sx[4:] detected=True if changed: fbak=doc+'.bak' ck.out('') ck.out('Document changed, backing up to '+fbak+' ...') r=ck.save_text_file({'text_file':fbak, 'string':s_orig}) if r['return']>0: return r ck.out('') ck.out('Updating document '+doc+' ...') s='' for x in l: s+=x+'\n' r=ck.save_text_file({'text_file':doc, 'string':s}) if r['return']>0: return r return {'return':0} ############################################################################## # convert tex article to live ck report def convert_to_live_ck_report(i): """ Input: { module_uoa data_uoa - LaTex publication to process (input) - input file (paper.tex by default) (input_bbl) - BBL input file for references (paper.bbl by default) (output) - output file in CK live report format } Output: { return - return code = 0, if successful > 0, if error (error) - error text if return > 0 } """ # Init anchors={} refs={} cites={} xcites=[] figures={} tables={} sections={} appendices={} ifigures=0 itables=0 isections=0 iappendices='A' muoa=i['module_uoa'] duoa=i['data_uoa'] fi=i.get('input','') if fi=='': fi='paper.tex' fib=i.get('input_bbl','') if fib=='': fib='paper.bbl' fo=i.get('output','') if fo=='': fo='ck-interactive-paper.html' # Check entry in current path (for URL) r=ck.cid({}) if r['return']>0: return r self_cid=r['module_uid']+':'+r['data_uid'] self_url='$#ck_root_url#$action=pull&common_func=yes&cid='+self_cid+'&filename=' # Get path to entry r=ck.access({'action':'load', 'module_uoa':muoa, 'data_uoa':duoa}) if r['return']>0: return r p=r['path'] pfi=os.path.join(p,fi) pfib=os.path.join(p,fib) # Read paper ck.out('') ck.out('Loading paper: '+pfi+' ...') r=ck.load_text_file({'text_file':pfi}) if r['return']>0: return r paper=r['string'].replace('\r','') # Read references ck.out('') ck.out('Loading references: '+pfib+' ...') r=ck.load_text_file({'text_file':pfib}) if r['return']>0: return r bbl=r['string'].replace('\r','') # Parse references ck.out('') ck.out('Parsing references: '+pfib+' ...') j=bbl.find('\\bibitem') while j>=0: # Check if []% and then remove it index=9 x=bbl[j+8:j+9] if x=='[': j1=bbl.find(']%', j+9) if j1<0: return {'return':1, 'error':'unknown bibitem format - expected ]% after \\bibitem['} j=bbl.find('{',j1) index=1 elif x!='{': return {'return':1, 'error':'unknown bibitem format - expected \\bititem{ or \\bibitem['} j1=bbl.find('}',j+1) if j1>=0: ref=bbl[j+index:j1] j2=bbl.find('\n\n', j1+1) if j2>0: ck.out(' * '+ref) s=bbl[j1+1:j2].strip() # Processing special tokens s=s.replace('~',' ').replace('\\newblock','
    ').replace('\\&','&').replace('\\ ',' ') # https://www.w3schools.com/charsets/ref_utf_latin_extended_a.asp s=s.replace('\\c{T}','Ţ').replace('\\u{a}','ă').replace('\\c{s}','ş') j5=s.find('\\url{') if j5>=0: j6=s.find('}',j5+1) if j6>=0: s=s[:j5]+'Link'+s[j6+1:] j5=s.find('\\href{') if j5>=0: j6=s.find('}',j5+1) if j6>=0: j7=s.find('{',j6+1) if j7>=0: j8=s.find('}',j7+1) if j8>=0: s=s[:j5]+''+s[j7+1:j8]+''+s[j8+1:] s=s.replace('{\\em','').replace('{','').replace('}','') cites[ref]={'html':s} j=bbl.find('\\bibitem',j+1) r=ck.load_text_file({'text_file':pfib}) if r['return']>0: return r bbl=r['string'] hpaper='' # Searching first section (ignore all above - will be prepared by CK via meta.json) nref=1 j=paper.find('%CK_INTERACTIVE_START') if j>=0: # Searching for the bibliography j1=paper.find('\\bibliographystyle') if j1>=0: hpaper=paper[j:j1-1]+'\n\n' # Start processing special commands for tt in tokens: t=tt['key'] tend=tt.get('end','') thtml1=tt.get('html1','') thtml2=tt.get('html2','') idx=tt['id'] if tend!='': j=hpaper.find(t) while j>=0: j1=hpaper.find(tend,j+len(t)) if j1>=0: sx=hpaper[j+len(t):j1] xthtml1=thtml1 sx_right='' if idx==80: # Check if appendices l=hpaper.rfind('%CK_APPENDIX={', 0, j+1) if l>=0: l1=hpaper.find('}',l+1) app=hpaper[l+14:l1] else: isections+=1 app=str(isections) sx=app+'  '+sx sx_right='\n\n\n\n' l=hpaper.find('CK_LABEL={', j) if l>=0: l1=hpaper.find('}',l+1) lbl=hpaper[l+10:l1] sx_right='\n\n'+sx_right refs[lbl]=app elif idx==81: # Check current session l=hpaper.rfind('CK_CUR_SECTION={',0, j+1) if l>=0: l1=hpaper.find('}',l+1) section=hpaper[l+16:l1] subsection='' l2=hpaper.rfind('CK_CUR_SUBSECTION={',l,j+1) if l2>=0: l3=hpaper.find('}',l2) if l3>=0: subsection=hpaper[l2+19:l3] if subsection=='': subsection='1' else: subsection=str(int(subsection)+1) app=section+'.'+subsection sx=app+'  '+sx sx_right='\n\n\n\n' l=hpaper.find('CK_LABEL={', j) if l>=0: l1=hpaper.find('}',l+1) lbl=hpaper[l+10:l1] sx_right='\n\n'+sx_right refs[lbl]=app elif idx==82: # Check current session l=hpaper.rfind('CK_CUR_SECTION={',0, j+1) if l>=0: l1=hpaper.find('}',l+1) section=hpaper[l+16:l1] subsection='' l2=hpaper.rfind('CK_CUR_SUBSECTION={',l,j+1) if l2>=0: l3=hpaper.find('}',l2) if l3>=0: subsection=hpaper[l2+19:l3] subsubsection='' l4=hpaper.rfind('CK_CUR_SUBSUBSECTION={',l2,j+1) if l4>=0: l5=hpaper.find('}',l4) if l5>=0: subsubsection=hpaper[l4+22:l5] if subsubsection=='': subsubsection='1' else: subsubsection=str(int(subsubsection)+1) app=section+'.'+subsection+'.'+subsubsection sx=app+'  '+sx sx_right='\n\n\n\n' l=hpaper.find('CK_LABEL={', j) if l>=0: l1=hpaper.find('}',l+1) lbl=hpaper[l+10:l1] sx_right='\n\n'+sx_right refs[lbl]=app if idx==554: # Check if appendices ifigures+=1 anc='' xlbl='' l=hpaper.find('CK_LABEL={', j) if l>=0: l1=hpaper.find('}',l+1) lbl=hpaper[l+10:l1] figures[lbl]={'id':ifigures} refs[lbl]=str(ifigures) xlbl='' sx='\n
    '+xlbl+'Figure '+str(ifigures)+'\n' elif idx==555: # Check if appendices itables+=1 anc='' xlbl='' l=hpaper.find('CK_LABEL={', j) if l>=0: l1=hpaper.find('}',l+1) lbl=hpaper[l+10:l1] tables[lbl]={'id':itables} refs[lbl]=str(itables) xlbl='
    ' sx='\n
    '+xlbl+'Table '+str(itables)+'

    \n' elif idx==10: sx=sx.replace(':','_').replace('-','_') sx='\n\n' # xthtml1=thtml1.replace('$#aname#$',sx) elif idx==600: sx=sx.replace(':','_').replace('-','_') sx='
    '+str(refs[sx])+'' # xthtml1=thtml1.replace('$#aname#$',sx) elif idx==150: rx=ck.load_text_file({'text_file':sx}) if rx['return']>0: return rx sx=rx['string'] elif idx==333: sx=''+sx+'' elif idx==334: sx1=sx if len(hpaper)>j1 and hpaper[j1+1:j1+2]=='{': j2=hpaper.find('}',j1+2) sx1=hpaper[j1+2:j2] j1=j2 sx=''+sx1+'' elif idx==198: r=ck.convert_json_str_to_dict({'str':'{'+sx+'}', 'skip_quote_replacement':'yes'}) if r['return']>0: return r ii=r['dict'] url=ii['url'] text=ii['text'] sx=''+text+'
    ' elif idx==199: # b9=sx.find(';') # if b9<0: # sx='' # else: # sy=sx[b9+1:].strip() # sx=sx[:b9].strip() # # sx='' sxs=sx.split(';') if len(sxs)<1: sx='' else: s0=sxs[0].strip() s1=sxs[1].strip() s2='' if len(sxs)>2: s2=sxs[2].strip() sx='' elif idx==298: # Passive graph (include) sx='\n$#ck_include_start#$\n{'+sx+'}\n$#ck_include_stop#$\n' elif idx==299: # Active graph (generate) sx='\n$#ck_access_start#$\n{'+sx+'}\n$#ck_access_stop#$\n' elif idx==250: psx=os.path.join(p,sx) rx=ck.load_text_file({'text_file':psx}) if rx['return']>0: return rx sx=rx['string'] elif idx==300: ycites=sx.replace('\n','').strip().split(',') xc='' for cx in ycites: c=cx.strip() if c in cites: x=cites[c] n=x.get('number','') if n=='': n=nref x['number']=n xcites.append(c) nref+=1 if xc!='': xc+=', ' xc+=''+str(n)+'' else: return {'return':1, 'error':'citation "'+c+'" was not found in bbl'} sx=xc elif idx==100: # Convert from JSON to dict r=ck.convert_json_str_to_dict({'str':'{'+sx+'}', 'skip_quote_replacement':'yes'}) if r['return']>0: return r ii=r['dict'] tp=ii.get('ck_url','') fx=ii.get('file','') px=ii.get('path','') euid=ii.get('extra_uid','') if euid!='': euid+='-' ckimg=ii.get('ck_image','') ckimgw=ii.get('ck_image_width','') ckey='%CK_URL={'+fx+'}' if fx.endswith('.pdf'): fx=fx[:-4]+'.png' ii['file']=fx if euid!='': f0,f1=os.path.splitext(fx) fx=f0.replace('.','-')+f1 fxx=px+'/'+euid+fx url=self_url+fxx ck.out('') ck.out('* Processing CK command '+sx+' ...') r=ck.access(ii) if r['return']>0: return r x='' if ckimg=='yes': x='


    ' hpaper1=hpaper.replace(ckey,x) if hpaper1!=hpaper: ck.out(' CHANGED!') hpaper=hpaper1 if tt.get('remove','')=='yes': sx='' hpaper=hpaper[:j]+xthtml1+sx+thtml2+hpaper[j1+len(tend):] # Add extra to the right of the line (CK remarks) if sx_right!='': k=hpaper.find('\n',j+1) if k>=0: hpaper=hpaper[:k]+sx_right+hpaper[k+1:] else: return {'return':1, 'error':'inconsistent token "'+t+'" in tex file ('+hpaper[j:j+16]+' ...)'} j=hpaper.find(t, j) else: hpaper=hpaper.replace(t, thtml1) # Check references if len(xcites)>0: hpaper+='

    \n' hpaper+='

    References

    \n' hpaper+='\n' nref=0 for c in xcites: nref+=1 hpaper+=' \n' hpaper+=' ' hpaper+=' \n' hpaper+=' \n' hpaper+='
    ['+str(nref)+']'+cites[c]['html'] hpaper+='
    \n' for q in range(0,50): hpaper+='
    ' # Saving to report ck.out('') ck.out('Saving interactive CK report: '+fo+' ...') r=ck.save_text_file({'text_file':fo, 'string':hpaper}) if r['return']>0: return r return {'return':0} ############################################################################## # compile paper def compile(i): """ Input: { data_uoa - paper UOA } Output: { return - return code = 0, if successful > 0, if error (error) - error text if return > 0 } """ i['script']='compile' return run_script(i) ############################################################################## # clean paper def clean(i): """ Input: { data_uoa - paper UOA } Output: { return - return code = 0, if successful > 0, if error (error) - error text if return > 0 } """ i['script']='clean' return run_script(i) ############################################################################## # internal: run script def run_script(i): import os import platform duoa=i.get('data_uoa','') if duoa=='': return {'return':1, 'error':'paper name is not defined (see ck ls '+work['self_module_uoa']+')'} # Load entry r=ck.access({'action':'load', 'module_uoa':work['self_module_uid'], 'data_uoa':duoa}) if r['return']>0: return r p=r['path'] d=r['dict'] # Prepare script name s=i['script'] sname=d.get('scripts',{}).get(s,'') if sname!='': s=sname script='_'+s if platform.system().lower().startswith('win'): script+='.bat' else: script='bash ./'+script+'.sh' # Run script os.chdir(p) os.system(script) return {'return':0}