def backup(args): global options parser = optparse.OptionParser(usage="%prog [options] ") parser.add_option("-v", "--verbose", action = "store_true", help = "print debug data") (options, args) = parser.parse_args(args) verbose("Args are: %s " % args) ## setting up the location for the world file to be saved to # split the list into strings location = sys.path[0].split("/") # create a seperate path for finding the world file world_location = "/".join(location) verbose("world folder in:"+world_location) # make the strings back into a list for location to save the backup world backup_location = os.path.join(world_location,"backups","world") # change the dir to find the world dir os.chdir(world_location) ##SAVE os.system("screen -r %s -X stuff \"save-all $(echo -ne '\\r')\"" % config.readScreenName()) time.sleep(3) os.system("screen -r %s -X stuff \"save-off $(echo -ne '\\r')\"" % config.readScreenName()) time.sleep(1) #find the current time today = datetime.datetime.today().strftime("%Y-%m-%d-%H-%M-%S") shutil.copytree("world", os.path.join(backup_location,today)) #ZIP IT UP BITCH os.chdir(backup_location) #YEA MAN zipper(today,today+".zip") shutil.rmtree(today) time.sleep(1) os.system("screen -r %s -X stuff \"save-on $(echo -ne '\\r')\"" % config.readScreenName()) print bcolors.OKGREEN + "Backup Done!" + bcolors.ENDC
def stop(args): global options global screen_child #begin by parsing command line arguments #setup the f****n parser parser = optparse.OptionParser(\ usage=bcolors.OKGREEN+"%prog start" + bcolors.ENDC) parser.add_option('-v', '--verbose', action='store_true', help='print debug data') (options, args) = parser.parse_args(args) verbose("Attempting to stop "+config.readScreenName()) screen_child = pexpect.spawn('screen', ['-r', config.readScreenName()]) try: screen_child.expect('There is no screen', timeout = 1) print bcolors.FAIL + 'Server not found to be running... try %smanage.py start%s' % (bcolors.OKBLUE, bcolors.ENDC) except pexpect.TIMEOUT: stop_server()
def connect(args): os.system('screen -r %s' % config.readScreenName())