Exemple #1
0
def resetFactorySettings():
    from astroprint.cloud import astroprintCloud
    from shutil import copy

    logger = logging.getLogger(__name__)
    logger.warning("Executing a Restore Factory Settings operation")

    #We log out first
    astroprintCloud().signout()

    s = settings()

    emptyFolder(s.get(['folder', 'uploads']) or s.getBaseFolder('uploads'))
    emptyFolder(s.get(['folder', 'timelapse']) or s.getBaseFolder('timelapse'))
    emptyFolder(
        s.get(['folder', 'timelapse_tmp']) or s.getBaseFolder('timelapse_tmp'))
    emptyFolder(s.get(['folder', 'virtualSd']) or s.getBaseFolder('virtualSd'))

    networkManager().forgetWifiNetworks()

    configFolder = s.getConfigFolder()

    #replace config.yaml with config.factory
    config_file = s._configfile
    config_factory = os.path.join(configFolder, "config.factory")
    if config_file and os.path.exists(config_file):
        if os.path.exists(config_factory):
            copy(config_factory, config_file)
        else:
            os.unlink(config_file)

    #replace printer-profile.yaml with printer-profile.factory
    p_profile_file = os.path.join(configFolder, "printer-profile.yaml")
    p_profile_factory = os.path.join(configFolder, "printer-profile.factory")
    if os.path.exists(p_profile_file):
        if os.path.exists(p_profile_factory):
            copy(p_profile_factory, p_profile_file)
        else:
            os.unlink(p_profile_file)

    #remove info about users
    user_file = s.get(["accessControl", "userfile"]) or os.path.join(
        configFolder, "users.yaml")
    if user_file and os.path.exists(user_file):
        os.unlink(user_file)

    logger.info("Restore completed, rebooting...")

    #We should reboot the whole device
    if softwareManager.restartServer():
        return jsonify()
    else:
        return ("There was an error rebooting.", 500)
Exemple #2
0
def restartServer():
    if softwareManager.restartServer():
        return jsonify()
    else:
        return ("There was an error trying to restart the server.", 400)
Exemple #3
0
    emptyFolder(s.get(['folder', 'virtualSd']) or s.getBaseFolder('virtualSd'))

    networkManager().forgetWifiNetworks()

    #replace config.yaml with config.factory
    config_file = s._configfile
    os.unlink(config_file)

    #remove info about users
    user_file = settings().get(["accessControl", "userfile"]) or os.path.join(
        os.path.dirname(config_file), "users.yaml")
    if user_file and os.path.exists(user_file):
        os.unlink(user_file)

    #We should reboot the whole device
    if softwareManager.restartServer():
        return jsonify()
    else:
        return ("There was an error rebooting.", 500)


@api.route("/settings/software/check", methods=['GET'])
@restricted_access
def checkSoftwareVersion():
    softwareInfo = softwareManager.checkSoftwareVersion()

    if softwareInfo:
        s = settings()
        s.set(["software", "lastCheck"], time.time())
        s.save()
        return jsonify(softwareInfo)
Exemple #4
0
def restartServer():
	if softwareManager.restartServer():
		return jsonify();
	else:
		return ("There was an error trying to restart the server.", 400)
Exemple #5
0
	#replace config.yaml with config.factory
	config_file = s._configfile
	os.unlink(config_file)

	#remove info about users
	user_file  = settings().get(["accessControl", "userfile"]) or os.path.join( os.path.dirname(config_file), "users.yaml")
	if user_file and os.path.exists(user_file):
		os.unlink(user_file)

	s._config = {}
	s.load(migrate=False)

	networkManager().forgetWifiNetworks()

	#We should reboot the whole device
	softwareManager.restartServer()

	return jsonify()

@api.route("/settings/software/check", methods=['GET'])
@restricted_access
def checkSoftwareVersion():
	softwareInfo = softwareManager.checkSoftwareVersion()

	if softwareInfo:
		return jsonify(softwareInfo);
	else:
		return ("There was an error checking for new software.", 400)

@api.route("/settings/software/update", methods=['POST'])
@restricted_access
Exemple #6
0
	def restartServer(self, data=None, sendResponse=None):
		#We should reboot the whole device
		if softwareManager.restartServer():
			sendResponse({'success': 'no_error'})
		else:
			sendResponse("error_restarting",True)
Exemple #7
0
	def resetFactorySettings(self, data, sendMessage):
		from astroprint.cloud import astroprintCloud
		from shutil import copy

		try:

			#astroprintCloud().signout()
			astroprintCloud().remove_logged_user()

			logger = logging.getLogger(__name__)
			logger.warning("Executing a Restore Factory Settings operation")

			s = settings()

			#empty all folders
			def emptyFolder(folder):
				if folder and os.path.exists(folder):
					for f in os.listdir(folder):
						p = os.path.join(folder, f)
						try:
							if os.path.isfile(p):
								os.unlink(p)
						except Exception, e:
							pass

			emptyFolder(s.get(['folder', 'uploads']) or s.getBaseFolder('uploads'))
			emptyFolder(s.get(['folder', 'timelapse']) or s.getBaseFolder('timelapse'))
			emptyFolder(s.get(['folder', 'timelapse_tmp']) or s.getBaseFolder('timelapse_tmp'))
			emptyFolder(s.get(['folder', 'virtualSd']) or s.getBaseFolder('virtualSd'))

			networkManager().forgetWifiNetworks()

			configFolder = s.getConfigFolder()

			#replace config.yaml with config.factory
			config_file = s._configfile
			config_factory = os.path.join(configFolder, "config.factory")
			if config_file and os.path.exists(config_file):
				if os.path.exists(config_factory):
					copy(config_factory, config_file)
				else:
					os.unlink(config_file)

			#replace printer-profile.yaml with printer-profile.factory
			p_profile_file = os.path.join(configFolder, "printer-profile.yaml")
			p_profile_factory = os.path.join(configFolder, "printer-profile.factory")
			if os.path.exists(p_profile_file):
				if os.path.exists(p_profile_factory):
					copy(p_profile_factory, p_profile_file)
				else:
					os.unlink(p_profile_file)

			#remove info about users
			user_file  = s.get(["accessControl", "userfile"]) or os.path.join( configFolder, "users.yaml")
			if user_file and os.path.exists(user_file):
				os.unlink(user_file)

			logger.info("Restore completed, rebooting...")

			#We should reboot the whole device
			if softwareManager.restartServer():
				sendMessage({'success': 'no_error'})
			else:
				sendMessage("error_rebooting",True)