forked from endorphant/ttbp
		
	adding environment validator and nopub clearer
on startup, ttbp checks to see if the environment is valid, and prompts user to run setup again if not. also, nopub files are now removed from html if they were generated.
This commit is contained in:
		
							parent
							
								
									aebdd51d08
								
							
						
					
					
						commit
						d33bdbfab1
					
				
							
								
								
									
										35
									
								
								bin/_ttbp.py
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								bin/_ttbp.py
									
									
									
									
									
								
							| @ -57,7 +57,6 @@ p = inflect.engine() | ||||
| 
 | ||||
| ## user globals | ||||
| USER = os.path.basename(os.path.expanduser("~")) | ||||
| 
 | ||||
| PATH = os.path.join("/home", USER, ".ttbp") | ||||
| PUBLIC = os.path.join("/home", USER, "public_html") | ||||
| WWW = os.path.join(PATH, "www") | ||||
| @ -158,6 +157,7 @@ def check_init(): | ||||
|     if os.path.exists(os.path.join(os.path.expanduser("~"),".ttbp")): | ||||
|         print(chatter.say("greet")+", "+USER+".\n") | ||||
| 
 | ||||
|         ''' | ||||
|         ## ttbprc validation | ||||
|         while not os.path.isfile(TTBPRC): | ||||
|             setup_repair() | ||||
| @ -165,6 +165,11 @@ def check_init(): | ||||
|             SETTINGS = json.load(open(TTBPRC)) | ||||
|         except ValueError: | ||||
|             setup_repair() | ||||
|         ''' | ||||
| 
 | ||||
|         ## ttbp env validation | ||||
|         if not valid_setup(): | ||||
|             setup_repair() | ||||
| 
 | ||||
|         ## version checker | ||||
|         mismatch = build_mismatch() | ||||
| @ -256,6 +261,33 @@ def gen_header(): | ||||
|     """ | ||||
|     return header | ||||
| 
 | ||||
| def valid_setup(): | ||||
|     ''' | ||||
|     Checks to see if user has a sane ttbp environment. | ||||
|     ''' | ||||
| 
 | ||||
|     global SETTINGS | ||||
| 
 | ||||
|     if not os.path.isfile(TTBPRC): | ||||
|         return False | ||||
| 
 | ||||
|     try: | ||||
|         SETTINGS = json.load(open(TTBPRC)) | ||||
|     except ValueError: | ||||
|         return False | ||||
| 
 | ||||
|     if core.publishing(): | ||||
|         if not SETTINGS.get("publish dir"): | ||||
|             return False | ||||
| 
 | ||||
|         if not os.path.exists(WWW): | ||||
|             return False | ||||
| 
 | ||||
|         if not os.path.exists(os.path.join(WWW, SETTINGS.get("pubish dir"))): | ||||
|             return False | ||||
| 
 | ||||
|     return True | ||||
| 
 | ||||
| def setup_repair(): | ||||
|     ''' | ||||
|     setup repair function | ||||
| @ -296,6 +328,7 @@ def setup(): | ||||
| 
 | ||||
|     # publishing selection | ||||
|     SETTINGS.update({"publishing":select_publishing()}) | ||||
|     core.reload_ttbprc(SETTINGS) | ||||
|     update_publishing() | ||||
|     redraw("blog publishing: "+str(core.publishing())) | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										12
									
								
								bin/core.py
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								bin/core.py
									
									
									
									
									
								
							| @ -69,6 +69,15 @@ def load(ttbprc={}): | ||||
| 
 | ||||
|     load_files() | ||||
| 
 | ||||
| def reload_ttbprc(ttbprc={}): | ||||
|     ''' | ||||
|     reloads new ttbprc into current session | ||||
|     ''' | ||||
| 
 | ||||
|     global SETTINGS | ||||
| 
 | ||||
|     SETTINGS = ttbprc | ||||
| 
 | ||||
| def load_files(): | ||||
|     ''' | ||||
|     file loader | ||||
| @ -83,6 +92,9 @@ def load_files(): | ||||
| 
 | ||||
|     for filename in os.listdir(DATA): | ||||
|         if nopub(filename): | ||||
|             link = os.path.join(WWW, os.path.splitext(os.path.basename(filename))[0]+".html") | ||||
|             if os.path.exists(link): | ||||
|                 subprocess.call(["rm", link]) | ||||
|             continue | ||||
|         filename = os.path.join(DATA, filename) | ||||
|         if os.path.isfile(filename) and valid(filename): | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user