Minor changes, decrypt project within PappySession
Changed to decrypting project to within the PappySession object, instead of in main. More maintainable, and makes more sense.
This commit is contained in:
parent
e7d1f75435
commit
ff8595e8f4
3 changed files with 13 additions and 10 deletions
|
@ -45,9 +45,8 @@ class Compress(object):
|
|||
zf = zipfile.ZipFile(self.zip_archive, mode="a")
|
||||
zf.write(self.config.crypt_dir)
|
||||
zf.close()
|
||||
except e:
|
||||
raise PappyException("Error creating the zipfile. Error: ", e)
|
||||
pass
|
||||
except zipfile.LargeZipFile as e:
|
||||
raise PappyException("Project zipfile too large. Error: ", e)
|
||||
|
||||
def unzip_project(self):
|
||||
"""
|
||||
|
@ -63,7 +62,7 @@ class Compress(object):
|
|||
|
||||
try:
|
||||
zf.extract("config.json")
|
||||
except e:
|
||||
except zipfile.BadZipfile as e:
|
||||
raise PappyException("Project archive contents corrupted. Error: ", e)
|
||||
|
||||
zf.extractall()
|
||||
|
@ -80,5 +79,5 @@ class Compress(object):
|
|||
try:
|
||||
with tarfile.open(self.bz2_archive, "r:bz2") as archive:
|
||||
archive.extractall()
|
||||
except tarfile.ExtractError, e:
|
||||
except tarfile.ExtractError as e:
|
||||
raise PappyException("Project archive contents corrupted. Error: ", e)
|
||||
|
|
|
@ -82,6 +82,8 @@ class Crypto(object):
|
|||
archive = fern.decrypt(archive_crypt)
|
||||
except InvalidToken:
|
||||
raise PappyException("Problem decrypting the file, restart pappy to try again")
|
||||
reactor.stop()
|
||||
defer.returnValue(None)
|
||||
|
||||
archive_file.write(archive)
|
||||
archive_file.close()
|
||||
|
@ -162,7 +164,7 @@ class Crypto(object):
|
|||
try:
|
||||
if not self.key:
|
||||
self.key = b64encode(scrypt.hash(self.password, self.salt, buflen=32))
|
||||
except TypeError, e:
|
||||
except TypeError as e:
|
||||
raise PappyException("Scrypt failed with type error: ", e)
|
||||
except scrypt.error, e:
|
||||
raise PappyException("Scrypt failed with internal error: ", e)
|
||||
|
|
|
@ -70,6 +70,12 @@ class PappySession(object):
|
|||
@defer.inlineCallbacks
|
||||
def start(self):
|
||||
from . import proxy, plugin
|
||||
|
||||
if self.config.crypt_session:
|
||||
self.decrypt()
|
||||
self.config.load_from_file('./config.json')
|
||||
self.config.global_load_from_file()
|
||||
self.delete_data_on_quit = False
|
||||
|
||||
# If the data file doesn't exist, create it with restricted permissions
|
||||
if not os.path.isfile(self.config.datafile):
|
||||
|
@ -216,10 +222,6 @@ def main():
|
|||
if settings['crypt']:
|
||||
pappy_config.crypt_file = settings['crypt']
|
||||
pappy_config.crypt_session = True
|
||||
session.decrypt()
|
||||
conf_settings = pappy_config.load_from_file('./config.json')
|
||||
pappy_config.global_load_from_file()
|
||||
session.delete_data_on_quit = False
|
||||
elif settings['lite']:
|
||||
conf_settings = pappy_config.get_default_config()
|
||||
conf_settings['debug_dir'] = None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue