removed board plugin for now, added getfile command
This commit is contained in:
		
							parent
							
								
									c1d4040807
								
							
						
					
					
						commit
						cf37823fd7
					
				
					 6 changed files with 30 additions and 71 deletions
				
			
		|  | @ -50,6 +50,7 @@ class Onionr: | |||
|             Main Onionr class. This is for the CLI program, and does not handle much of the logic. | ||||
|             In general, external programs and plugins should not use this class. | ||||
|         ''' | ||||
|         self.userRunDir = os.getcwd() # Directory user runs the program from | ||||
|         try: | ||||
|             os.chdir(sys.path[0]) | ||||
|         except FileNotFoundError: | ||||
|  | @ -190,6 +191,10 @@ class Onionr: | |||
| 
 | ||||
|             'add-file': self.addFile, | ||||
|             'addfile': self.addFile, | ||||
| 
 | ||||
|             'get-file': self.getFile, | ||||
|             'getfile': self.getFile, | ||||
| 
 | ||||
|             'listconn': self.listConn, | ||||
| 
 | ||||
|             'import-blocks': self.onionrUtils.importNewBlocks, | ||||
|  | @ -230,6 +235,7 @@ class Onionr: | |||
|             'add-peer': 'Adds a peer to database', | ||||
|             'list-peers': 'Displays a list of peers', | ||||
|             'add-file': 'Create an Onionr block from a file', | ||||
|             'get-file': 'Get a file from Onionr blocks', | ||||
|             'import-blocks': 'import blocks from the disk (Onionr is transport-agnostic!)', | ||||
|             'listconn': 'list connected peers', | ||||
|             'kex': 'exchange keys with peers (done automatically)', | ||||
|  | @ -780,6 +786,24 @@ class Onionr: | |||
| 
 | ||||
|         return columns | ||||
| 
 | ||||
|     def getFile(self): | ||||
|         ''' | ||||
|             Get a file from onionr blocks | ||||
|         ''' | ||||
|         if len(sys.argv) >= 3: | ||||
|             fileName = sys.argv[2] | ||||
|             print(fileName) | ||||
|             contents = None | ||||
|             bHash = sys.argv[3] | ||||
|             if os.path.exists(fileName): | ||||
|                 logger.error("File already exists") | ||||
|                 return | ||||
|             if not self.onionrUtils.validateHash(bHash): | ||||
|                 logger.error('Block hash is invalid') | ||||
|                 return | ||||
|             Block.mergeChain(bHash, fileName) | ||||
|         return | ||||
| 
 | ||||
|     def addFile(self): | ||||
|         ''' | ||||
|             Adds a file to the onionr network | ||||
|  | @ -790,8 +814,9 @@ class Onionr: | |||
|             contents = None | ||||
| 
 | ||||
|             if not os.path.exists(filename): | ||||
|                 logger.warn('That file does not exist. Improper path?') | ||||
| 
 | ||||
|                 logger.error('That file does not exist. Improper path (specify full path)?') | ||||
|                 return | ||||
|             logger.info('Adding file... this might take a long time.') | ||||
|             try: | ||||
|                 blockhash = Block.createChain(file = filename) | ||||
|                 logger.info('File %s saved in block %s.' % (filename, blockhash)) | ||||
|  |  | |||
|  | @ -177,6 +177,7 @@ class Block: | |||
|             # signed data is jsonMeta + block content (no linebreak) | ||||
|             self.signedData = (None if not self.isSigned() else self.getHeader('meta') + self.getContent()) | ||||
|             self.date = self.getCore().getBlockDate(self.getHash()) | ||||
|             self.claimedTime = self.getHeader('time', None) | ||||
| 
 | ||||
|             if not self.getDate() is None: | ||||
|                 self.date = datetime.datetime.fromtimestamp(self.getDate()) | ||||
|  |  | |||
|  | @ -17,7 +17,7 @@ | |||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| ''' | ||||
| import onionrblockapi, logger, onionrexceptions | ||||
| import onionrblockapi, logger, onionrexceptions, json | ||||
| class OnionrUser: | ||||
|     def __init__(self, coreInst, publicKey): | ||||
|         self.trust = 0 | ||||
|  |  | |||
|  | @ -1,5 +0,0 @@ | |||
| { | ||||
|     "name" : "boards", | ||||
|     "version" : "1.0", | ||||
|     "author" : "onionr" | ||||
| } | ||||
|  | @ -1,63 +0,0 @@ | |||
| ''' | ||||
|     Onionr - P2P Anonymous Storage Network | ||||
| 
 | ||||
|     This is an interactive menu-driven CLI interface for Onionr | ||||
| ''' | ||||
| ''' | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| ''' | ||||
| 
 | ||||
| # Imports some useful libraries | ||||
| import logger, config, sys | ||||
| from onionrblockapi import Block | ||||
| try: | ||||
|     import tkinter | ||||
| except (ImportError, NameError) as e: | ||||
|     TK_ENABLED = False | ||||
| else: | ||||
|     TK_ENABLED = True | ||||
| 
 | ||||
| 
 | ||||
| plugin_name = 'cliui' | ||||
| PLUGIN_VERSION = '0.0.1' | ||||
| 
 | ||||
| class OnionrBoards: | ||||
|     def __init__(self, apiInst): | ||||
|         self.api = apiInst | ||||
|         self.myCore = apiInst.get_core() | ||||
| 
 | ||||
|         if TK_ENABLED: | ||||
|             self.gui = tkinter.Tk() | ||||
| 
 | ||||
|         return | ||||
| 
 | ||||
|     def start(self): | ||||
|         return | ||||
| 
 | ||||
| def on_init(api, data = None): | ||||
|     ''' | ||||
|         This event is called after Onionr is initialized, but before the command | ||||
|         inputted is executed. Could be called when daemon is starting or when | ||||
|         just the client is running. | ||||
|     ''' | ||||
| 
 | ||||
|     # Doing this makes it so that the other functions can access the api object | ||||
|     # by simply referencing the variable `pluginapi`. | ||||
|     pluginapi = api | ||||
|     ui = OnionrBoards(api) | ||||
|     api.commands.register('boards', ui.start) | ||||
|     api.commands.register_help('boards', 'Open the board viewer') | ||||
| 
 | ||||
| 
 | ||||
|     return | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue