Ejemplo n.º 1
0
def detach(device=" ", logger=False):
    """
    Eject the ramdisk
    Detach (on the mac) is a better solution than unmount and eject
    separately.. Besides unmounting the disk, it also stops any processes
    related to the mntPoint

    @author: Roy Nielsen
    """
    success = False
    if not logger:
        logger = CyLogger()
    else:
        logger = logger
    myRunWith = RunWith(logger)
    if not re.match("^\s*$", device):
        cmd = ["/usr/bin/hdiutil", "detach", device]
        myRunWith.setCommand(cmd)
        myRunWith.communicate()
        retval, reterr, retcode = myRunWith.getNlogReturns()
        if not reterr:
            success = True

        myRunWith.getNlogReturns()
    else:
        raise Exception("Cannot eject a device with an empty name..")
    return success
Ejemplo n.º 2
0
 def __init__(self):
     """
     Initialization Method...
     """
     self.logger = CyLogger()
     
     self.getLibc()
Ejemplo n.º 3
0
 def __init__(self, logger):
     """
     """
     if logger:
         self.logger = logger
     else:
         self.logger = CyLogger()
     self.module_version = '20160224.032043.009191'
     self.prefix = []
Ejemplo n.º 4
0
 def setUpClass(self):
     """
     """
     #####
     # Set up logging
     self.logger = CyLogger(debug_mode=True)
     self.logger.initializeLogs()
     self.rw = RunWith(self.logger)
     #####
     # Start timer in miliseconds
     self.test_start_time = datetime.now()
    def setUpClass(self):
        """
        Initializer
        """
        unittest.SkipTest("Tests need to be written...")
        # Start timer in miliseconds
        self.test_start_time = datetime.now()

        self.logger = CyLogger()
        self.logger.initializeLogs()

        self.libcPath = None  # initial initialization
Ejemplo n.º 6
0
    def setUpClass(self):
        """
        """
        #####
        # Set up logging
        self.logger = CyLogger(debug_mode=True)
        self.logger.initializeLogs()
        self.rw = RunWith(self.logger)

        self.enviro = Environment()
        self.ca = CheckApplicable(self.enviro, LOGGER)

        #####
        # Start timer in miliseconds
        self.testStartTime = datetime.now()
    def tearDownClass(self):
        """
        disconnect ramdisk
        """
        self.logger = CyLogger()
        #####
        # capture end time
        test_end_time = datetime.now()

        #####
        # Calculate and log how long it took...
        test_time = (test_end_time - self.test_start_time)

        self.logger.log(
            lp.INFO, self.__module__ + " took " + str(test_time) +
            " time to complete...")
    def setUpClass(self):
        """
        Initializer
        """
        unittest.SkipTest("Tests need to be written...")
        # Start timer in miliseconds
        self.test_start_time = datetime.now()

        self.logger = CyLogger()

        self.libcPath = None  # initial initialization

        #####
        # If we don't have a supported platform, skip this test.
        if not sys.platform.startswith("darwin") and \
           not sys.platform.startswith("linux"):
            raise unittest.SkipTest("This is not valid on this OS")
        raise unittest.SkipTest("Not a supported tests....")
    def setUpClass(self):
        """
        """
        self.libc = getLibc()
        self.subdirs = ["two", "three" "one/four"]
        self.logger = CyLogger()
        self.logger.log(lp.CRITICAL, "Logger initialized............................")

        """
        Set up a ramdisk and use that random location as a root to test the
        filesystem functionality of what is being tested.
        """
        #Calculate size of ramdisk to make for this unit test.
        size_in_mb = 1800
        ramdisk_size = size = size_in_mb
        self.mnt_pnt_requested = "testmntpnt"

        self.success = False
        self.mountPoint = ""
        self.ramdiskDev = False
        self.mnt_pnt_requested = False

        # get a ramdisk of appropriate size, with a secure random mountpoint
        self.my_ramdisk = RamDisk(str(ramdisk_size), self.mnt_pnt_requested, logger=self.logger)
        (self.success, self.mountPoint, self.ramdiskDev) = self.my_ramdisk.getData()
        self.logger.log(lp.WARNING, str(self.success) + " : " + str(self.mountPoint) + " : " + str(self.ramdiskDev))
        self.mount = self.mountPoint

        self.logger.log(lp.INFO, "::::::::Ramdisk Mount Point: " + str(self.mountPoint))
        self.logger.log(lp.INFO, "::::::::Ramdisk Device     : " + str(self.ramdiskDev))

        if not self.success:
            raise IOError("Cannot get a ramdisk for some reason. . .")

        #####
        # Create a temp location on disk to run benchmark tests against
        self.fs_dir = tempfile.mkdtemp()

        # Start timer in miliseconds
        self.test_start_time = datetime.now()

        self.setUpInstanceSpecifics()
Ejemplo n.º 10
0
    def __init__(self, size=0, mountpoint=False, logger=False):
        """
        """
        #####
        # Version/timestamp is
        # <YYYY><MM><DD>.<HH><MM><SS>.<microseconds>
        # in UTC time
        self.module_version = '20160224.032043.009191'
        if not isinstance(logger, CyLogger):
            self.logger = CyLogger()
        else:
            self.logger = logger
        self.logger.log(lp.INFO, "Logger: " + str(self.logger))
        self.diskSize = size
        self.success = False
        self.myRamdiskDev = None
        if not mountpoint:
            self.getRandomizedMountpoint()
        else:
            self.mntPoint = mountpoint

        self.logger.log(lp.DEBUG, "disk size: " + str(self.diskSize))
        self.logger.log(lp.DEBUG, "volume name: " + str(self.mntPoint))
Ejemplo n.º 11
0
                  "--debug",
                  action="store_true",
                  dest="debug",
                  default=0,
                  help="Print debug messages")
parser.add_option("-v",
                  "--verbose",
                  action="store_true",
                  dest="verbose",
                  default=False,
                  help="Print status messages")

(opts, args) = parser.parse_args()

if opts.verbose:
    level = CyLogger(level=lp.INFO)
elif opts.debug:
    level = CyLogger(level=lp.DEBUG)
else:
    level = lp.WARNING

if opts.size:
    size = int(opts.size)  # in Megabytes
else:
    size = str(512)

if opts.mntpnt:
    mntpnt = opts.mntpnt
else:
    mntpnt = "uniontest"
Ejemplo n.º 12
0
    def __init__(self,
                 options=optparse.Values({"compileGui": False, "version": "0",
                                          "clean": False, "test": False,
                                          "debug":False, "sig":False,
                                          "hiddenImports":False,
                                          "keychain":''}),
                 ramdisk_size=1600):
        '''
        Initialization routine.
        @param: compileGui - bool to determine if the gui should be compiled
                             or not
        @param: version - if passed in, the version to use for app and package
                          creation.
        @param: clean - bool to determine whether or not to clean artifacts
                        from previous builds
        @param: test - Don't run the driver - specifically for unit testing
        @param: debug - bool to determine whether or not to log in debug mode
        @param: sig - signature to use for application and package signing
                      in the build process
        '''
        if isinstance(options.debug, bool) and options.debug:
            debug = 20
        else:
            debug = 40

        # format log file name according to tracker artf55027
        datestamp = datetime.datetime.now()
        stamp = datestamp.strftime("%Y-%m-%d_%H-%M-%S")
        log_name = "build-output_" + str(stamp) + ".log"
        # set macbuild logging path according to tracker artf55027
        try:
            log_path = os.path.dirname(os.path.realpath(__file__))
        except (IOError, OSError, AttributeError):
            log_path = os.getcwd()

        #####
        # helper class initialization
        self.logger = CyLogger(level=debug)
        # initialize the logger object to log macbuild.py logs according to tracker artf55027
        self.logger.initializeLogs(logdir=log_path, filename=log_name)
        self.rw = RunWith(self.logger)
        self.mu = ManageUser(self.logger)
        self.mk = ManageKeychain(self.logger)
        self.ramdisk_size = ramdisk_size
        self.libc = getLibc()

        #####
        # Handle command line options
        self.mbl = None
        self.signature = options.sig
        self.includeHiddenImports = options.hiddenImports
        self.keychain = options.keychain
        self.noExit = options.noExit

        # This script needs to be run from [stonixroot]/src/MacBuild; make sure
        # that is our current operating location
        cwd = os.getcwd()
        if not re.search("src/MacBuild$", cwd):
            print("This script needs to be run from src/MacBuild. Exiting...")
            exit(1)

        try:
            rmtree("/tmp/the_luggage")
        except OSError as e:
            if not e.errno == 2:
                raise
        #if options.clean:
        #    self.clean()

        if FISMACAT is not None and FISMACAT != '':
            self.FISMACAT = FISMACAT
        else:
            self.FISMACAT = "low"

        # If version was not included at command line, use hardcoded version
        # number
        if options.version == "0":
            self.APPVERSION = "0.9.5.1"
        else:
            self.APPVERSION = options.version

        self.compileGui = options.compileGui

        if not self._configParser():
            raise ConfusingConfigurationError("Cannot determine the correct configuration...")

        self.RSYNC = "/usr/bin/rsync"

        print(" ")
        print(" ")
        print("   ************************************************************")
        print("   ************************************************************")
        print(("   ***** App Version: " + self.APPVERSION))
        print("   ************************************************************")
        print("   ************************************************************")
        print(" ")
        print(" ")

        if self.signature:
            count = 0
            while count < 3:
                success = False
                self.keyuser = os.environ['SUDO_USER']
                self.keypass = getpass.getpass("Keychain Password: "******"Sorry, Keychain password is not valid... Please try again.")
                count += 1
            if not success:
                sys.exit(1)
            #####
            # Get a translated password
            self.ordPass = self.getOrdPass(self.keypass)

        else:
            self.keyuser = getpass.getuser()
            self.keypass = False
            self.ordPass = False

        if not options.test:
            self.driver()
Ejemplo n.º 13
0
                      "--verbose",
                      dest="verbose",
                      default="",
                      help="Determine verbosity if performing a codesign.")

    (opts, args) = parser.parse_args()

    log_level = ""
    if opts.debug:
        loglevel = 20
    elif opts.verbose:
        loglevel = 30
    else:
        loglevel = 40

    logger = CyLogger(level=lp.DEBUG)

    logger.initializeLogs()

    logger.log(lp.DEBUG, "Logger initialized")

    os.environ['DEVELOPER_DIR'] = '/Applications/Xcode.app/Contents/Developer'

    keychainPass = False

    if opts.password:
        #####
        # On the other end, each character was translated by 'ord' to a number,
        # and each number was separated by a colon.  Change the password from
        # letters that have been converted to a number via the 'ord' function
        # back to the origional character
 def setUpClass(self):
     """ 
     """
     self.logger = CyLogger(debug_mode=True)
     self.logger.initializeLogs()
     self.logger.log(lp.DEBUG, "Test " + self.__name__ + " initialized...")
Ejemplo n.º 15
0
#!/usr/bin/python
'''
TODO: Fix this example
'''

#--- Native python libraries
import sys

sys.path.append("../")

#--- non-native python libraries in this source tree
from ramdisk.lib.manage_user.macos_user import MacOSUser
from ramdisk.lib.loggers import CyLogger
from ramdisk.lib.loggers import LogPriority as lp

logger = CyLogger(debug_mode=True)
logger.initializeLogs()

mu = MacOSUser(logDispatcher=logger)

user = input("User to collect properties for: ")

success, userProperties = mu.getUserProperties(str(user))

print(str(userProperties))

for key, value in userProperties.iteritems():
    if not re.search("JPEG", key):
        print key + " : " + value
Ejemplo n.º 16
0
    if options.all:
        modules = None
    elif options.modules:
        modules = options.modules
    else:
        modules = None

    #####
    # ... processing logging options...
    if options.verbose:
        level = 20
    elif options.debug:
        level = 10
    else:
        level = 30
    logger = CyLogger(level=level)
    logger.initializeLogs(filename="ramdiskTestLog")

    logger.log(lp.DEBUG, "Modules: " + str(modules))

    #####
    # ... processing test prefixes
    if options.prefix:
        prefix = options.prefix
    else:
        prefix = ["test_", "Test_"]
    """
    #####
    # todo: Need to figure out a different way to do this that doesn't require interaction -
    # Perhaps a unittest needs to do this check as part of its tests rather than in the
    # test runner....
Ejemplo n.º 17
0
import unittest
import ctypes as C
from datetime import datetime

#####
# Include the parent project directory in the PYTHONPATH
appendDir = "/".join(
    os.path.abspath(os.path.dirname(__file__)).split('/')[:-1])
sys.path.append(appendDir)

# --- Non-native python libraries in this source tree
from ramdisk.lib.loggers import CyLogger
from ramdisk.lib.loggers import LogPriority as lp
from ramdisk.lib.getLibc import getLibc

LOGGER = CyLogger()
#LOGGER.setInitialLoggingLevel(30)


class test_getLibc(unittest.TestCase):
    """
    """
    metaVars = {'setupDone': None, 'testStartTime': 0, 'setupCount': 0}
    libc = getLibc()

    ##################################

    def setUp(self):
        """
        This method runs before each test run.