cleaning up gopher publishing + more verbose docs
This commit is contained in:
		
							parent
							
								
									e3669b8135
								
							
						
					
					
						commit
						9fd7b8020e
					
				| @ -4,22 +4,28 @@ This module contains gopher-related stuff. | |||||||
| import getpass | import getpass | ||||||
| import os | import os | ||||||
| import time | import time | ||||||
|  | import subprocess | ||||||
| 
 | 
 | ||||||
| from . import util | from . import util | ||||||
| from .core import parse_date | from .core import parse_date | ||||||
| 
 | 
 | ||||||
| GOPHER_PROMPT = """ | GOPHER_PROMPT = """ | ||||||
| Would you like to publish your feels to gopher? |  | ||||||
| 
 |  | ||||||
| gopher is a pre-web technology that is text-oriented and primarily used to | gopher is a pre-web technology that is text-oriented and primarily used to | ||||||
| share folders of your files with the world. | share folders of your files with the world. | ||||||
| 
 | 
 | ||||||
|  | Would you like to publish your feels to gopher? | ||||||
|  | 
 | ||||||
|  | Entries you write will automatically get linked to ~/public_gopher/feels/, | ||||||
|  | including gophermap generation. Files you manually delete will no longer be | ||||||
|  | visible from your gopherhole, and will be purged from your gophermap on your | ||||||
|  | next entry update. | ||||||
|  | 
 | ||||||
| If you don't know what it is or don't want it that is totally ok! | If you don't know what it is or don't want it that is totally ok! | ||||||
| 
 | 
 | ||||||
| You can always change this later.""".lstrip() | You can always change this later.""".lstrip() | ||||||
| 
 | 
 | ||||||
| GOPHERMAP_HEADER = """ | GOPHERMAP_HEADER = """ | ||||||
|  welcome to {user}'s feels on gopher. |  welcome to {user}'s gopherfeels. | ||||||
| 
 | 
 | ||||||
|      .::                     .:: |      .::                     .:: | ||||||
|    .:                        .:: |    .:                        .:: | ||||||
| @ -29,12 +35,12 @@ GOPHERMAP_HEADER = """ | |||||||
|    .::  .:        .:         .::    .:: |    .::  .:        .:         .::    .:: | ||||||
|    .::    .::::     .::::   .:::.:: .:: |    .::    .::::     .::::   .:::.:: .:: | ||||||
| 
 | 
 | ||||||
|  this file was created on their behalf by ttbp. |  this file is automatically generated by ttbp. | ||||||
| 
 | 
 | ||||||
| 0(about ttbp)\t/~endorphant/ttbp.txt\ttilde.town\t70 | 0(about ttbp)\t/~endorphant/ttbp.txt\ttilde.town\t70 | ||||||
| 1(back to user's home)\t/~{user} | 1(back to user's home)\t/~{user} | ||||||
| 
 | 
 | ||||||
|  entries: | entries: | ||||||
| 
 | 
 | ||||||
| """ | """ | ||||||
| 
 | 
 | ||||||
| @ -52,7 +58,7 @@ def publish_gopher(gopher_path, entry_filenames): | |||||||
|         gopher_path) |         gopher_path) | ||||||
| 
 | 
 | ||||||
|     if not os.path.isdir(ttbp_gopher): |     if not os.path.isdir(ttbp_gopher): | ||||||
|         print('\n\tERROR: something is wrong. your gopher directory is missing. re-enable gopher publishing.') |         print('\n\tERROR: something is wrong. your gopher directory is missing. re-enable gopher publishing from the settings menu to fix this up!') | ||||||
|         return |         return | ||||||
| 
 | 
 | ||||||
|     with open(os.path.join(ttbp_gopher, 'gophermap'), 'w') as gophermap: |     with open(os.path.join(ttbp_gopher, 'gophermap'), 'w') as gophermap: | ||||||
| @ -61,11 +67,15 @@ def publish_gopher(gopher_path, entry_filenames): | |||||||
|         for entry_filename in entry_filenames: |         for entry_filename in entry_filenames: | ||||||
|             filename = os.path.basename(entry_filename) |             filename = os.path.basename(entry_filename) | ||||||
| 
 | 
 | ||||||
|  |             ''' old file copying bit | ||||||
|             with open(os.path.join(ttbp_gopher, filename), 'w') as gopher_entry: |             with open(os.path.join(ttbp_gopher, filename), 'w') as gopher_entry: | ||||||
|                 with open(entry_filename, 'r') as source_entry: |                 with open(entry_filename, 'r') as source_entry: | ||||||
|                     gopher_entry.write(source_entry.read()) |                     gopher_entry.write(source_entry.read()) | ||||||
|  |             ''' | ||||||
|  |             # symlink instead | ||||||
|  | 
 | ||||||
|  |             subprocess.call(["ln", "-s", entry_filename, os.path.join(ttbp_gopher, os.path.basename(entry_fileNAME))]) | ||||||
| 
 | 
 | ||||||
|             #label = time.strftime("%Y-%m-%d at %H:%M", time.localtime(os.path.getmtime(entry_filename))) |  | ||||||
|             label = "-".join(parse_date(entry_filename)) |             label = "-".join(parse_date(entry_filename)) | ||||||
|             gophermap.write('0{file_label}\t{filename}\n'.format( |             gophermap.write('0{file_label}\t{filename}\n'.format( | ||||||
|                 file_label=label, |                 file_label=label, | ||||||
| @ -75,8 +85,8 @@ def publish_gopher(gopher_path, entry_filenames): | |||||||
| def setup_gopher(gopher_path): | def setup_gopher(gopher_path): | ||||||
|     """Given a path relative to ~/public_gopher, this function: |     """Given a path relative to ~/public_gopher, this function: | ||||||
| 
 | 
 | ||||||
|     - creates a directory under public_gopher |     - creates a directory ~/.ttbp/gopher | ||||||
|     - creates a landing page |     - symlinks that directory to ~/public_gopher/{gopher_path} | ||||||
| 
 | 
 | ||||||
|     It doesn't create a gophermap as that is left to the publish_gopher |     It doesn't create a gophermap as that is left to the publish_gopher | ||||||
|     function. |     function. | ||||||
| @ -91,4 +101,8 @@ def setup_gopher(gopher_path): | |||||||
|         print("\n\tERROR: gopher path is already set up. quitting so we don't overwrite anything.") |         print("\n\tERROR: gopher path is already set up. quitting so we don't overwrite anything.") | ||||||
|         return |         return | ||||||
| 
 | 
 | ||||||
|     os.makedirs(ttbp_gopher) |     #os.makedirs(ttbp_gopher) | ||||||
|  | 
 | ||||||
|  |     gopher_entries = os.path.join(os.path.expanduser("~/.ttbp"), "gopher") | ||||||
|  |     os.makedirs(gopher_entries) | ||||||
|  |     subprocess.call(["ln", "-s", gopher_entries, ttbp_gopher]) | ||||||
|  | |||||||
							
								
								
									
										14
									
								
								ttbp/ttbp.py
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								ttbp/ttbp.py
									
									
									
									
									
								
							| @ -354,6 +354,9 @@ def valid_setup(): | |||||||
|         if not os.path.exists(os.path.join(config.WWW, SETTINGS.get("pubish dir"))): |         if not os.path.exists(os.path.join(config.WWW, SETTINGS.get("pubish dir"))): | ||||||
|             return False |             return False | ||||||
| 
 | 
 | ||||||
|  |     if not SETTINGS.get("gopher"): | ||||||
|  |         return False | ||||||
|  | 
 | ||||||
|     return True |     return True | ||||||
| 
 | 
 | ||||||
| def setup_repair(): | def setup_repair(): | ||||||
| @ -376,9 +379,9 @@ def setup(): | |||||||
|     master setup function |     master setup function | ||||||
| 
 | 
 | ||||||
|     * editor selection |     * editor selection | ||||||
|     * publishing toggle |     * publishing toggle (publish/unpublish as needed) | ||||||
|     * publish/unpublish as needed |  | ||||||
|     * directory selection |     * directory selection | ||||||
|  |     * gopher opt in/out | ||||||
| 
 | 
 | ||||||
|     TODO: break this out better? |     TODO: break this out better? | ||||||
|     ''' |     ''' | ||||||
| @ -661,15 +664,13 @@ def show_credits(): | |||||||
|     ''' |     ''' | ||||||
| 
 | 
 | ||||||
|     print(""" |     print(""" | ||||||
| ttbp was written by ~endorphant in python. the codebase is | ttbp was written for tilde.town by ~endorphant in python. the codebase is | ||||||
| publicly available on github at https://github.com/modgethanc/ttbp | publicly available on github at https://github.com/modgethanc/ttbp | ||||||
| 
 | 
 | ||||||
| other contributors: | other contributors: | ||||||
|     ~vilmibm, packaging help and gopher support |     ~vilmibm, packaging help and gopher support | ||||||
|     ~sanqui, the bug swatter |     ~sanqui, the bug swatter | ||||||
| 
 | 
 | ||||||
| for the full changelog, see ~endorphant/projects/ttbp/changelog.txt |  | ||||||
| 
 |  | ||||||
| if you have ideas for ttbp, you are welcome to contact me to discuss them; | if you have ideas for ttbp, you are welcome to contact me to discuss them; | ||||||
| please send me tildemail or open a github issue. i am not a very experienced | please send me tildemail or open a github issue. i am not a very experienced | ||||||
| developer, and ttbp is one of my first public-facing projects, so i appreciate | developer, and ttbp is one of my first public-facing projects, so i appreciate | ||||||
| @ -719,8 +720,9 @@ editor. | |||||||
|         core.write("index.html") |         core.write("index.html") | ||||||
|         left = "posted to "+config.LIVE+config.USER+"/"+str(SETTINGS.get("publish dir"))+"/index.html\n\n>" |         left = "posted to "+config.LIVE+config.USER+"/"+str(SETTINGS.get("publish dir"))+"/index.html\n\n>" | ||||||
| 
 | 
 | ||||||
|     if SETTINGS['gopher']: |     if SETTINGS.get('gopher'): | ||||||
|         gopher.publish_gopher('feels', core.get_files()) |         gopher.publish_gopher('feels', core.get_files()) | ||||||
|  |         left += "also posted to your ~/public_gopher!" | ||||||
|     redraw(left + " thanks for sharing your feels!") |     redraw(left + " thanks for sharing your feels!") | ||||||
| 
 | 
 | ||||||
|     return |     return | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user