forked from indymedia/epicyon
				
			Tidying of the command arguments
							parent
							
								
									e1f656ffe6
								
							
						
					
					
						commit
						27858b70e9
					
				
							
								
								
									
										65
									
								
								epicyon.py
								
								
								
								
							
							
						
						
									
										65
									
								
								epicyon.py
								
								
								
								
							|  | @ -17,6 +17,7 @@ from posts import createOutbox | ||||||
| from posts import archivePosts | from posts import archivePosts | ||||||
| from posts import sendPost | from posts import sendPost | ||||||
| from posts import getPersonBox | from posts import getPersonBox | ||||||
|  | from posts import getPublicPostsOfPerson | ||||||
| from session import createSession | from session import createSession | ||||||
| from session import getJson | from session import getJson | ||||||
| import json | import json | ||||||
|  | @ -48,12 +49,14 @@ def str2bool(v): | ||||||
|         raise argparse.ArgumentTypeError('Boolean value expected.') |         raise argparse.ArgumentTypeError('Boolean value expected.') | ||||||
|      |      | ||||||
| parser = argparse.ArgumentParser(description='ActivityPub Server') | parser = argparse.ArgumentParser(description='ActivityPub Server') | ||||||
| parser.add_argument('-d','--domain', dest='domain', type=str,default='localhost', | parser.add_argument('-d','--domain', dest='domain', type=str,default=None, | ||||||
|                     help='Domain name of the server') |                     help='Domain name of the server') | ||||||
| parser.add_argument('-p','--port', dest='port', type=int,default=80, | parser.add_argument('-p','--port', dest='port', type=int,default=8085, | ||||||
|                     help='Port number to run on') |                     help='Port number to run on') | ||||||
| parser.add_argument('--path', dest='baseDir', type=str,default=os.getcwd(), | parser.add_argument('--path', dest='baseDir', type=str,default=os.getcwd(), | ||||||
|                     help='Directory in which to store posts') |                     help='Directory in which to store posts') | ||||||
|  | parser.add_argument('--posts', dest='posts', type=str,default=None, | ||||||
|  |                     help='Show posts for the given handle') | ||||||
| parser.add_argument('-f','--federate', nargs='+',dest='federationList', | parser.add_argument('-f','--federate', nargs='+',dest='federationList', | ||||||
|                     help='Specify federation list separated by spaces') |                     help='Specify federation list separated by spaces') | ||||||
| parser.add_argument("--https", type=str2bool, nargs='?', | parser.add_argument("--https", type=str2bool, nargs='?', | ||||||
|  | @ -65,13 +68,23 @@ parser.add_argument("--tor", type=str2bool, nargs='?', | ||||||
| parser.add_argument("--tests", type=str2bool, nargs='?', | parser.add_argument("--tests", type=str2bool, nargs='?', | ||||||
|                         const=True, default=False, |                         const=True, default=False, | ||||||
|                         help="Run unit tests") |                         help="Run unit tests") | ||||||
|  | parser.add_argument("--testsnetwork", type=str2bool, nargs='?', | ||||||
|  |                         const=True, default=False, | ||||||
|  |                         help="Run network unit tests") | ||||||
| args = parser.parse_args() | args = parser.parse_args() | ||||||
|  | 
 | ||||||
| if args.tests: | if args.tests: | ||||||
|     runAllTests() |     runAllTests() | ||||||
|     sys.exit() |     sys.exit() | ||||||
| 
 | 
 | ||||||
| print(args.domain) | if args.testsnetwork: | ||||||
| print(str(args.federationList)) |     print('Network Tests') | ||||||
|  |     testPostMessageBetweenServers() | ||||||
|  |     sys.exit() | ||||||
|  | 
 | ||||||
|  | if not args.domain: | ||||||
|  |     print('Specify a domain with --domain [name]') | ||||||
|  |     sys.exit() | ||||||
|      |      | ||||||
| nickname='admin' | nickname='admin' | ||||||
| domain=args.domain | domain=args.domain | ||||||
|  | @ -87,44 +100,10 @@ federationList=[] | ||||||
| if args.federationList: | if args.federationList: | ||||||
|     federationList=args.federationList.copy() |     federationList=args.federationList.copy() | ||||||
| 
 | 
 | ||||||
| session = createSession(domain,port,useTor) | if args.posts: | ||||||
| personCache={} |     nickname=args.posts.split('@')[0] | ||||||
| cachedWebfingers={} |     domain=args.posts.split('@')[1] | ||||||
|  |     getPublicPostsOfPerson(nickname,domain) | ||||||
|  |     sys.exit() | ||||||
| 
 | 
 | ||||||
| privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(baseDir,nickname,domain,port,https,True) |  | ||||||
| #deleteAllPosts(baseDir,nickname,domain) |  | ||||||
| setPreferredNickname(baseDir,nickname,domain,'badger') |  | ||||||
| setBio(baseDir,nickname,domain,'Some personal info') |  | ||||||
| #createPublicPost(baseDir,nickname, domain, port,https, "G'day world!", False, True, None, None, 'Not suitable for Vogons') |  | ||||||
| #archivePosts(nickname,domain,baseDir,4) |  | ||||||
| #outboxJson=createOutbox(baseDir,nickname,domain,port,https,2,True,None) |  | ||||||
| #pprint(outboxJson) |  | ||||||
| 
 |  | ||||||
| #testPostMessageBetweenServers() |  | ||||||
| runDaemon(domain,port,https,federationList,useTor) | runDaemon(domain,port,https,federationList,useTor) | ||||||
| 
 |  | ||||||
| #testHttpsig() |  | ||||||
| sys.exit() |  | ||||||
| 
 |  | ||||||
| #pprint(person) |  | ||||||
| #print('\n') |  | ||||||
| #pprint(wfEndpoint) |  | ||||||
| 
 |  | ||||||
| handle="https://mastodon.social/@Gargron" |  | ||||||
| wfRequest = webfingerHandle(session,handle,True,cachedWebfingers) |  | ||||||
| if not wfRequest: |  | ||||||
|     sys.exit() |  | ||||||
| 
 |  | ||||||
| personUrl,pubKeyId,pubKey,personId=getPersonBox(session,wfRequest,personCache,'outbox') |  | ||||||
| #pprint(personUrl) |  | ||||||
| #sys.exit() |  | ||||||
| 
 |  | ||||||
| wfResult = json.dumps(wfRequest, indent=4, sort_keys=True) |  | ||||||
| #print(str(wfResult)) |  | ||||||
| #sys.exit() |  | ||||||
| 
 |  | ||||||
| maxMentions=10 |  | ||||||
| maxEmoji=10 |  | ||||||
| maxAttachments=5 |  | ||||||
| userPosts = getPosts(session,personUrl,30,maxMentions,maxEmoji,maxAttachments,federationList,personCache) |  | ||||||
| #print(str(userPosts)) |  | ||||||
|  |  | ||||||
							
								
								
									
										23
									
								
								posts.py
								
								
								
								
							
							
						
						
									
										23
									
								
								posts.py
								
								
								
								
							|  | @ -536,3 +536,26 @@ def archivePosts(nickname: str,domain: str,baseDir: str, \ | ||||||
|             noOfPosts -= 1 |             noOfPosts -= 1 | ||||||
|             if noOfPosts <= maxPostsInOutbox: |             if noOfPosts <= maxPostsInOutbox: | ||||||
|                 break |                 break | ||||||
|  | 
 | ||||||
|  | def getPublicPostsOfPerson(nickname,domain): | ||||||
|  |     """ This is really just for test purposes | ||||||
|  |     """ | ||||||
|  |     useTor=True | ||||||
|  |     session = createSession(domain,port,useTor) | ||||||
|  |     personCache={} | ||||||
|  |     cachedWebfingers={} | ||||||
|  |     federationList=[] | ||||||
|  | 
 | ||||||
|  |     handle="https://"+domain+"/@"+nickname | ||||||
|  |     wfRequest = webfingerHandle(session,handle,True,cachedWebfingers) | ||||||
|  |     if not wfRequest: | ||||||
|  |         sys.exit() | ||||||
|  | 
 | ||||||
|  |     personUrl,pubKeyId,pubKey,personId=getPersonBox(session,wfRequest,personCache,'outbox') | ||||||
|  |     wfResult = json.dumps(wfRequest, indent=4, sort_keys=True) | ||||||
|  | 
 | ||||||
|  |     maxMentions=10 | ||||||
|  |     maxEmoji=10 | ||||||
|  |     maxAttachments=5 | ||||||
|  |     userPosts = getPosts(session,personUrl,30,maxMentions,maxEmoji,maxAttachments,federationList,personCache) | ||||||
|  |     #print(str(userPosts)) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue