Example #1
1
def make_cache_level(ncaches, prototypes, level, next_cache):
    global next_subsys_index, proto_l1, testerspec, proto_tester

    index = next_subsys_index[level]
    next_subsys_index[level] += 1

    # Create a subsystem to contain the crossbar and caches, and
    # any testers
    subsys = SubSystem()
    setattr(system, "l%dsubsys%d" % (level, index), subsys)

    # The levels are indexing backwards through the list
    ntesters = testerspec[len(cachespec) - level]

    # Scale the progress threshold as testers higher up in the tree
    # (smaller level) get a smaller portion of the overall bandwidth,
    # and also make the interval of packet injection longer for the
    # testers closer to the memory (larger level) to prevent them
    # hogging all the bandwidth
    limit = (len(cachespec) - level + 1) * 100000000
    testers = [proto_tester(interval=10 * (level * level + 1), progress_check=limit) for i in xrange(ntesters)]
    if ntesters:
        subsys.tester = testers

    if level != 0:
        # Create a crossbar and add it to the subsystem, note that
        # we do this even with a single element on this level
        xbar = L2XBar()
        subsys.xbar = xbar
        if next_cache:
            xbar.master = next_cache.cpu_side

        # Create and connect the caches, both the ones fanning out
        # to create the tree, and the ones used to connect testers
        # on this level
        tree_caches = [prototypes[0]() for i in xrange(ncaches[0])]
        tester_caches = [proto_l1() for i in xrange(ntesters)]

        subsys.cache = tester_caches + tree_caches
        for cache in tree_caches:
            cache.mem_side = xbar.slave
            make_cache_level(ncaches[1:], prototypes[1:], level - 1, cache)
        for tester, cache in zip(testers, tester_caches):
            tester.port = cache.cpu_side
            cache.mem_side = xbar.slave
    else:
        if not next_cache:
            print "Error: No next-level cache at top level"
            sys.exit(1)

        if ntesters > 1:
            # Create a crossbar and add it to the subsystem
            xbar = L2XBar()
            subsys.xbar = xbar
            xbar.master = next_cache.cpu_side
            for tester in testers:
                tester.port = xbar.slave
        else:
            # Single tester
            testers[0].port = next_cache.cpu_side
Example #2
0
 def bug_found(self):
     """
     Builds a crash-report when StarCluster encounters an unhandled
     exception. Report includes system info, python version, dependency
     versions, and a full debug log and stack-trace of the crash.
     """
     dashes = '-' * 10
     header = dashes + ' %s ' + dashes + '\n'
     crashfile = open(static.CRASH_FILE, 'w')
     argv = sys.argv[:]
     argv[0] = os.path.basename(argv[0])
     argv = ' '.join(argv)
     crashfile.write(header % "SYSTEM INFO")
     crashfile.write("StarCluster: %s\n" % __version__)
     crashfile.write("Python: %s\n" % sys.version.replace('\n', ' '))
     crashfile.write("Platform: %s\n" % platform.platform())
     dependencies = ['boto', 'paramiko', 'Crypto']
     for dep in dependencies:
         self.__write_module_version(dep, crashfile)
     crashfile.write("\n" + header % "CRASH DETAILS")
     crashfile.write('Command: %s\n\n' % argv)
     for line in logger.get_session_log():
         crashfile.write(line)
     crashfile.close()
     print
     log.error("Oops! Looks like you've found a bug in StarCluster")
     log.error("Crash report written to: %s" % static.CRASH_FILE)
     log.error("Please remove any sensitive data from the crash report")
     log.error("and submit it to starcluster@mit.edu")
     sys.exit(1)
def main(name):
  try:
    from python_qt_binding.QtGui import QApplication
  except:
    print >> sys.stderr, "please install 'python_qt_binding' package!!"
    sys.exit(-1)

  masteruri = init_cfg_path()
  parser = init_arg_parser()
  args = rospy.myargv(argv=sys.argv)
  parsed_args = parser.parse_args(args[1:])
  # Initialize Qt
  global app
  app = QApplication(sys.argv)

  # decide to show main or echo dialog
  global main_form
  if parsed_args.echo:
    main_form = init_echo_dialog(name, masteruri, parsed_args.echo[0], parsed_args.echo[1], parsed_args.hz)
  else:
    main_form = init_main_window(name, masteruri, parsed_args.file)

  # resize and show the qt window
  if not rospy.is_shutdown():
    os.chdir(PACKAGE_DIR) # change path to be able to the images of descriptions
    main_form.resize(1024, 720)
    screen_size = QApplication.desktop().availableGeometry()
    if main_form.size().width() >= screen_size.width() or main_form.size().height() >= screen_size.height()-24:
      main_form.showMaximized()
    else:
      main_form.show()
    exit_code = -1
    rospy.on_shutdown(finish)
    exit_code = app.exec_()
Example #4
0
def run(arguments=sys.argv[1:]):
    # parse the command line arguments
    (options, command) = parse_args(arguments)

    # ensure the binary is given
    if not options.binary:
        print "Please provide a path to your Firefox binary: -b, --binary"
        sys.exit(1)

    # set the BROWSER_PATH environment variable so that
    # subshells will be able to invoke mozrunner
    os.environ['BROWSER_PATH'] = options.binary

    # Parse the manifest
    mp = TestManifest(manifests=(options.manifest,), strict=False)

    # run + report
    if command == "testpy":
        tests = mp.active_tests(disabled=False)
        results = test_all_python(mp.get(tests=tests, type='python'), options)
        if results.failures or results.errors:
            sys.exit(report(True, results, None, options))
        else:
            sys.exit(report(False))

    elif command == "testjs":
        tests = mp.active_tests(disabled=False)
        results = test_all_js(mp.get(tests=tests, type='javascript'), options)
        if results.fails:
            sys.exit(report(True, None, results, options))
        else:
            sys.exit(report(False))

    elif command == "testall":
        test_all(mp.active_tests(disabled=False), options)
Example #5
0
def chainref_cmd ( cmd, host='/tmp/chainrefd', log=None ):
    if ( len(cmd) > 1 ):
        arg = cmd[1]
    else:
        arg = None

    if ( cmd[0] not in COMMANDS ):
        print 'chainref-cmd: invalid command \'%s\'' % cmd[0]
        return

    if ( cmd[0].startswith('ajax') ):
        host = '/tmp/chainref-ajax-0'

    if ( arg != None ):
        content = COMMANDS[cmd[0]] ( arg )
    else:
        content = COMMANDS[cmd[0]] ( )

    s = socket.socket ( socket.AF_UNIX, socket.SOCK_STREAM )

    try:
        s.connect ( host )
        s.send ( content )
    except Exception,e:
        print 'chainref-cmd: communication with server failed: %s' % str(e)
        s.close ( )
        sys.exit ( 1 )
Example #6
0
 def clean_up(self):
     """ Move DQ outputs to their appropriate directory """
     try:
         data_dir = os.environ["DATA"]
         plots_dir = os.environ["PLOTS"]
         logs_dir = os.environ["LOGS"]
     except KeyError as detail:
         print "GenerateSpectrum.clean_up: error", detail, "not set"
         print " --> source analysis environment scripts before running!"
         sys.exit(1)
     for root, dirs, files in os.walk(os.getcwd()):
         for file in files:
             is_data = re.search(r".*\.root$", file)
             is_plot = re.search(r".*\.png$", file)
             hostname = socket.gethostname()
             is_log =  re.search(r"^rat\."+hostname+r"\.[0-9]+\.log$", file)
             if is_data:
                 try:
                     root_file = TFile(file)
                     tree = root_file.Get("T")
                     tree.ls()
                 except ReferenceError as detail:
                     "generate_spectrum.clean_up: error in TFile,", detail
                     sys.exit(1)
                 file_manips.copy_file(os.path.join(root, file), data_dir)
             elif is_plot:
                 file_manips.copy_file(os.path.join(root, file), plots_dir)
             elif is_log:
                 file_manips.copy_file(os.path.join(root, file), logs_dir)
Example #7
0
    def _clone_test_db(self, suffix, verbosity, keepdb=False):
        source_database_name = self.connection.settings_dict['NAME']
        target_database_name = self.get_test_db_clone_settings(suffix)['NAME']
        test_db_params = {
            'dbname': self.connection.ops.quote_name(target_database_name),
            'suffix': self.sql_table_creation_suffix(),
        }
        with self._nodb_connection.cursor() as cursor:
            try:
                self._execute_create_test_db(cursor, test_db_params, keepdb)
            except Exception:
                try:
                    if verbosity >= 1:
                        self.log('Destroying old test database for alias %s...' % (
                            self._get_database_display_str(verbosity, target_database_name),
                        ))
                    cursor.execute('DROP DATABASE %(dbname)s' % test_db_params)
                    self._execute_create_test_db(cursor, test_db_params, keepdb)
                except Exception as e:
                    self.log('Got an error recreating the test database: %s' % e)
                    sys.exit(2)

        dump_cmd = DatabaseClient.settings_to_cmd_args(self.connection.settings_dict)
        dump_cmd[0] = 'mysqldump'
        dump_cmd[-1] = source_database_name
        load_cmd = DatabaseClient.settings_to_cmd_args(self.connection.settings_dict)
        load_cmd[-1] = target_database_name

        dump_proc = subprocess.Popen(dump_cmd, stdout=subprocess.PIPE)
        load_proc = subprocess.Popen(load_cmd, stdin=dump_proc.stdout, stdout=subprocess.PIPE)
        dump_proc.stdout.close()    # allow dump_proc to receive a SIGPIPE if load_proc exits.
        load_proc.communicate()
Example #8
0
def main():
    if sys.argv[1:]:
        try:
            fp = open(sys.argv[1], 'r')
        except IOError, msg:
            print 'Can\'t open "%s":' % sys.argv[1], msg
            sys.exit(1)
Example #9
0
def _maybe_extract(fpath, dirname, descend=True):
    path = os.path.dirname(fpath)
    untar_fpath = os.path.join(path, dirname)
    if not os.path.exists(untar_fpath):
        print('Extracting contents of "{}"...'.format(dirname))
        tfile = zipfile.ZipFile(fpath, 'r')
        try:
            tfile.extractall(untar_fpath)
        except (Exception, KeyboardInterrupt) as e:
            if os.path.exists(untar_fpath):
                if os.path.isfile(untar_fpath):
                    os.remove(untar_fpath)
                else:
                    shutil.rmtree(untar_fpath)
            raise
        tfile.close()
    if descend:
        dirs = [os.path.join(untar_fpath, o)
                for o in os.listdir(untar_fpath)
                if os.path.isdir(os.path.join(untar_fpath, o))]
        if len(dirs) != 1:
            print("Error, found not exactly one dir: {}".format(dirs))
            sys.exit(-1)
        return dirs[0]
    else:
        return untar_fpath
Example #10
0
	def setInitialCondition(self,U0):
		if np.shape(self.U) != np.shape(U0):
			print "Wrong shape",np.shape(U0)," of initial condition! Must match shape of mesh",np.shape(self.mesh),". Exiting"
			# U0 = U0[:np.shape(self.U)[0],:np.shape(self.U)[-1]]
			import sys
			sys.exit(0)
		self.Up = U0
def option_none(option, opt, value, parser):
    """ checks a parameter for taking value"""
    if parser.rargs and not parser.rargs[0].startswith('-'):
        print "Option arg error"
        print opt, " option should be empty"
        sys.exit(2)
    setattr(parser.values, option.dest, True)
Example #12
0
def main():
    idir, ofile, dffile = _parse_cmdline()

    print u'Loading doc-freqs file {}...'.format(dffile)
    with open(dffile, 'rb') as f:
        df = pickle.load(f)    

    print u'Reading input directory: {}'.format(idir)
    jobs = _load_jobs(idir, df)

    # Do the work.
    pool = Pool(4)
    njobs = len(jobs)

    try:
        import sys
        with codecs.open(ofile, 'wb') as pf:
            pickle.dump(njobs, pf)
            results = pool.imap_unordered(worker, jobs)
            for i, result in enumerate(results, 1):
                pickle.dump(result, pf)
                per = 100 * (float(i) / njobs)
                sys.stdout.write(u'\rPercent Complete: {:2.3f}%'.format(per))
                sys.stdout.flush()
            sys.stdout.write(u'\rPercent Complete: 100%    \n')
            sys.stdout.flush()

    except KeyboardInterrupt:
        sys.stdout.write(u'\rPercent Complete: {:2.3f}%    \n'.format(per))
        sys.stdout.write(u'Shutting down.\n')
        sys.stdout.flush()
        sys.exit()

    print u'Complete!'
Example #13
0
    def parse_subcommands(self, gparser=None):
        """
        Parse global arguments, find subcommand from list of subcommand
        objects, parse local subcommand arguments and return a tuple of
        global options, selected command object, command options, and
        command arguments.

        Call execute() on the command object to run. The command object has
        members 'gopts' and 'opts' set for global and command options
        respectively, you don't need to call execute with those but you could
        if you wanted to.
        """
        gparser = gparser or self.gparser
        # parse global options.
        gopts, args = gparser.parse_args()
        if not args:
            gparser.print_help()
            raise SystemExit("\nError: you must specify an action.")
        # set debug level if specified
        if gopts.DEBUG:
            console.setLevel(logger.DEBUG)
            config.DEBUG_CONFIG = True
        # load StarClusterConfig into global options
        try:
            cfg = config.StarClusterConfig(gopts.CONFIG)
            cfg.load()
        except exception.ConfigNotFound, e:
            log.error(e.msg)
            e.display_options()
            sys.exit(1)
Example #14
0
 def handle_completion(self):
     if self.is_completion_active():
         gparser = self.create_global_parser(no_usage=True, add_help=False)
         # set sys.path to COMP_LINE if it exists
         self._init_completion()
         # fetch the global options
         gopts = self.get_global_opts()
         # try to load StarClusterConfig into global options
         if gopts:
             try:
                 cfg = config.StarClusterConfig(gopts.CONFIG)
                 cfg.load()
             except exception.ConfigError:
                 cfg = None
             gopts.CONFIG = cfg
         scmap = {}
         for sc in commands.all_cmds:
             sc.gopts = gopts
             for n in sc.names:
                 scmap[n] = sc
         listcter = completion.ListCompleter(scmap.keys())
         subcter = completion.NoneCompleter()
         completion.autocomplete(gparser, listcter, None, subcter,
                                 subcommands=scmap)
         sys.exit(1)
Example #15
0
def lookup_command(command_name):
    """Lookup a command.

    command_name: the command name

    Returns: a method which implements that command
    """
    BASE_COMMANDS = {'help': print_help}

    REPLICATION_COMMANDS = {'compare': replication_compare,
                            'dump': replication_dump,
                            'livecopy': replication_livecopy,
                            'load': replication_load,
                            'size': replication_size}

    commands = {}
    for command_set in (BASE_COMMANDS, REPLICATION_COMMANDS):
        commands.update(command_set)

    try:
        command = commands[command_name]
    except KeyError:
        if command_name:
            sys.exit(_("Unknown command: %s") % command_name)
        else:
            command = commands['help']
    return command
Example #16
0
 def auth_dialog(self):
     try:
         with open(CONF_FILE) as conf:
             token = json.load(conf)
     except (OSError, json.JSONDecodeError, KeyError):
         print("Your token file doesn't exist or is malformed.")
         print("If you WANT to proceed anonymously, pass"
               "`-a/--anonymous` on the command line.")
         print("Or you can create a new token now. "
               "Create token? [y/n] ", end='')
         if input().lower() in ('y', 'yes'):
             username = input('Username: ')
             password = getpass.getpass()
             note = 'gist3_{}'.format(id_gen())
             resp = req.post(API_BASE + '/authorizations',
                             auth=(username, password),
                             json={'scopes': ['gist'],
                                   'note': note})
             if resp.status_code == req.codes.created:
                 token = resp.json()['token']
                 with open(CONF_FILE, 'w') as conf:
                     json.dump(token, conf)
                 print('Token created & saved to {}'.format(CONF_FILE))
             else:
                 print('There was an error from github: ')
                 print(json.dumps(resp.json(), sort_keys=True, indent=4))
                 sys.exit(2)
         else:
             print('Aborting...')
             sys.exit(0)
     return AccessTokenAuth(token)
Example #17
0
def links(args):
    """
    %prog links url

    Extract all the links "<a href=''>" from web page.
    """
    p = OptionParser(links.__doc__)
    p.add_option("--img", default=False, action="store_true",
                 help="Extract <img> tags [default: %default]")
    opts, args = p.parse_args(args)

    if len(args) != 1:
        sys.exit(not p.print_help())

    url, = args
    img = opts.img

    htmlfile = download(url)
    page = open(htmlfile).read()
    soup = BeautifulSoup(page)

    tag = 'img' if img else 'a'
    src = 'src' if img else 'href'
    aa = soup.findAll(tag)
    for a in aa:
        link = a.get(src)
        link = urljoin(url, link)
        print(link)
def main():
    print '----------------------------------'
    print '-    Coursera.org Downloader     -'
    print '-         by Logan Ding          -'
    print '----------------------------------'
    print
    # Add courses by yourself. Not all tested. You can feed back.
    course = { '1' : 'modelthinking',
               '2' : 'gametheory',  
               '3' : 'crypto',
               '4' : 'saas',
               '5' : 'pgm', 
               '6' : 'algo'}

    # Your Coursera.org email and password needed here to download videos. 
    email = 'youremail'
    password = 'password'

    if email == 'youremail':
        print 'You must change the email and the password to yours in main() first.'
        sys.exit(1)

    path  = download_path()
    print 'All files will be downloaded to:', path
    print
    course = choose_course(course)
    br = initialize_browser(course, email, password)
    mp4, pdf, pptx = resolve_resources(br, path)
    downloader(mp4, pdf, pptx, br, path)
Example #19
0
    def _collect(self, lines):
        elements = {}
        tag = None
        for line_tmp in lines:
            line = line_tmp.replace('!', '#').split('#')[0]
            for val in [x.lower() for x in line.split()]:
                if val in self._set_methods:
                    tag = val
                    elements[tag] = []
                elif tag is not None:
                    elements[tag].append(val)

        for tag in ['natom', 'ntypat']:
            if tag not in elements:
                print("%s is not found in the input file." % tag)
                sys.exit(1)

        for tag in elements:
            self._values = elements[tag]
            if tag == 'natom' or tag == 'ntypat':
                self._set_methods[tag]()

        for tag in elements:
            self._values = elements[tag]
            if tag != 'natom' and tag != 'ntypat':
                self._set_methods[tag]()
def initialize_browser(course, email, password):
    #Use mechanize to handle cookie
    print
    print 'Initialize browsering session...'
    br = mechanize.Browser()
    cj = cookielib.LWPCookieJar()
    br.set_cookiejar(cj)
    br.set_handle_equiv(True)
    #br.set_handle_gzip(True)
    br.set_handle_redirect(True)
    br.set_handle_referer(True)
    br.set_handle_robots(False)
    br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time = 0)
    auth_url = 'https://www.coursera.org/****/auth/auth_redirector?type=login&subtype=normal&email'.replace('****', course)
    br.open(auth_url)

    br.select_form(nr = 0)
    br.form['email'] =  email
    br.form['password'] = password
    br.submit()
    print 'It takes seconds to login and resolve resources to download...\n'

    #Check if email + password submitted correctly
    if 'https://www.coursera.org/****/auth/login_receiver?data='.replace('****', course) not in br.geturl():
        print 'Failed to login, exit...'
        sys.exit(1)

    video_lectures = 'https://www.coursera.org/****/lecture/index'.replace('****', course)
    br.open(video_lectures)
    return br
def listfunction(llist):
    """This function does all the work and lists groups or hosts"""
    variable_manager = VariableManager()
    loader = DataLoader()
    if not os.path.isfile(inventory_file):
        print "%s is not a file - halting. Consider using the '--inventory $path/to/ansible_inventory file' parameter" % inventory_file
        sys.exit(1)
    else:
        inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list=inventory_file)

    if chosen_group and single:
        def traverse(agroup, hostset):
            """Recursive depth-first traversal"""
            for child in agroup.child_groups:
                traverse(child, hostset)
            if len(agroup.hosts) > 0:
                hostset.add(agroup.hosts[0].name.encode('utf8'))
        single_hosts = set()
        traverse(inventory.groups[chosen_group], single_hosts)
        return {chosen_group:list(single_hosts)}

    if chosen_group:
        thegroup = inventory.groups[chosen_group]
        newhosts = []
        for h in thegroup.get_hosts():
            newhosts.append(h.name.encode('utf8'))
        return {chosen_group:newhosts}
    else:
        all_groups = {}
        for g in inventory.groups:
            newhosts = []
            for h in inventory.get_group(g).get_hosts():
                newhosts.append(h.name.encode('utf8'))
            all_groups[g] = newhosts
        return all_groups
Example #22
0
def main():
    topdir = detect_topdir()
    if topdir is None:
        print('Could not locate topdir. You must run ``gloabl-wasp`` '
              'either from a file tree'
              'containing a ``wasp`` file or from a build directory '
              'containing an initialized `{0}` file.'.format(CACHE_FILE))
        sys.exit(1)
    unpack_dir = os.path.join(topdir, UNPACK_DIR)
    if not os.path.exists(unpack_dir):
        fname = os.path.join(topdir, 'wasp')
        code = []
        with open(fname, 'r') as f:
            start = False
            for line in f:
                if 'wasp_packed=[' in line:
                    start = True
                if line == '\n' and start:
                    break
                if start:
                    code.append(line)
        vs = {}
        exec(''.join(code), vs, vs)
        unpack(unpack_dir, vs['wasp_packed'])
    sys.path.append(unpack_dir)
    run(topdir, unpack_dir)
Example #23
0
 def _act_on_pillows(self, action):
     # Used to stop or start pillows
     service = Pillowtop(self.environment, AnsibleContext(None))
     exit_code = service.run(action=action)
     if not exit_code == 0:
         print("ERROR while trying to {} pillows. Exiting.".format(action))
         sys.exit(1)
    def read(self,filename):

        try:
            self.file = open(filename, 'r')
        except IOError, (errno, strerror):
            print "Error Opening %s. (%s): %s" % (filename,errno, strerror)
            sys.exit(1)
def connectToDB():
    """
    _connectToDB_
    
    Connect to the database specified in the WMAgent config.
    """
    if not os.environ.has_key("WMAGENT_CONFIG"):
        print "Please set WMAGENT_CONFIG to point at your WMAgent configuration."
        sys.exit(1)
        
    if not os.path.exists(os.environ["WMAGENT_CONFIG"]):
        print "Can't find config: %s" % os.environ["WMAGENT_CONFIG"]
        sys.exit(1)

    wmAgentConfig = loadConfigurationFile(os.environ["WMAGENT_CONFIG"])
    
    if not hasattr(wmAgentConfig, "CoreDatabase"):
        print "Your config is missing the CoreDatabase section."

    socketLoc = getattr(wmAgentConfig.CoreDatabase, "socket", None)
    connectUrl = getattr(wmAgentConfig.CoreDatabase, "connectUrl", None)
    (dialect, junk) = connectUrl.split(":", 1)

    myWMInit = WMInit()
    myWMInit.setDatabaseConnection(dbConfig = connectUrl, dialect = dialect,
                                   socketLoc = socketLoc)
    return
    def call_all_circuits_with_seed(self, command, iteration, seed):
        stats_pattern = re.compile(self.stats_regex, re.DOTALL)
        self.command = command

        for circuit in self.circuits:
            print('    ' + circuit)
            out, err = self.call_circuit(command, circuit, iteration, seed)

            if err:
                print(err)
                print('There was a problem with circuit "{0}"'.format(circuit))
                sys.exit(1)

            # Get and save statistics
            match = stats_pattern.search(out)

            if match is None:
                print(out)
                print('Failed to match pattern: {0}'.format(self.stats_regex))
                sys.exit(1)

            for metric in self.metrics:
                group_name = metric.lower().replace(' ', '_')
                result = match.group(group_name)
                if not result:
                    result = 0

                self.results[circuit][metric].append(float(result))
Example #27
0
    def load_commands_from_entry_point(self, group='mach.providers'):
        """Scan installed packages for mach command provider entry points. An
        entry point is a function that returns a list of paths to files or
        directories containing command providers.

        This takes an optional group argument which specifies the entry point
        group to use. If not specified, it defaults to 'mach.providers'.
        """
        try:
            import pkg_resources
        except ImportError:
            print("Could not find setuptools, ignoring command entry points",
                  file=sys.stderr)
            return

        for entry in pkg_resources.iter_entry_points(group=group, name=None):
            paths = entry.load()()
            if not isinstance(paths, Iterable):
                print(INVALID_ENTRY_POINT % entry)
                sys.exit(1)

            for path in paths:
                if os.path.isfile(path):
                    self.load_commands_from_file(path)
                elif os.path.isdir(path):
                    self.load_commands_from_directory(path)
                else:
                    print("command provider '%s' does not exist" % path)
Example #28
0
def main():

    parser = argparse.ArgumentParser(description='Deploy interface.')
    parser.add_argument('--version', action='version', version=APP + " " + VERSION)
    parser.add_argument('--logging', dest='log_level', action='store',
                        default='DEBUG', choices=['DEBUG', 'INFO'],
                        help='Minimum level of logging message to show. Default (DEBUG)')

    subparsers = parser.add_subparsers(dest='cmd')

    parser_a = subparsers.add_parser('install',
                                     help='Run install')
    parser_a.set_defaults(func=install)

    parser_a = subparsers.add_parser('uninstall',
                                     help='Run uninstall')
    parser_a.set_defaults(func=uninstall)

    if len(sys.argv) == 1:
        error_msg = "ERROR: No arguments supplied!"
        print >> sys.stderr, error_msg
        parser.print_help()
        sys.exit(1)

    args = parser.parse_args()

    logging.basicConfig(level=args.log_level,
                        format=LOGGING_FORMAT)

    args.func(args)
Example #29
0
    def stop(self):
        """
                Stop the daemon
                """
        # Get the pid from the pidfile
        try:
            pf = file(self.pidfile, 'r')
            pid = int(pf.read().strip())
            pf.close()
        except IOError:
            pid = None

        if not pid:
            message = "pidfile %s does not exist. Daemon not running?\n"
            sys.stderr.write(message % self.pidfile)
            return  # not an error in a restart

        # Try killing the daemon process
        try:
            while 1:
                os.kill(pid, SIGTERM)
                time.sleep(0.1)
        except OSError, err:
            err = str(err)
            if err.find("No such process") > 0:
                if os.path.exists(self.pidfile):
                    os.remove(self.pidfile)
            else:
                print str(err)
                sys.exit(1)
Example #30
0
def copy_hardware(hemps_path, testcase_path, system_model_description):
    
    source_hw_path = hemps_path+"/hardware"
    testcase_hw_path = testcase_path+"/hardware"
    
    #Creates the direcoty into testcase path
    create_ifn_exists(testcase_hw_path)
    
    if system_model_description == "sc" or system_model_description == "scmod":
        
        delete_if_exists(testcase_hw_path+"/vhdl")
        source_hw_path = source_hw_path+"/sc"
        testcase_hw_path = testcase_hw_path+"/sc"
        ignored_names_list = [".svn" , ".vhd"]
        
    elif system_model_description == "vhdl":
        
        delete_if_exists(testcase_hw_path+"/sc")
        source_hw_path = source_hw_path+"/vhdl"
        testcase_hw_path = testcase_hw_path+"/vhdl"
        ignored_names_list = [".svn" , ".h", ".cpp"]
        
    else:
        sys.exit('Error in system_model_description - you must provide a compatible system model description')
    
    generic_copy(source_hw_path, testcase_hw_path, ignored_names_list)