Exemplo n.º 1
0
def test_all_widgets_small_values(max_value):
    widgets = [
        progressbar.Timer(),
        progressbar.ETA(),
        progressbar.AdaptiveETA(),
        progressbar.AbsoluteETA(),
        progressbar.DataSize(),
        progressbar.FileTransferSpeed(),
        progressbar.AdaptiveTransferSpeed(),
        progressbar.AnimatedMarker(),
        progressbar.Counter(),
        progressbar.Percentage(),
        progressbar.FormatLabel('%(value)d'),
        progressbar.SimpleProgress(),
        progressbar.Bar(),
        progressbar.ReverseBar(),
        progressbar.BouncingBar(),
        progressbar.CurrentTime(),
        progressbar.CurrentTime(microseconds=False),
        progressbar.CurrentTime(microseconds=True),
    ]
    p = progressbar.ProgressBar(widgets=widgets, max_value=max_value)
    for i in range(10):
        time.sleep(1)
        p.update(i + 1)
    p.finish()
Exemplo n.º 2
0
def test_all_widgets_large_values(max_value):
    widgets = [
        progressbar.Timer(),
        progressbar.ETA(),
        progressbar.AdaptiveETA(),
        progressbar.AbsoluteETA(),
        progressbar.DataSize(),
        progressbar.FileTransferSpeed(),
        progressbar.AdaptiveTransferSpeed(),
        progressbar.AnimatedMarker(),
        progressbar.Counter(),
        progressbar.Percentage(),
        progressbar.FormatLabel('%(value)d/%(max_value)d'),
        progressbar.SimpleProgress(),
        progressbar.Bar(fill=lambda progress, data, width: '#'),
        progressbar.ReverseBar(),
        progressbar.BouncingBar(),
        progressbar.FormatCustomText('Custom %(text)s', dict(text='text')),
    ]
    p = progressbar.ProgressBar(widgets=widgets, max_value=max_value)
    p.update()
    time.sleep(1)
    p.update()

    for i in range(0, 10**6, 10**4):
        time.sleep(1)
        p.update(i)
Exemplo n.º 3
0
def test_all_widgets_max_width(max_width, term_width):
    widgets = [
        progressbar.Timer(max_width=max_width),
        progressbar.ETA(max_width=max_width),
        progressbar.AdaptiveETA(max_width=max_width),
        progressbar.AbsoluteETA(max_width=max_width),
        progressbar.DataSize(max_width=max_width),
        progressbar.FileTransferSpeed(max_width=max_width),
        progressbar.AdaptiveTransferSpeed(max_width=max_width),
        progressbar.AnimatedMarker(max_width=max_width),
        progressbar.Counter(max_width=max_width),
        progressbar.Percentage(max_width=max_width),
        progressbar.FormatLabel('%(value)d', max_width=max_width),
        progressbar.SimpleProgress(max_width=max_width),
        progressbar.Bar(max_width=max_width),
        progressbar.ReverseBar(max_width=max_width),
        progressbar.BouncingBar(max_width=max_width),
        progressbar.FormatCustomText('Custom %(text)s',
                                     dict(text='text'),
                                     max_width=max_width),
        progressbar.DynamicMessage('custom', max_width=max_width),
        progressbar.CurrentTime(max_width=max_width),
    ]
    p = progressbar.ProgressBar(widgets=widgets, term_width=term_width)
    p.update(0)
    p.update()
    for widget in p._format_widgets():
        if max_width and max_width < term_width:
            assert widget == ''
        else:
            assert widget != ''
Exemplo n.º 4
0
def loop():
    last_clean = time.time()
    sql_error = False
    db = MySQLdb.connect(**config.mysql)
    db.commit()
    db.close()
    last_loop = 0
    loop_interval = 300
    try:
        while True:
            try:
                last_loop = time.time()
                print("\n\n\nNEW LOOP")
                get_new_torrent()
                db = MySQLdb.connect(**config.mysql)
                update_torrent_file(db)
                notfound = fetch_torrent(db)
                feed_torcache(db)
                scrape(db)
                db.commit()
                db.close()
                widgets = [
                    progressbar.Bar('>'), ' ',
                    progressbar.ETA(), ' ',
                    progressbar.ReverseBar('<')
                ]
                now = time.time()
                maxval = int(max(0, loop_interval - (now - last_loop)))
                if maxval > 0:
                    print("Now spleeping until the next loop")
                    pbar = progressbar.ProgressBar(widgets=widgets,
                                                   maxval=maxval).start()
                    for i in range(0, maxval):
                        time.sleep(1)
                        pbar.update(i + 1)
                    pbar.finish()
                db = MySQLdb.connect(**config.mysql)
                clean_files(db)
                compact_torrent(db)
                if time.time() - last_clean > 60 * 15:
                    clean(db)
                    last_clean = time.time()
                db.commit()
                sql_error = False
            except socket.timeout:
                if sql_error:
                    raise
                time.sleep(10)
                sql_error = True
            finally:
                try:
                    db.close()
                except:
                    pass
    finally:
        print("exiting")
Exemplo n.º 5
0
def double_bar_example():
    widgets = [
        progressbar.Bar('>'), ' ',
        progressbar.ETA(), ' ',
        progressbar.ReverseBar('<'),
    ]
    bar = progressbar.ProgressBar(widgets=widgets, max_value=1000).start()
    for i in range(100):
        # do something
        bar.update(10 * i + 1)
        time.sleep(0.01)
    bar.finish()
Exemplo n.º 6
0
 def start_progress(self, maxval):
     if not self._progress_bar_enabled:
         return
     self.counter = 0
     widgets = [
         progressbar.Bar('>'), ' ',
         progressbar.SimpleProgress(), ' - ',
         progressbar.Percentage(), ' - ',
         progressbar.ETA(), ' / Rate: ',
         progressbar.FileTransferSpeed(unit=' items'), ' ',
         progressbar.ReverseBar('<')
     ]
     self.pbar = progressbar.ProgressBar(widgets=widgets,
                                         maxval=maxval).start()
Exemplo n.º 7
0
def progress_bar(name, max_am, reverse=False):
    widgets = list()
    widgets.append('%s: ' % (name))
    widgets.append(progressbar.Percentage())
    widgets.append(' ')
    if reverse:
        widgets.append(progressbar.ReverseBar())
    else:
        widgets.append(progressbar.Bar())
    widgets.append(' ')
    widgets.append(progressbar.ETA())
    p_bar = progressbar.ProgressBar(maxval=max_am, widgets=widgets)
    p_bar.start()
    try:
        yield p_bar
    finally:
        p_bar.finish()
Exemplo n.º 8
0
def example3():
    """
    Display progress bar using tqdm.

    >>> example3()
    True
    """
    widgets = [
        progressbar.Bar(">"), " ",
        progressbar.ETA(), " ",
        progressbar.ReverseBar("<")
    ]
    pbar = progressbar.ProgressBar(widgets=widgets, max_value=1000).start()
    for i in range(100):
        sleep(0.01)
        pbar.update(10 * i + 1)
    pbar.finish()
    return True
Exemplo n.º 9
0
def test_all_widgets_large_values():
    widgets = [
        progressbar.Timer(),
        progressbar.ETA(),
        progressbar.AdaptiveETA(),
        progressbar.FileTransferSpeed(),
        progressbar.AdaptiveTransferSpeed(),
        progressbar.AnimatedMarker(),
        progressbar.Counter(),
        progressbar.Percentage(),
        progressbar.FormatLabel('%(value)d/%(max_value)d'),
        progressbar.SimpleProgress(),
        progressbar.Bar(),
        progressbar.ReverseBar(),
        progressbar.BouncingBar(),
    ]
    p = progressbar.ProgressBar(widgets=widgets, max_value=10**6)
    for i in range(0, 10**6, 10**4):
        time.sleep(0.001)
        p.update(i + 1)
    p.finish()
Exemplo n.º 10
0
from prettytable import PrettyTable
from sklearn import manifold

if os.name == "posix":  # Only on linux
    try:
        import argcomplete
    except:
        print("argcomplete not detected, if you want to use autocompletetion")
        print("install argcomplete module.")
        print("See https://github.com/kislyuk/argcomplete for more info")
        pass
# ==============================================================================
#                     GLOBAL VARIABLES
# ==============================================================================
WIDGETS = [pg.Bar('>'), ' ', pg.ETA(), ' ', pg.ReverseBar('<')]
COORDS = []
COLOR_LIST = [
    "red", "blue", "lime", "yellow", "darkorchid", "deepskyblue", "orange",
    "brown", "gray", "black", "darkgreen", "navy"
]
DPI = 600

# ==============================================================================
#                          CLASS
# ==============================================================================


class Cluster:
    """
    DESCRIPTION
Exemplo n.º 11
0
timetaken = nicetimediff(endtime - starttime)

notify(computer, withsound,
       "Dear user, I'm done with the alignment. I did it in %s." % timetaken)
print("Now updating the database...")

backupfile(imgdb, dbbudir, "alignimages")

if "geomapangle" not in db.getFieldNames(imgdb):
    db.addFields(imgdb,
                 ['geomapangle:float', 'geomaprms:float', 'geomapscale:float'])

widgets = [
    progressbar.Bar('>'), ' ',
    progressbar.ETA(), ' ',
    progressbar.ReverseBar('<')
]
pbar = progressbar.ProgressBar(widgets=widgets, maxval=len(images)).start()
for (retdict, image) in zip(retdicts, images):
    #print image["geomapscale"]
    if not retdict == None:
        db.update(
            imgdb, ['recno'], [image['recno']], {
                'geomapangle': retdict["geomapangle"],
                'geomaprms': retdict["geomaprms"],
                'geomapscale': retdict["geomapscale"]
            })
    pbar.update(i)
pbar.finish()

db.pack(imgdb)
Exemplo n.º 12
0
def makejpgtgz(pngdirpath, tgzdir, maxfilenamelength = 5, askquestions=True):
	"""
	Give me a path to a directory containing png files
	I will transfrom them into jpgs, and then make a tgz archive with these jpgs.
	pngdirpath : the path of the directory that contains the pngs
	tgzdir : the dir in which you want me to put the archive
	maxfilenamelength : used to discriminate between 0001.png and stuff like Mer1_434333_20049874T...
	
	typical use is :
	if makejpgarchives:
		makejpgtgz(pngdir, workdir, askquestions = askquestions)
	"""
	import os
	import glob
	import progressbar
	
	
	pngfiles = sorted(glob.glob(os.path.join(pngdirpath, "*.png")))
	# We get rid of the long filenames (i.e. we only want to process the ordered links like 0001.png etc, not the actual files) :	
	#print pngfiles
	pngfiles = [os.path.basename(pngfile) for pngfile in pngfiles if len(os.path.basename(pngfile)) <= (maxfilenamelength + 4)]
	
	print "I will now make a jpg archive of %i pngs." % len(pngfiles)
	#proquest(askquestions)
	
	#origdir = os.getcwd()
	#os.chdir(pngdirpath)
	
	# We convert them to jpgs :
	
	print "PNG -> JPG conversion ..."
	widgets = [progressbar.Bar('>'), ' ', progressbar.ETA(), ' ', progressbar.ReverseBar('<')]
        pbar = progressbar.ProgressBar(widgets=widgets, maxval=len(pngfiles)).start()
	for i, pngfile in enumerate(pngfiles):
		cmd = "mogrify -format jpg -quality 100%% %s" % os.path.join(pngdirpath, pngfile)
		pbar.update(i)
		#print cmd
		#print pngfile
		os.system(cmd)
	pbar.finish()
	
	print "Moving files ..."
	origdir = os.getcwd()
	os.chdir(pngdirpath)
	os.mkdir("jpg")
	os.system("mv *.jpg jpg/.")
	
	# We rename this correctly
	if pngdirpath[-1] == "/":
		pngdirpath = pngdirpath[:-1]
	jpgarchivename = os.path.split(pngdirpath)[1] + "_jpg"
	os.system("mv jpg ./%s" % jpgarchivename)
	
	print "Builing archive ..."
	os.system("tar zcvf %s.tgz %s" % (jpgarchivename, jpgarchivename))
	
	print "Moving archive into place ..."
	
	
	os.system("mv %s.tgz %s.tgz" % (jpgarchivename, os.path.join(tgzdir, jpgarchivename)))
	print "Ok, done; the jpg archive is here :"
	print os.path.join(tgzdir, jpgarchivename + ".tgz")
	
	os.chdir(origdir)
Exemplo n.º 13
0
def animation():
 global bar
 right=False
 left=True
 count=0
 bar = progressbar.ProgressBar(maxval=100, widgets=['Capturing packets(Press CNTRL^C to stop):', progressbar.Bar(left=Fore.RED+'[', marker=Fore.GREEN+'~', right=Fore.RED+']'+Fore.RESET),progressbar.ReverseBar(left=Fore.RED+'[', marker=Fore.GREEN+'~', right=Fore.RED+']'+Fore.RESET),]).start()
 while True:
  if left == True:
   count+=1
   bar.update(count)
   time.sleep(0.03)
   if count == 100:
    left=False
    right=True
  if right==True:
   count=0
   left=True
   right=False
Exemplo n.º 14
0
    def create_progress_bar(self, event):
        """
        Create a :py:class:`.ProgressBar` for the `event` if none exists yet.
        Otherwise return the bar.

        Parameters
        ----------
        event : str

        Returns
        -------
        bool, ProgressBar.
            If the progressbar is newly created, the progressbar object.
        """
        if event not in self.pbars:

            def get_shared_widgets(event_name):
                event_name = event_name.ljust(event_length)[:event_length]
                return [event_name, ': ', progressbar.Percentage(), ' ']

            widgets = get_shared_widgets(event) + [progressbar.Bar(marker=progressbar.RotatingMarker()), ' ', progressbar.ETA()]

            if event == MyEventSystem.EVENT_TOTAL_PROGRESS:
                widgets = get_shared_widgets(EVENT_OVERALL_PROGRESS) + [progressbar.Bar('>'), progressbar.ReverseBar('<'), ' ', progressbar.ETA()]

            pbar = progressbar.ProgressBar(fd=TerminalWriter(0, idx=self.get_progressbar_idx()), widgets=widgets, maxval=1.0).start()
            self.pbars[event] = pbar

            return True, pbar

        return False, self.pbars[event]
Exemplo n.º 15
0
	if len(sys.argv)>1:
		init = float(data[0].split(":")[0])
		day =  tm.time()-init
		for each in sys.argv:
			if each.isdigit():
				day= 60*60*24*int(each)
				break
		print "start time", tm.ctime(init)
		print "Will process ",len (data), "data points"
	else:
		day = 60*60*24
	i = 0
	x=[]
	y=[]
	l=len(data)
	widgets = [progressbar.Bar('>'), ' ', progressbar.ETA(), ' ', progressbar.ReverseBar('<')]
	pbar =progressbar.ProgressBar(widgets=widgets)
	for each in pbar(data):
	    i+=1
	    #if round(float(i)/l*100,3)%1==0 and day <> 60*60*24:
		#print "loading-"+str(int(float(i)/l*100))+"%"+str(int(float(i)/l*40)*"-"),
		#print(chr(27)+"["+str(14+int(float(i)/l*40))+"D"),

	    try: 
	     #i+=1
	     #print i,
	     sys.stdout.flush()
	     tmp =each.split(":")
	     #temp = (tm.time()-day)-((tm.time()-day)%(3600))	
	     for entry in tmp: 
		if entry==np.nan or entry == "nan" or float(tmp[4])>100 or float(tmp[4])<0 :