Exemple #1
0
    def __init__(self, vault=None):
        self.Glacier = Glacier(vault)
               
        self.root = tk.Tk()
        self.root.title("Amazon Glacier - Support Tool")
        w, h   = 640, 480
        ws, hs = self.root.winfo_screenwidth(), self.root.winfo_screenheight()
        x = (ws/2) - (w/2)
        y = (hs/2) - (h/2)
        self.root.geometry("%dx%d+%d+%d" % (w,h,x,y) )

        self.createUI()
        self.updateTick()
        self.root.wm_protocol("WM_DELETE_WINDOW", self.onDelete)
        
        self.Glacier.loadDefault()
        self.updateFileList()
        
        self.root.mainloop()
import matplotlib.pyplot as plt
import numpy as np
import math

from glacier import Glacier

if __name__ == '__main__':
    resolution = 100
    glacier_length = 100000
    x = np.arange(start=0, stop=glacier_length + 1, step=resolution)

    glacier = Glacier(length=glacier_length, isostatic=True)

    densities = dict([
        (3410, dict(linestyle='solid', color='black')),
        (3350, dict(linestyle='dotted', color='red')),
        (3270, dict(linestyle='dashed', color='blue')),
    ])

    plt.figure(figsize=(15, 8))

    for density, line_style in densities.items():
        glacier.mantel_density = density

        surface_height = [glacier.surface_height(value) for value in x]
        bed_depth = [glacier.bed_depth(value) for value in surface_height]

        plt.plot(x,
                 surface_height,
                 label='Density ' + str(density),
                 **line_style)
Exemple #3
0
        #    #TODO: However, it is more efficient to use an Amazon SNS
        #    # notification to determine when a job is complete.
        #    if (job.completed):
        #        self.active_jobs.pop(i)
        #        ret = self.glacier.get_job_output()
        #        print(ret)

class FullPath(argparse.Action):
    """Expand user- and relative-paths"""
    def __call__(self, parser, namespace, values, option_string=None):
        setattr(namespace, self.dest, os.path.abspath(os.path.expanduser(values)))
def is_dir(dirname):
    """Checks if a path is an actual directory"""
    if not os.path.isdir(dirname):
        msg = "{0} is not a directory".format(dirname)
        raise argparse.ArgumentTypeError(msg)
    else:
        return dirname

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="description here")
    parser.add_argument("-d",help="Directory to be uploaded using Multipart",action=FullPath, type=is_dir)
    args = parser.parse_args()
    if (args.d == None):
        app = App()
    else:
        glacier = Glacier()
        glacier.loadDefault()
        glacier.uploadDirectory(args.d)        
        glacier.closeDefault()
Exemple #4
0
class App():
    def __init__(self, vault=None):
        self.Glacier = Glacier(vault)
               
        self.root = tk.Tk()
        self.root.title("Amazon Glacier - Support Tool")
        w, h   = 640, 480
        ws, hs = self.root.winfo_screenwidth(), self.root.winfo_screenheight()
        x = (ws/2) - (w/2)
        y = (hs/2) - (h/2)
        self.root.geometry("%dx%d+%d+%d" % (w,h,x,y) )

        self.createUI()
        self.updateTick()
        self.root.wm_protocol("WM_DELETE_WINDOW", self.onDelete)
        
        self.Glacier.loadDefault()
        self.updateFileList()
        
        self.root.mainloop()

    def onDelete(self):
        self.Glacier.closeDefault()
        self.root.destroy()

    def createUI(self):
        # Add Labels about Vault
        tk.Label(self.root, text="Vault Name: " + self.Glacier.vault.vault_name).pack()
        tk.Label(self.root, text="Creation Date: " + self.Glacier.vault.creation_date).pack()
        tk.Label(self.root, text="# of Archives: " + str(self.Glacier.vault.number_of_archives)).pack()
        tk.Label(self.root, text="Size in bytes: " + str(self.Glacier.vault.size_in_bytes)).pack()

        # Add Main Buttons
        btnTop = tk.Frame(self.root)
        tk.Button(btnTop, text="List Vaults", command=self.listVaults).pack(side=tk.LEFT)
        tk.Button(btnTop, text="Request List Files", command=self.listFiles).pack(side=tk.LEFT)
        tk.Button(btnTop, text="Job Status", command=self.jobStatus).pack(side=tk.LEFT)
        btnTop.pack()

        # Add File Treeview
        cols = ["File","Size","Date"]
        self._files = ttk.Treeview(self.root, columns=cols, show="headings")
        for c in cols: self._files.heading(c,text=c)
        self._files.pack()

        # Add File Buttons
        btnBottom = tk.Frame(self.root)
        tk.Button(btnBottom, text="Upload Directory", command=self.uploadDirectory).pack(side=tk.LEFT)
        tk.Button(btnBottom, text="Upload File", command=self.uploadFile).pack(side=tk.LEFT)
        tk.Button(btnBottom, text="Multipart File Upload", command=self.uploadFileMP).pack(side=tk.LEFT)
        tk.Button(btnBottom, text="Delete File", command=self.deleteFile).pack(side=tk.LEFT)
        btnBottom.pack()
        
    def uploadDirectory(self):
        f = filedialog.askdirectory()
        if ( f != () and os.path.isdir(f) ):
            self.Glacier.uploadDirectory(f)

    def uploadFileMP(self):
        f = filedialog.askopenfilename()
        if ( f != () and os.path.isfile(f) ):
            request = messagebox.askyesno("Multipart Upload","Uploading file in Multiparts: " + f + " ?\nDepending of the size of the file and your bandwidth it may take some time.\nDo you want to continue?")
            if (request): self.Glacier.uploadFileMultiPart(f)


    def uploadFile(self):
        f = filedialog.askopenfilename()
        if ( f != () and os.path.isfile(f) ):
            request = messagebox.askyesno("Upload File","Uploading file: " + f + " ?\nDepending of the size of the file and your bandwidth it may take some time.\nDo you want to continue?")
            if (request):
                self.Glacier.uploadFile(f)
                aid, txtStatus, checksum, comcheck = self.updateFileList()
                # Show Window with Result
                top = tk.Toplevel()
                tk.Label(top, text=txtStatus, height=0, width=150).pack()
                tk.Label(top, text="ArchiveId: " + aid, height=0, width=150).pack()
                tk.Label(top, text=checksum, height=0, width=150).pack()
                tk.Label(top, text=comcheck, height=0, width=150).pack()

    def deleteFile(self):
        focus = self._files.focus()
        if (focus == ''): return
        
        # Get Row
        f = self._files.set(focus)
        # Get File
        ffile = self.Glacier.inventory.getFile(f["Size"], f["Date"], f["File"])
        if (ffile.deleted):
            messagebox.showinfo("File can't be deleted", "File Already Removed from the Cloud")
            return
        
        # Check Interval
        d = dateutil.parser.parse(f["Date"])
        d.replace(tzinfo=None)
        days = (d.replace(tzinfo=None)-datetime.datetime.utcnow()).days
        request = True
        if (days > -90):
            title = "Continue Deleting Archive?"
            msg = """This file was uploaded less than 90 days ago.
This action will cost deletion fee.
Do you want to continue?"""
            request = messagebox.askyesno(title,msg)

        # Delete?
        if (request and ffile.aid != None and ffile.deleted == False):
            self.Glacier.deleteFile(ffile)
            self.updateFileList()
            

    #TODO
    def jobStatus(self):
        jobs = self.Glacier.listJobs()
        top = tk.Toplevel()
        for job in jobs:
            tk.Label(top, text="Action: " + job["Action"] , height=0, width=50).pack()
            tk.Label(top, text="Status: " + job["StatusCode"] , height=0, width=50).pack()
            tk.Label(top, text="Creation Date: " + job["CreationDate"] , height=0, width=50).pack()
            if (job["StatusCode"] == "Succeeded"):
                tk.Label(top, text="Completion Date: " + job["CompletionDate"] , height=0, width=50).pack()
        self.updateFileList()

    def updateFileList(self):
        # Clear Tree
        self._files.delete(*self._files.get_children())
        # Repopulate Tree
        if (self.Glacier.inventory != None):
            for f in self.Glacier.inventory.files:
                tags = ()
                if (f.deleted): tags=("deleted",)
                elif (f.isNew): tags=("new",)
                self._files.insert("","end",values=[f.desc,f.size,f.date], tags=tags)
            self._files.tag_configure("deleted", background="red")
            self._files.tag_configure("new", background="green")
    

    def listVaults(self):
        ret = self.Glacier.glacier.list_vaults()
        if ("VaultList" in ret):
            for i in ret["VaultList"]:
                print(i["VaultName"] + ": " + str(i["SizeInBytes"]) + " bytes")

    def listFiles(self):
        request = False
        # Inventory is only created around 1 day after first file is upload
        if (self.Glacier.vault.last_inventory_date == None):
            request = messagebox.askyesno("No Inventory Found","Request Inventory from AWS Glacier?\nJob will take around 4-5 hours to complete.")
        else:
            d = dateutil.parser.parse( self.Glacier.vault.last_inventory_date )
            d.replace(tzinfo=None)
            days = (datetime.datetime.utcnow() - d.replace(tzinfo=None)).days
            hours = (datetime.datetime.utcnow() - d.replace(tzinfo=None)).seconds/3600.0
            hours = floor(hours*100)/100;
            # Amazon Glacier prepares an inventory for each vault periodically, every 24 hours.
            # When you initiate a job for a vault inventory, Amazon Glacier returns the last
            # inventory for the vault. The inventory data you get might be up to a day or
            # two days old.
            #
            # - So, we only request a new list if our current list is more than 2 days older
            # TODO: Here we need to check if we already have a inventory_retrieval job
            if (days >= 2):
                request = messagebox.askyesno("Inventory is " + str(days) + " days old","Request Inventory from AWS Glacier?\nJob will take around 4-5 hours to complete.")
            else:
                request = messagebox.askyesno("Inventory is " + str(hours) + " hours old","Request Inventory from AWS Glacier?\nJob will take around 4-5 hours to complete.")
                
        if (request):
            self.Glacier.initListFiles()
            #TODO: Add Message/Feedback
        else:
            # Use old data
            #TODO: Here, update self.inventory with archives information
            # Havent find a way to get old inventory data yet.. so will keep it locally
            print(self.Glacier.vault.number_of_archives)
            print(self.Glacier.vault.size_in_bytes)
    
    def updateTick(self):
        print("tum tum")
Exemple #5
0
import matplotlib.pyplot as plt
import numpy as np

from glacier import Glacier

if __name__ == '__main__':
    ela_elevations = np.arange(4000, 5100, 100)
    ela_changes = np.arange(100, 510, 100)
    slopes = np.arange(0.05, 0.30, 0.05)

    glacier = Glacier(max_bed_height=5500)

    fig, ((ax1, ax2), (ax3, ax4), (ax5, ax6)) = plt.subplots(nrows=3,
                                                             ncols=2,
                                                             figsize=(14, 10))

    # Length change with varying ELA
    for slope in slopes:
        glacier.slope = slope
        length_change = [
            glacier.linear_equilibrium_length(elevation)
            for elevation in ela_elevations
        ]
        ax1.plot(ela_elevations, length_change, label=slope.round(2))
    ax1.set_title('Length change with varying ELA')
    ax1.legend(title='Slope')

    # Change of length over change of ELA
    for slope in slopes:
        lengths = [
            glacier.length_change(ela_change, slope)
Exemple #6
0
parser = argparse.ArgumentParser()
parser.add_argument(
    '--blockpull',
    help=
    'Perform a blockpull prior to uploading, so that the resulting disk image is independent of prior snapshots.',
    action='store_true')
parser.add_argument('--connection',
                    help='Specify qemu:///system or qemu:///session',
                    action='store')
args = parser.parse_args()

from glacier import Glacier

if __name__ == '__main__':
    glacier = Glacier(access_key_id=ACCESS_KEY_ID,
                      secret_access_key=SECRET_ACCESS_KEY,
                      region_name=REGION_NAME)

    try:
        logging.debug("Connecting to libvirt")
        virsh = libvirt.open(args.connection)

        vault = glacier.create_vault()
        for domain in virsh.listAllDomains(
                flags=libvirt.VIR_CONNECT_LIST_DOMAINS_ACTIVE):
            logging.debug("Parsing XML for: %s" % domain.name())
            domXML = domain.XMLDesc()
            logging.debug(domXML)

            tree = ElementTree.fromstring(domXML)
            disks = tree.findall('./devices/disk[@type="file"]/source/[@file]')
# t_0: 0 to 90, change ELA every 10 years
# ELA = 2900, 3100, 2800, 2700, 3000, 2800, 3400, 3300, 3200, 3500
# Get to steady state length for ELA at 3500
# - How long is the glacier (length)
# - How long does it take to get there (time)

import math
import numpy as np
import matplotlib.pyplot as plt

from glacier import Glacier

if __name__ == '__main__':
    initial_length = 22000
    glacier = Glacier(max_bed_height=3900, length=initial_length, slope=0.1)
    elas = [2900, 3100, 2800, 2700, 3000, 2800, 3400, 3300, 3200, 3500]
    time = np.arange(0, 501, step=1)
    lengths = []
    ela_index = 0
    time_delta = 1

    e_folding = 1 / math.e
    e_year = None
    e_length = None

    for year in time:
        lengths.append(glacier.length_over_time(time_delta, elas[ela_index]))
        glacier.length = lengths[-1]

        if 1 < year < 99 and (year % 10 == 9):
import matplotlib.pyplot as plt
import numpy as np

from glacier import Glacier

if __name__ == '__main__':
    resolution = 100
    glacier_length = 100000

    x = np.arange(start=0, stop=glacier_length + 1, step=resolution)

    glacier = Glacier(length=glacier_length)
    y = [glacier.surface_height(value) for value in x]

    glacier.isostatic = True
    y_isostatic = [glacier.surface_height(value) for value in x]
    y_isostatic_b = [glacier.bed_depth(value) for value in y_isostatic]

    plt.plot(x, y, linestyle='solid')
    plt.plot(x,
             y_isostatic,
             linestyle='dashed',
             label='isostatic',
             color='orange')
    plt.plot(x, y_isostatic_b, linestyle='dashed', color='orange')
    plt.legend()
    plt.xlabel('Length of Glacier')
    plt.ylabel('Thickness of the Glacier')
    plt.show()
Exemple #9
0
    'West': {
        'bed_height': 1127,
        'mean_ice_thickness': 2101,
        'max_surface': 3041,
        'min_surface': 0,
        'length_of_segment': 380000,
    },
}


def calc_slope(min_surface, max_surface, length):
    return (max_surface - min_surface) / length


if __name__ == '__main__':
    glacier = Glacier()

    measured_length = []
    linear_equilibrium_length = []

    max_surfaces = []
    ela = []
    critical_ela = []

    measured_thickness = []
    mean_thickness = []
    static_thickness = []

    for basin, data in BASINS.items():
        glacier.max_bed_height = data['bed_height']
        glacier.length = data['length_of_segment']