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 = zipfile.ZipFile(self.zip_archive, mode="a")
|
||||||
zf.write(self.config.crypt_dir)
|
zf.write(self.config.crypt_dir)
|
||||||
zf.close()
|
zf.close()
|
||||||
except e:
|
except zipfile.LargeZipFile as e:
|
||||||
raise PappyException("Error creating the zipfile. Error: ", e)
|
raise PappyException("Project zipfile too large. Error: ", e)
|
||||||
pass
|
|
||||||
|
|
||||||
def unzip_project(self):
|
def unzip_project(self):
|
||||||
"""
|
"""
|
||||||
|
@ -63,7 +62,7 @@ class Compress(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
zf.extract("config.json")
|
zf.extract("config.json")
|
||||||
except e:
|
except zipfile.BadZipfile as e:
|
||||||
raise PappyException("Project archive contents corrupted. Error: ", e)
|
raise PappyException("Project archive contents corrupted. Error: ", e)
|
||||||
|
|
||||||
zf.extractall()
|
zf.extractall()
|
||||||
|
@ -80,5 +79,5 @@ class Compress(object):
|
||||||
try:
|
try:
|
||||||
with tarfile.open(self.bz2_archive, "r:bz2") as archive:
|
with tarfile.open(self.bz2_archive, "r:bz2") as archive:
|
||||||
archive.extractall()
|
archive.extractall()
|
||||||
except tarfile.ExtractError, e:
|
except tarfile.ExtractError as e:
|
||||||
raise PappyException("Project archive contents corrupted. Error: ", e)
|
raise PappyException("Project archive contents corrupted. Error: ", e)
|
||||||
|
|
|
@ -82,6 +82,8 @@ class Crypto(object):
|
||||||
archive = fern.decrypt(archive_crypt)
|
archive = fern.decrypt(archive_crypt)
|
||||||
except InvalidToken:
|
except InvalidToken:
|
||||||
raise PappyException("Problem decrypting the file, restart pappy to try again")
|
raise PappyException("Problem decrypting the file, restart pappy to try again")
|
||||||
|
reactor.stop()
|
||||||
|
defer.returnValue(None)
|
||||||
|
|
||||||
archive_file.write(archive)
|
archive_file.write(archive)
|
||||||
archive_file.close()
|
archive_file.close()
|
||||||
|
@ -162,7 +164,7 @@ class Crypto(object):
|
||||||
try:
|
try:
|
||||||
if not self.key:
|
if not self.key:
|
||||||
self.key = b64encode(scrypt.hash(self.password, self.salt, buflen=32))
|
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)
|
raise PappyException("Scrypt failed with type error: ", e)
|
||||||
except scrypt.error, e:
|
except scrypt.error, e:
|
||||||
raise PappyException("Scrypt failed with internal error: ", e)
|
raise PappyException("Scrypt failed with internal error: ", e)
|
||||||
|
|
|
@ -71,6 +71,12 @@ class PappySession(object):
|
||||||
def start(self):
|
def start(self):
|
||||||
from . import proxy, plugin
|
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 the data file doesn't exist, create it with restricted permissions
|
||||||
if not os.path.isfile(self.config.datafile):
|
if not os.path.isfile(self.config.datafile):
|
||||||
with os.fdopen(os.open(self.config.datafile, os.O_CREAT, 0o0600), 'r'):
|
with os.fdopen(os.open(self.config.datafile, os.O_CREAT, 0o0600), 'r'):
|
||||||
|
@ -216,10 +222,6 @@ def main():
|
||||||
if settings['crypt']:
|
if settings['crypt']:
|
||||||
pappy_config.crypt_file = settings['crypt']
|
pappy_config.crypt_file = settings['crypt']
|
||||||
pappy_config.crypt_session = True
|
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']:
|
elif settings['lite']:
|
||||||
conf_settings = pappy_config.get_default_config()
|
conf_settings = pappy_config.get_default_config()
|
||||||
conf_settings['debug_dir'] = None
|
conf_settings['debug_dir'] = None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue