Refactor code

master
Arinerron 2018-04-22 20:49:53 -07:00
parent a5dbf73df4
commit 0dc6a0b6c5
No known key found for this signature in database
GPG Key ID: 99383627861C62F0
3 changed files with 14 additions and 15 deletions

View File

@ -556,13 +556,11 @@ class Onionr:
return
def get_hostname(self):
retVal = ''
try:
with open('./data/hs/hostname', 'r') as hostname:
retVal = hostname.read()
except FileNotFoundError:
retVal = None
return retVal
return hostname.read().strip()
except Exception:
return None
def addFile(self):
'''command to add a file to the onionr network'''

View File

@ -17,8 +17,10 @@
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 nacl.encoding, nacl.hash, nacl.utils, time, math, threading, binascii, logger
import btc
class POW:
def pow(self, reporting = False):
startTime = math.floor(time.time())
@ -77,7 +79,9 @@ class POW:
self.difficulty = newDiff
def getResult(self):
'''Returns the result then sets to false, useful to automatically clear the result'''
'''
Returns the result then sets to false, useful to automatically clear the result
'''
try:
retVal = self.result
except AttributeError:

View File

@ -120,14 +120,11 @@ class OnionrUtils:
def getMyAddress(self):
try:
myAddressFile = open("data/hs/hostname", 'r')
myAddress = myAddressFile.read()
myAddressFile.close()
return myAddress.strip()
with open('./data/hs/hostname', 'r') as hostname:
return hostname.read().strip()
except Exception as error:
logger.error('Failed to read my address.', error=error)
return ''
return None
def localCommand(self, command, silent = True):
'''