Beispiel #1
0
 def test_missing(self):
     # If the command does not exist, an OSError (No such file or
     # directory) is raised.
     bad = command('this command does not exist')
     with self.assertRaises(OSError) as info:
         bad()
     self.assertEqual(2, info.exception.errno)
 def test_missing(self):
     # If the command does not exist, an OSError (No such file or
     # directory) is raised.
     bad = command("this command does not exist")
     with self.assertRaises(OSError) as info:
         bad()
     self.assertEqual(2, info.exception.errno)
 def test_quoting(self):
     # There is no need to quote special shell characters in commands.
     ls = command("/bin/ls")
     ls("--help", ">")
 def test_baked_in_arguments(self):
     # Arguments can be passed when creating the command as well as when
     # executing it.
     ll = command("/bin/ls", "-al")
     self.assertIn("rw", ll())  # Assumes a file is r/w in the pwd.
     self.assertIn("Usage:", ll("--help"))
 def test_error(self):
     # If the command returns a non-zero exit code, an exception is raised.
     bad = command("/bin/ls", "--not a valid switch")
     self.assertRaises(ProcessError, bad)
 def test_arguments(self):
     # Arguments can be passed to commands.
     ls = command("/bin/ls")
     self.assertIn("Usage:", ls("--help"))
 def test_simple_command(self):
     # Creating a simple command (ls) works and running the command
     # produces a string.
     ls = command("/bin/ls")
     self.assertIsInstance(ls(), str)
Beispiel #8
0
import json
import logging
import os
import tempfile

from charmhelpers import make_charm_config_file

from helpers import (
    command,
    juju,
    wait_for_unit,
)

rsync = command('rsync', '-a',
                '--exclude', '.git',
                '--exclude', '.bzr',
                '--exclude', '/tests')


def setup_repository(name, source, series='trusty'):
    """Create a temporary Juju repository to use for charm deployment.

    Copy the charm files in source in the repository section corresponding to
    the given series, using the provided charm name and excluding the
    virtualenv and Git directories.

    Return the repository path.
    """
    source = os.path.abspath(source) + os.path.sep
    repo = tempfile.mkdtemp()
    destination = os.path.join(repo, series, name)
Beispiel #9
0
 def test_quoting(self):
     # There is no need to quote special shell characters in commands.
     ls = command('/bin/ls')
     ls('--help', '>')
Beispiel #10
0
 def test_baked_in_arguments(self):
     # Arguments can be passed when creating the command as well as when
     # executing it.
     ll = command('/bin/ls', '-al')
     self.assertIn('rw', ll())  # Assumes a file is r/w in the pwd.
     self.assertIn('Usage:', ll('--help'))
Beispiel #11
0
 def test_error(self):
     # If the command returns a non-zero exit code, an exception is raised.
     bad = command('/bin/ls', '--not a valid switch')
     self.assertRaises(ProcessError, bad)
Beispiel #12
0
 def test_arguments(self):
     # Arguments can be passed to commands.
     ls = command('/bin/ls')
     self.assertIn('Usage:', ls('--help'))
Beispiel #13
0
 def test_simple_command(self):
     # Creating a simple command (ls) works and running the command
     # produces a string.
     ls = command('/bin/ls')
     self.assertIsInstance(ls(), str)
Beispiel #14
0
def git_log_calendar(past=None):

	# help in finding starting date
	os.system('git log --reverse --format="%ci" > first.txt')
	with open('first.txt','r') as f:
		data = f.read()
	f.close()
	first = re.match(r'(\d+)\-(\d+)\-(\d+)',data).groups()
	os.system('rm first.txt')

	today = date.today()
	# lastyear, just 365 days in past
	ly = today - timedelta(days=365)

	# project starting date
	startdate = date(int(first[0]),int(first[1]),int(first[2]))

	# to show calendar or not
	show = True

	if past is not None:
		past = int(past)
		# same as showing generally
		if(past == 1):
			pass
		else:
			# if history is available that back
			if((today-startdate).days > (past-1)*365):
				today = today - timedelta(days=365*(past-1))
				ly = today - timedelta(days=365)
			else:
				# now don't show calendar
				show = False
				# warn : wrong user input
				print "This project does't have that long commit history"

	if(show):
		# today's date variables
		tyear = today.year
		tmonth = today.month
		tday = today.day

		# represent each day of calendar, intially starting day of calendar
		cursor = ly + timedelta(days=1)
		
		# total day count
		count = 0

		# using it like 2D matrix for 53 week-data [52 week + 1 day]
		weekly = {}

		# weekday on ending date of calendar, used to leave 6 blank spaces
		wd = weekday(today.year,today.month,today.day)

		# labels on leftside of calendar for weekdays
		weekly[0] = days

		# month's label
		monthLabel = "    "
		mon = cursor.month
		monthLabel = render(monthLabel + months[mon-1])
		gap1 = 2

		# to keep first month in some extra left
		flag=True

		# organising last 365 day's commit logs in 53 lists[of 7 length]
		while(cursor <= today):
			# mantaining spaces in month label, not so good
			if(cursor.month != mon):
				gap2 = len(weekly)

				# it temporary fixes alignment, if a month starts on sunday, will check
				if(weekday(cursor.year,cursor.month,cursor.day)==0):
					gap2 = gap2+1

				# to keep first month in some extra left
				if(flag):
					monthLabel = monthLabel + " "
					flag = False

				mon = cursor.month				
				monthLabel = monthLabel + render(" "*(2*(gap2-gap1)-3) + months[cursor.month-1]) 
				gap1 = gap2
		
			# marking as ' '(blank) for days of first week that are not counted in a year
			if(count==0):
				weekly[1] = []
				for j in range(0,wd):
					weekly[1].append(blank)

			if(cursor.month < 10):
				nm = '0%s'%(str(cursor.month))
			else:
				nm = cursor.month

			if(cursor.day < 10):
				nd = '0%s'%(str(cursor.day))
			else:
				nd = cursor.day
		
			cmt = int(command('git log --format=format:"%ci" ' + ' | grep "%d-%s-%s" | wc -l'%(cursor.year,nm,nd)))
		
			# filling in first week if 7 days are not complete 
			if(len(weekly[1])<=6):
				weekly[1].append(cmt)

			# mantaining calendar with first and last week
			if(count >= (7-wd)):
				# new list for new week
				if((count+wd)%7 == 0):
					weekly[((count+wd)/7)+1] = []
				weekly[((count+wd)/7)+1].append(cmt)
		
			count = count + 1
			cursor = cursor + timedelta(days=1)


		# suffer-sorting :D
		fake = []
		for i in range(1,len(weekly)):
			for j in range(len(weekly[i])):
				p = weekly[i][j]
				if(p!=0):
					fake.append(p)

		fake = sorted(fake)
		lf = len(fake)

		# quartile values
		Q1 = fake[lf/4]
		Q2 = fake[lf/2]
		Q3 = fake[3*lf/4]
	
		# as it is not defined already
		for i in range(wd+1,7):
			weekly[53].append(blank)

		# month label on top
		print monthLabel

		# generating the calendar
		for k in range(0,7):
			x = ''
			for l in range(0,54):
				x = '%s %s'%(x,(render(rank(Q1,Q2,Q3,weekly[l][k]))))
			print x
	
		# less-more indicator color palatte
		palatte = render('     Less ')
		for x in range(5):
			palatte = palatte + render(x) +  ' '
		palatte = palatte + render(' More')
		print palatte