Beispiel #1
0
def printConsole(line):
    if line == None:
        return
    line = line.strip().replace("//", "/")
    CONSOLE.writeLine(line)

    print(line)
Beispiel #2
0
def untar_callback():
    global member_count
    global member_total

    member_count = member_count + 1
    percent = int((float(member_count) / member_total) * 100)
    CONSOLE.setProgress(percent)
Beispiel #3
0
def untar_callback():
	global member_count
	global member_total

	member_count = member_count+1
	percent=int((float(member_count)/member_total)*100)	
	CONSOLE.setProgress(percent)
Beispiel #4
0
def wget( url, name,console=None):
		"""Downloads from url specified to the filename/path specified and displays progress"""
		print("Fetching "+name+" from "+url+"\n\n")
		#console update callback
		def progresshook(numblocks, blocksize, filesize, url=None):
			
			try:
				percent = min((numblocks * blocksize * 100) / filesize, 100)
			except:
				percent = 100
			if numblocks != 0:
				
				
				MB_CONST = 1000000 # 1 MB is 1 million bytes
				out_str =  "Progress:" + str(percent) + '%' + " of " + str(filesize / MB_CONST) + "MB\r"
				
				if (console==None):

					sys.stdout.write("\r"+out_str)
				else:
					if (filesize>0):
						console.setProgress(percent)
					else:
						console.setIndeterminate(True)
						bytecount=numblocks*blocksize;
						progstr="Downloaded: "+str(bytecount/MB_CONST)+" MB ("+str(bytecount)+" bytes) of ~200MB"
						console.setProgressString(progstr)
		CONSOLE.setProgress(0)
		urlStream = urllib.urlretrieve(url, name, progresshook)
		CONSOLE.setIndeterminate(False)
		CONSOLE.setProgressString(None)
		CONSOLE.hideProgress()
Beispiel #5
0
def cygwin_untar(windows_path,
                 filename,
                 directory="/home/BIRCH",
                 noroot=False):
    global member_total
    global member_count

    tarball = tarfile.open(windows_path)

    print_console("Calculating tar info, this may take some time")
    info = tarball.getmembers()
    tarball.close()

    member_total = len(info)
    member_count = 0
    print_console("There are " + str(member_total) + " members in " + filename)
    CONSOLE.setProgress(0)
    print_console("Beginning the extraction process")

    cmd = "cd " + directory + " && tar -xvpf " + filename

    cygwin_exec(cmd, callbackfunc=untar_callback, verbosity=False)

    print_console("Extracted " + str(member_count) + " members from archive.")
    if (noroot == True):
        if (info[0].name.find("pax_global_header") >= 0):
            print_console("Trimming global header")
            info.pop(0)
        rootpath = info.pop(0)
        print_console("Using " + rootpath.name + " as root tar dir.")

        contents = os.listdir(rootpath.name)
        for each in contents:
            print_console("Moving " + each + " to rebased root path.")
            shutil.move(rootpath.name + "/" + each, os.getcwd() + "/" + each)

        shutil.rmtree(rootpath.name)

    member_count = 0
    member_total = 0

    CONSOLE.setProgress(0)
    CONSOLE.hideProgress()
Beispiel #6
0
def cygwin_untar(windows_path,filename, directory ="/home/BIRCH",noroot=False):
	global member_total
	global member_count

	tarball = tarfile.open(windows_path)

	print_console("Calculating tar info, this may take some time")
	info=tarball.getmembers()
	tarball.close()

	member_total=len(info)
	member_count=0
	print_console("There are "+str(member_total)+ " members in "+filename)
	CONSOLE.setProgress(0)
	print_console("Beginning the extraction process")
			
	cmd = "cd "+directory+" && tar -xvpf "+filename
	
	cygwin_exec(cmd,callbackfunc=untar_callback,verbosity=False)

	print_console("Extracted "+str(member_count)+ " members from archive.")
	if (noroot==True):
		if (info[0].name.find("pax_global_header")>=0):
			print_console("Trimming global header")
			info.pop(0)
		rootpath=info.pop(0)
		print_console("Using "+rootpath.name+" as root tar dir.")

		contents=os.listdir(rootpath.name)
		for each in contents:
			print_console("Moving "+each+" to rebased root path.")
			shutil.move(rootpath.name+"/"+each,os.getcwd()+"/"+each)

		shutil.rmtree(rootpath.name)

	member_count=0
	member_total=0

	CONSOLE.setProgress(0)
	CONSOLE.hideProgress()
Beispiel #7
0
def shutdown():
	info("Shutting down")
	CONSOLE.shutdown()
Beispiel #8
0

def untar(file, path=".",noroot=False,exclude=list()  ):
		"""Extracts the tarfile given by file to current working directory by default, or path"""

        cwd = os.getcwd()
        if( os.path.isdir(path))
            os.chdir(path)

		tarball = tarfile.open(file)
		info("Calculating tar info, this may take some time")
		tarInfo=tarball.getmembers()

		total=len(tarInfo)
		count=0
		CONSOLE.setProgress(0)
		info("Beginning the extraction process")

        if (not native):
            for each in tarInfo:
                if (not each.name in exclude):
                    count=count+1
                    percent=int((float(count)/total)*100)	
                    item=list()
                    item.append(each)
                    tarball.extractall(members=item)
                    CONSOLE.setProgress(percent)
                else:
                    info("Excluded member "+each.name)

		if (noroot==True):