Changeset 5378 for lliurex-jclic-shared/trunk/fuentes/lliurex-jclic-shared.install-files/net/server-sync/share/jclic-aula/helper.py
- Timestamp:
- Jun 28, 2017, 1:55:49 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lliurex-jclic-shared/trunk/fuentes/lliurex-jclic-shared.install-files/net/server-sync/share/jclic-aula/helper.py
r4455 r5378 11 11 12 12 name_zip=str(sys.argv[1]) 13 #name_zip="/home/lliurex/ mat_alh.jclic.zip"13 #name_zip="/home/lliurex/essent.jclic.zip" 14 14 extract_dir="/net/server-sync/share/jclic-aula/jclic_uploads" 15 15 dir_jclic_orig="/net/server-sync/share/jclic-aula/jclic_uploads/0rig_jclic" … … 17 17 index="index.html" 18 18 jclic_js="http://server/jclic-aula/jclic.min.js" 19 jclic_plugin="http://server/jclic-aula/jclicplugin.js" 20 jar_path_lib="http://server/jclic-aula/jars" 19 21 sufix=".lock" 20 22 … … 125 127 126 128 127 def index_write(extract_dira,indexa,title_in,jclic_js_path,name_jclic_used): 128 index_path=os.path.join(extract_dira, indexa) 129 130 html_str=""" 131 <!DOCTYPE html> 132 <html> 133 <head> 134 <meta charset="UTF-8"> 135 <title>%s</title> 136 <meta name="apple-mobile-web-app-capable" content="yes"> 137 <meta name="mobile-web-app-capable" content="yes"> 138 <meta name="application-name" content="%s"> 139 <link rel="shortcut icon" href="favicon.ico"> 140 <link rel="icon" sizes="16x16" href="favicon.ico"> 141 <link rel="icon" sizes="72x72" href="icon-72.png"> 142 <link rel="icon" sizes="192x192" href="icon-192.png"> 143 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 144 <script type="text/javascript" src="%s"></script> 145 </head> 146 <body style="margin:0"> 147 <div class ="JClic" data-project="%s"></div> 148 </body> 149 </html> 150 """%(title_in,title_in,jclic_js_path,name_jclic_used) 151 152 html_index=open(index_path, "w") 153 html_index.write(html_str) 154 html_index.close() 155 print "Created index.html in: %s"%index_path 129 def index_write(extract_dira,indexa,title_in,jclic_plugin_path,jar_path,name_jclic_used): 130 try: 131 index_path=os.path.join(extract_dira, indexa) 132 print index_path 133 print "dentro con %s %s %s %s"%(title_in,jclic_plugin_path,jar_path,name_jclic_used) 134 135 html_str=""" 136 <!DOCTYPE HTML PUBLIC> 137 <html> 138 <head> 139 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 140 <title>%s</title> 141 <script language="JavaScript" SRC="%s" type="text/javascript"></script> 142 </head> 143 <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="window.focus();"> 144 <script language="JavaScript"> 145 <!-- 146 setJarBase('%s'); 147 setLanguage('null'); 148 writePlugin('%s', '100%%', '100%%'); 149 --> 150 </script> 151 </body> 152 </html> 153 """%(title_in,jclic_plugin_path,jar_path,name_jclic_used) 154 155 print "fin" 156 print "abriendo index path para escribir fichero en %s"%index_path 157 158 html_index=open(index_path, "w") 159 html_index.write(html_str) 160 html_index.close() 161 print "Created index.html in: %s"%index_path 162 163 except Exception as e: 164 print e 165 return [False,str(e)] 156 166 157 167 # def index_write … … 257 267 258 268 if dir_name.endswith(".jclic"): 259 dir_name=os.path.splitext(dir_name)[0] 269 dir_name=os.path.splitext(dir_name)[0] 260 270 extract_dir=os.path.join(extract_dir, dir_name) 261 271 262 272 263 273 print "-----------------------------------" 264 print " %s to HTML5"%name_zip274 print "Generating index.html for %s"%name_zip 265 275 print "-----------------------------------" 266 276 … … 268 278 if not os.path.exists (extract_dir): 269 279 os.makedirs(extract_dir) 280 281 os.system("setfacl -m group:www-data:rwx %s"%extract_dir) 282 os.system("setfacl -m default:group:www-data:rwx %s"%extract_dir) 270 283 271 284 if not os.path.exists (dir_jclic_orig): 272 285 os.makedirs(dir_jclic_orig) 273 274 # Extraccion de los ficheros del jclic286 287 #Busco el ficero jclic para saber el nombre real 275 288 with zipfile.ZipFile(name_zip,"r") as zip_file: 276 289 for member in zip_file.namelist(): 277 290 filename=os.path.basename(member) 278 291 #Me aseguro que no es una linea en blanco 279 if isNotEmpty(filename): 280 #transformamos mayusculas y espacios en minusculas y raya baja 281 filename=filename.replace(" ", "_").lower() 282 if filename == "index.html": 283 html5=True 284 filename=remove_utf8(filename) 285 source=zip_file.open(member) 286 target=file(os.path.join(extract_dir,filename), "wb") 287 shutil.copyfileobj(source, target) 288 289 290 #Averiguamos el fichero del jclic 291 for file in os.listdir(extract_dir): 292 if file.endswith(".jclic"): 293 name_jclic=file 294 print "name_jclic: %s"%name_jclic 295 296 extend_jclic=os.path.join(extract_dir, name_jclic) 297 292 if filename.endswith(".jclic"): 293 #print "tengo el fichero jclic: %s"%filename 294 tilte="Untiled" 295 with zip_file.open(filename) as f: 296 for line in f: 297 #obtengo el titulo del index 298 if "<title>" in line or "<Title>" in line: 299 title=title_file(line)[1] 300 301 302 303 304 if (title.lower()).strip() in ["","sin nombre", "sense nom"]: 305 title=dir_name 306 print "Titulo sin nombre" 307 308 print "Jclic Titulo: %s"%title 298 309 299 310 #Creacion del index.html 300 if not html5: 301 index_write(extract_dir,index,index_create(extend_jclic)[1],jclic_js,name_jclic) 302 303 304 305 #Modificando el fichero jclic con nuevas rutas 306 jclic_review (extend_jclic) 307 os.chmod(extend_jclic,0775) 308 #textito=os.path.dirname(name_zip) 309 #with open("/tmp/kkita.txt", "w") as text_file: 310 # text_file.write("Path name_zip: %s" % textito) 311 #Movemos el fichero del jclic original 312 if "jclic_uploads" in os.path.dirname(name_zip): 313 print "Lo muevo" 314 new_name=dir_jclic_orig+"/"+orig_name_file 315 shutil.move(name_zip,new_name) 311 jclic_filename=os.path.basename(name_zip) 312 print "genero el index con extract_dir: %s -index: %s - title: %s - jclic_js: %s - jar_path_lib: %s - name_zip: %s "%(extract_dir,index,title,jclic_plugin,jar_path_lib,jclic_filename) 313 index_write(extract_dir,index,title,jclic_plugin,jar_path_lib,jclic_filename) 314 315 new_name=os.path.join(extract_dir, jclic_filename) 316 shutil.move(name_zip,new_name) 316 317 317 318 … … 322 323 323 324 except Exception as e: 324 print Exception325 print e 325 326 sys.exit() 326 327
Note: See TracChangeset
for help on using the changeset viewer.