Exemple #1
0
 def create_gitignore(self):
     """ Creating the gitignore """
     if not os.path.exists('%s/.gitignore' % self.destination):
         os.system('cp %s/.gitignore %s/.gitignore' % (PROJECT_ROOTDIR, self.destination))
         termprint("INFO", "Created gitignore file since it wasn't found")
         return True
     return False
Exemple #2
0
 def create_setup(self, django=False):
     """ 
     Create the setup.py file 
     Copy the setup.py file
     Create another subdirectory with the same name as the package
     Creates files:
      - /absolute_path_destination/packagename/packagename/__init__.py
      - /absolute_path_destination/packagename/packagename/packagename.py
      - /absolute_path_destination/packagename/setup.py
     """
     # original setup file to copy. If django = True, use setup_django.py
     original_file = "setup.py"
     if django:
         original_file = "setup_django.py"
     orig = open("%s/%s" % (PROJECT_ROOTDIR, original_file), "r").read()
     oo = orig.replace('APP-NAME', self.get_project_name())
     # writes to this file (destination is always setup.py
     ooo = open('%s/setup.py' % self.destination, 'w')
     ooo.write(oo)
     ooo.close()
     if not os.path.exists('%s/%s.py' % (self.destination, self.get_project_name())):
         os.system('touch %s/%s.py' % (self.destination, self.get_project_name()))
     if os.path.exists('%s/setup.py' % self.destination):
         termprint("INFO", '... Copied setup base\n')
         return True
     else:
         termprint("ERROR", '... FAILED to copy setup to %s\n' % self.destination)
         return False
 def test_create_setup(self):
   """ Create the setup file """
   termprint("INFO", "\n\n.... Test the readme, enter another unique package name")
   cl = PythonPackage()
   self.assertTrue(cl.create_base_directories())
   # can now create the setup (skipping readme for test)
   self.assertTrue(cl.create_setup())
   self.assertTrue(os.path.exists('%s/setup.py' % cl.destination))
   termprint("", "Cleaning files")
   os.system('rm -rf %s' % cl.destination)
   self.break_row()
 def test_askuser(self):
   """
   Test ask user prompt
   """
   termprint("INFO", '\n.... Testing test_askuser(): Enter a random package name')
   cl = PythonPackage()
   # dpending what you entered    
   self.assertEquals(cl.destination.split('/')[-1], cl.user_response)
   termprint("", "Cleaning files")
   os.system('rm -rf %s' % cl.destination)
   self.break_row()
 def test_directory_exists(self):
   """ 
   Make sure we catch if the directory exists or not
   """
   termprint("INFO", "\n\n.... Testing for duplicate catch. \n\
     Enter another unique random package name (Not the same as previous)")
   cl = PythonPackage()    # create the base destination directory
   self.assertTrue(cl.create_base_directories())
   # now retry - should return false
   self.assertFalse(cl.create_base_directories())
   termprint("", "Cleaning files")
   os.system('rm -rf %s' % cl.destination)
   self.break_row()
Exemple #6
0
    def create_readme(self):
        """ Create the readme file """

        orig = open("%s/README_SAMPLE.rst" % PROJECT_ROOTDIR, "r").read()
        oo = orig.replace('PROJECT_NAME', self.get_project_name())
        ooo = open('%s/README.rst' % self.destination, 'w')
        ooo.write(oo)
        ooo.close()
        if os.path.exists('%s/README.rst' % self.destination):
            termprint("INFO", '... Copied readme base\n')
            return True
        else:
            termprint("ERROR", '... FAILED to copy read me to %s\n' % self.destination)
            return False
 def test_create_readme(self):
   """ 
   Create the readme file 
   """
   termprint("INFO", "\n\n.... Test the readme, enter another unique package name")
   cl = PythonPackage()
   self.assertTrue(cl.create_base_directories())
   # create the readme
   self.assertTrue(cl.create_readme())
   self.assertTrue(os.path.exists("%s/README.rst"%cl.destination))
   self.assertTrue(cl.user_response in open("%s/README.rst"%cl.destination, "r").read())
   termprint("", "Cleaning files")
   os.system('rm -rf %s' % cl.destination)
   self.break_row()
Exemple #8
0
 def set_destination(self, path):
     """ Check if relative or abs and set the path
     remove any trailing slashes. Remove any prefix slashes
     If there is an absolute path provided it will omit the settings
     CREATE_DIRECTORY value.
     """
     # if provided was an absolute path
     if self.has_trailing_slash(path):
         self.destination = path
     else:
         # should not copy to relative path cause no settins is set for project root
         if not cdir:
             termprint("ERROR", ERR_SET_DESTINATION)
             sys.exit(1)
         self.destination = "%s/%s" % (self.get_project_root(), path)
     # remove any trailing slashes for people who dont read    
     self.destination = self.remove_trailing_slash(self.destination)
Exemple #9
0
    def test_map_table(self):
        """ Test the db() methods. """
        # connect!
        session, metadata, connection = self.__connect()
        self.assertTrue(connection)
        
        # map the tables (autoloads meta data)
        user_profile_auto = map_table(metadata, DatabaseAutoload, "mainweb_userprofile")
        # map the other table (does not autoload, and passes a Table() instance instead of a name)
        user_profile = map_table(metadata, DatabaseNoAutoload, table_object, autoload=False, skip_table=True)

        # search for something (arguments: session, MappedClass, column_name, value)
        results_auto = db_filter(session, user_profile_auto, "user_id", '64')
        results = db_filter(session, user_profile, "user_id", '64')

        termprint("INFO", "Printing the results....\n")
        # show the results
        for i in results_auto:
            termprint("WARNING", "\t- %s" % i.id)

        for i in results:
            termprint("ERROR", "\t- %s" % i.id)

        # done, now close!
        db_disconnect(connection)
Exemple #10
0
 def intro(self):
     """ Intro questions to ask the user to get started and 
     sets the destination
     """
     # ask a user appropriately based on settings
     if not self.get_project_root():
         termprint("", INTRO_ABS_QUESTION)
         termprint("WARNING", "\t%s" % os.getcwd())
         termprint("INFO", INTRO_ABS_INFO)
         response = self.ask_user(INTRO_ABS_ENTER_DATA_MSG)
     else:
         # provide only package name (optional absolute)
         termprint("", INTRO_REL_QUESTION)
         termprint("INFO", "\t%s\n" % self.get_project_root())
         termprint("WARNING", INTRO_REL_WARNING)
         response = self.ask_user(INTRO_REL_ENTER_DATA_MSG)
     if response and len(str(response)) > 5:
         self.set_destination(response)
     return response
Exemple #11
0
 def __init__(self, message):
     s = termprint("ERROR", messages, return_text=True)
     Exception.__init__(self, s)
Exemple #12
0
 def create_base_directories(self):
     """ Create the base directory that was set to self.destination variable.
     If the directory exists, exit with an error, we are not overriding 
     and breaking anything today.
     Destination should be an absolute path that is set by self.set_destination, which 
     occurs after the intro()
     """
     termprint("INFO", "\n\t....Trying to create directory %s\n" % self.destination)
     if os.path.exists(self.destination):
         termprint("ERROR", ERR_DIRECTORY_EXISTS)
         termprint("WARNING", "\n\t%s" % self.destination)
         termprint("ERROR", "\n\nEXITING!!\n")
         return False
     else:
         os.system("mkdir %s" % self.destination)
         return True
     if os.path.exists(self.destination):
         termprint("INFO", "\nCreated Directory %s\n" % self.destination)
         return True
     else:
         termprint("ERROR", "\nFailed to create %s\n" % self.destination)
         return False
Exemple #13
0
 def break_row(self):
     """ Print a row separation for logs and stdout """
     termprint("", "\n")
     termprint("INFO", "-".join(["-" for x in range(0, 50)]))
     termprint("", "\n\n")
Exemple #14
0
 def __init__(self, msg, exit=False):
     termprint("ERROR", msg)
     if exit:
         sys.exit(1)
Exemple #15
0
import sys
from starpy import manager
from starpy.error import AMICommandFailure
from termprint import termprint
from unittest import TestCase, TestSuite, TextTestRunner
from twisted.internet import reactor
from nose.tools import ok_, eq_
import simplejson

sys.path.append('../')
sys.path.append('../pyamicmd')

try:
    import settings
except ImportError:
    termprint("ERROR", "No settings found")
    sys.exit(1)

class AssertionError:
    # simple assertion error output
    def __init__(self, msg, exit=False):
        termprint("ERROR", msg)
        if exit:
            sys.exit(1)

class TestAMIBase(TestCase):
    """ Base test class to check for settings
    and authentication information.
    """
    PBX = getattr(settings, "PBX")
    AMI_USER = getattr(settings, "AMI_USER")