예제 #1
0
파일: AIPSDir.py 프로젝트: mauch/Obit
def PListDir(disk,
             err,
             type="  ",
             first=1,
             last=1000,
             Aname=None,
             Aclass=None,
             Aseq=0,
             giveList=False):
    """
    List AIPS directory
    
    Entries can be selected using Aname, Aclass, Aseq, using AIPS wildcards
    A "?" matches one of any character, "*" matches any string
    all blanks matches anything
    If giveList then return list of CNOs

    * disk     = AIPS disk number
    * err      = Python Obit Error/message stack
    * type     = optional file type
    * Aname    = desired name, using AIPS wildcards, None -> don't check
    * Aclass   = desired class, using AIPS wildcards, None -> don't check
    * Aseq     = desired sequence, 0=> any
    * first    = optional first slot number (1-rel)
    * last     = optional last slot number
    * giveList = If true, return list of CNOs matching
    """
    ################################################################
    # Checks
    if not OErr.OErrIsA(err):
        raise TypeError, "err MUST be an OErr"
    #
    user = OSystem.PGetAIPSuser()
    ncno = PNumber(disk, user, err)
    OErr.printErrMsg(err, "Error getting number of cnos")
    # Init output
    if giveList:
        olist = []
    else:
        olist = None

    mincno = first
    maxcno = min(ncno, last)
    dirlist = "AIPS Directory listing for disk " + str(disk) + "\n"
    for cno in range(mincno, maxcno):
        line = PInfo(disk, user, cno, err)
        if WantDir(line, type=type, Aname=Aname, Aclass=Aclass, Aseq=Aseq):
            OErr.printErrMsg(err, "Error reading entry")
            dirlist = dirlist + string.rjust(str(cno), 3) + " " + line + "\n"
            if giveList:
                olist.append(cno)
    if err.isErr:
        OErr.printErrMsg(err, "Error getting AIPS directory listing")
    # User pager
    pydoc.ttypager(dirlist)
    return olist
예제 #2
0
파일: ObitScript.py 프로젝트: mauch/Obit-1
 def inputs(self):
     """List script"""
     scrList = "Listing of script " + self._name + "\n"
     if self.url:  # Remote host?
         scrList += "Execution host: " + self.url + "\n"
     for x in self.script:
         if not x.endswith("\n"):  # Make sure terminated
             x += "\n"
         scrList += x
     pydoc.ttypager(scrList)
     del scrList
예제 #3
0
파일: AIPSDir.py 프로젝트: mauch/Obit
def PListCat(cat,
             disk,
             type="  ",
             first=1,
             last=1000,
             Aname=None,
             Aclass=None,
             Aseq=0,
             giveList=False):
    """
    List AIPS directory given as entries in cat
    
    Entries can be selected using Aname, Aclass, Aseq, using AIPS wildcards
    A "?" matches one of any character, "*" matches any string
    all blanks matches anything
    If giveList then return list of CNOs

    * cat      = list of catalog entries as (cno,s)
      s is a string consisting of:

          ======  =============
          Aname   s[0:12]
          Aclass  s[13:19]
          Aseq    int(s[20:25])
          Atype   s[26:28]
          ======  =============
    * disk     = AIPS disk number
    * type     = optional file type
    * Aname    = desired name, using AIPS wildcards, None -> don't check
    * Aclass   = desired class, using AIPS wildcards, None -> don't check
    * Aseq     = desired sequence, 0=> any
    * first    = optional first slot number (1-rel)
    * last     = optional last slot number
    * giveList = If true, return list of CNOs matching (no terminal output)
    """
    ################################################################
    # Init output
    if giveList:
        olist = []
    else:
        olist = None
    ncno = len(cat)
    mincno = first
    maxcno = min(ncno, last)
    dirlist = "AIPS Directory listing for disk " + str(disk) + "\n"
    for (cno, line) in cat:
        if WantDir(line, type=type, Aname=Aname, Aclass=Aclass, Aseq=Aseq):
            dirlist = dirlist + string.rjust(str(cno), 3) + " " + line + "\n"
            if giveList:
                olist.append(cno)
    # Use pager if giveList is False
    if not giveList:
        pydoc.ttypager(dirlist)
    return olist
 def test_ttypager(self):
     # ttypager does not choke on unicode
     doc = pydoc.render_doc(self.Q)
     # Test ttypager
     with test.test_support.temp_cwd(), test.test_support.captured_stdin():
         with open('output', 'w') as f:
             saved, sys.stdout = sys.stdout, f
             try:
                 pydoc.ttypager(doc)
             finally:
                 sys.stdout = saved
         self.assertIn('Rational numbers:', open('output').read())
 def test_ttypager(self):
     # ttypager does not choke on unicode
     doc = pydoc.render_doc(self.Q)
     # Test ttypager
     with test.test_support.temp_cwd(), test.test_support.captured_stdin():
         with open('output', 'w') as f:
             saved, sys.stdout = sys.stdout, f
             try:
                 pydoc.ttypager(doc)
             finally:
                 sys.stdout = saved
         self.assertIn('Rational numbers:', open('output').read())
예제 #6
0
def ListFITSDirs():
    """ List currently defined FITS directories
    
    """
    dirlist = "\nFITS Directories \n"
    diskno = 1
    for fdisk in FITS.disks[1:]:
        if fdisk.url:
            url = fdisk.url
        else:
            url = "localhost"
        dirlist =  dirlist+string.rjust(str(diskno),3)+"  "+fdisk.dirname+ \
                  ", URL="+url+"\n"
        diskno += 1
    # User pager
    pydoc.ttypager(dirlist)
예제 #7
0
def ListAIPSDirs():
    """ List currently defined AIPS directories
    
    """
    dirlist = "\nAIPS Directories \n"
    diskno = 1
    for adisk in AIPS.disks[1:]:
        if adisk.url:
            url = adisk.url
        else:
            url = "localhost"
        dirlist =  dirlist+str(diskno).rjust(3)+"  "+adisk.dirname+ \
                  ", URL="+url+"\n"
        diskno += 1
    # User pager
    pydoc.ttypager(dirlist)
예제 #8
0
def PListDir(disk, err, type = "  ", first=1, last=1000,
             Aname=None, Aclass=None, Aseq=0, giveList=False):
    """ List AIPS directory

    Entries can be selected using Aname, Aclass, Aseq, using AIPS wildcards
    A "?" matches one of any character, "*" matches any string
    all blanks matches anything
    If giveList then return list of CNOs
    disk     = AIPS disk number
    err      = Python Obit Error/message stack
    type     = optional file type
    Aname    = desired name, using AIPS wildcards, None -> don't check
    Aclass   = desired class, using AIPS wildcards, None -> don't check
    Aseq     = desired sequence, 0=> any
    first    = optional first slot number (1-rel)
    last     = optional last slot number
    giveList = If true, return list of CNOs matching
    """
    ################################################################
    # Checks
    if not OErr.OErrIsA(err):
        raise TypeError,"err MUST be an OErr"
    #
    user = OSystem.PGetAIPSuser()
    ncno = PNumber (disk, user, err)
    OErr.printErrMsg(err, "Error getting number of cnos")
    # Init output
    if giveList:
        olist = []
    else:
        olist = None

    mincno = first;
    maxcno = min (ncno, last)
    dirlist = "AIPS Directory listing for disk "+str(disk)+"\n"
    for cno in range(mincno, maxcno):
        line=PInfo(disk, user, cno, err);
        if WantDir(line, type=type, Aname=Aname, Aclass=Aclass, Aseq=Aseq):
            OErr.printErrMsg(err, "Error reading entry")
            dirlist = dirlist+string.rjust(str(cno),3)+" "+line+"\n"
            if giveList:
                olist.append(cno)
    if err.isErr:
        OErr.printErrMsg(err, "Error getting AIPS directory listing")
    # User pager
    pydoc.ttypager(dirlist)
    return olist
예제 #9
0
def prompt_cards(cards, cycle=False, shuffle=False, dash_cut=100):
    names = list(cards.keys())
    if shuffle:
        random.shuffle(names)
    if cycle:
        names = util.cycle(names, shuffle_bet=shuffle)

    for name in names:
        print("\n" * 3)
        input(name)
        if len(name) <= dash_cut:
            print("-" * len(name))
        elif len(cards[name]) <= dash_cut:
            print("-" * len(cards[name]))
        else:
            print("-" * dash_cut)
        pydoc.ttypager(cards[name])
        input()
예제 #10
0
def cmd_log():
    global refresh_ui_lines
    ctx = "LOG"
    n = uinput("Number of previous log lines to display:")
    clear(s=True)
    try:
        n = int(n)
        info(ctx, "Displaying last %s status lines" % n)
    except:
        n = ""
        info(ctx, "Displaying complete status lines log")
    if n == "":
        pydoc.ttypager("\n ".join(status_hist))
    else:
        pydoc.ttypager("\n ".join(status_hist[-n:]))
    input("\n\nEnd of log file; Press <ENTER> to continue")
    clear(s=True)
    refresh_ui_lines = True
예제 #11
0
def PListCat(cat, disk, type = "  ", first=1, last=1000,
             Aname=None, Aclass=None, Aseq=0, giveList=False):
    """ List AIPS directory given as entries in cat

    Entries can be selected using Aname, Aclass, Aseq, using AIPS wildcards
    A "?" matches one of any character, "*" matches any string
    all blanks matches anything
    If giveList then return list of CNOs
    cat      = list of catalog entries as (cno,s)
               s is a string consisting of:
               Aname  = s[0:12]
               Aclass = s[13:19]
               Aseq   = int(s[20:25])
               Atype  = s[26:28]
    disk     = AIPS disk number
    type     = optional file type
    Aname    = desired name, using AIPS wildcards, None -> don't check
    Aclass   = desired class, using AIPS wildcards, None -> don't check
    Aseq     = desired sequence, 0=> any
    first    = optional first slot number (1-rel)
    last     = optional last slot number
    giveList = If true, return list of CNOs matching
    """
    ################################################################
    # Init output
    if giveList:
        olist = []
    else:
        olist = None
    ncno = len(cat)
    mincno = first;
    maxcno = min (ncno, last)
    dirlist = "AIPS Directory listing for disk "+str(disk)+"\n"
    for (cno,line) in cat:
        if WantDir(line, type=type, Aname=Aname, Aclass=Aclass, Aseq=Aseq):
            dirlist = dirlist+string.rjust(str(cno),3)+" "+line+"\n"
            if giveList:
                olist.append(cno)
    # User pager
    pydoc.ttypager(dirlist)
    return olist
예제 #12
0
파일: java_gateway.py 프로젝트: gdw2/py4j
    def help(self, var, pattern=None, short_name=True, display=True):
        """Displays a help page about a class or an object.

        :param var: JavaObject or JavaClass for which a help page will be
         generated.

        :param pattern: Star-pattern used to filter the members. For example
         'get*Foo' may return getMyFoo, getFoo, getFooBar, but not bargetFoo.

        :param short_name: If True, only the simple name of the parameter
         types and return types will be displayed. If False, the fully
         qualified name of the types will be displayed.

        :param display: If True, the help page is displayed in an interactive
         page similar to the `help` command in Python. If False, the page is
         returned as a string.
        """
        if hasattr2(var, '_get_object_id'):
            command = HELP_COMMAND_NAME +\
                      HELP_OBJECT_SUBCOMMAND_NAME +\
                      var._get_object_id() + '\n' +\
                      get_command_part(pattern) +\
                      get_command_part(short_name) +\
                      END_COMMAND_PART
            answer = self._gateway_client.send_command(command)
        elif hasattr2(var, '_fqn'):
            command = HELP_COMMAND_NAME +\
                      HELP_CLASS_SUBCOMMAND_NAME +\
                      var._fqn + '\n' +\
                      get_command_part(pattern) +\
                      get_command_part(short_name) +\
                      END_COMMAND_PART
            answer = self._gateway_client.send_command(command)
        else:
            raise Py4JError('var is neither a Java Object nor a Java Class')

        help_page = get_return_value(answer, self._gateway_client, None, None)
        if (display):
            ttypager(help_page)
        else:
            return help_page
예제 #13
0
    def help(self, var, pattern=None, short_name=True, display=True):
        """Displays a help page about a class or an object.

        :param var: JavaObject or JavaClass for which a help page will be
         generated.

        :param pattern: Star-pattern used to filter the members. For example
         'get*Foo' may return getMyFoo, getFoo, getFooBar, but not bargetFoo.

        :param short_name: If True, only the simple name of the parameter
         types and return types will be displayed. If False, the fully
         qualified name of the types will be displayed.

        :param display: If True, the help page is displayed in an interactive
         page similar to the `help` command in Python. If False, the page is
         returned as a string.
        """
        if hasattr2(var, '_get_object_id'):
            command = HELP_COMMAND_NAME +\
                      HELP_OBJECT_SUBCOMMAND_NAME +\
                      var._get_object_id() + '\n' +\
                      get_command_part(pattern) +\
                      get_command_part(short_name) +\
                      END_COMMAND_PART
            answer = self._gateway_client.send_command(command)
        elif hasattr2(var, '_fqn'):
            command = HELP_COMMAND_NAME +\
                      HELP_CLASS_SUBCOMMAND_NAME +\
                      var._fqn + '\n' +\
                      get_command_part(pattern) +\
                      get_command_part(short_name) +\
                      END_COMMAND_PART
            answer = self._gateway_client.send_command(command)
        else:
            raise Py4JError('var is neither a Java Object nor a Java Class')

        help_page = get_return_value(answer, self._gateway_client, None, None)
        if (display):
            ttypager(help_page)
        else:
            return help_page
예제 #14
0
def PListDir(disk, dir=None):
    """ List files in FITS directory

    disk     = FITS disk number, <=0 -> current directory
    dir       = relative or abs. path of directory, def. = cwd
                Only used if disk == 0
    """
    ################################################################
    if disk>0:
        flist = os.listdir(FITSdisks[disk-1])
        dirlist = "FITS Directory listing for disk "+str(disk)+\
                  ":"+FITSdisks[disk-1]+"\n"
    else:  # current directory
        if dir==None:
            dir = "./"
        flist = os.listdir(dir)
        dirlist = "File listing for directory "+dir+"\n"
    i=0
    for f in flist:
        dirlist = dirlist +string.rjust(str(i),6)+" "+f+"\n"
        i = i+1
    # User pager
    pydoc.ttypager(dirlist)
예제 #15
0
  def do_ls(self, path):
    """ls command"""
    paging = False
    if path.find('|') > -1:
      tmpPath = path.split('|')
      path = ''
      for i in xrange(len(tmpPath) - 1):
        path += tmpPath[i].strip()
      paging = True

    text = ''
    if len(path) > 0 and path[0] == '-':
      try:
        if path[1] != 'a':
          print("ls: invalid option -- {}".format(path[1]))
          print("Try `help ls' for more information.")
        else:
          path = path[2:]
          self.__bkListAll(path)
      except IndexError as e:
        print("Invalid oprion:", e)
    elif path == '':
      res = self.__bklist(self.currentPath)
      for i in sorted(res):
        if paging:
          text += i['name'] + '\n'
        else:
          print(i['name'])
    else:
      res = self.__bklist(path)
      for i in sorted(res):
        if paging:
          text += i['name'] + '\n'
        else:
          print(i['name'])
    if paging:
      pydoc.ttypager(text)
예제 #16
0
파일: FITSDir.py 프로젝트: mauch/Obit
def PListDir(disk, dir=None):
    """
    List files in FITS directory

    * disk = FITS disk number, <=0 -> current directory
    * dir  = relative or abs. path of directory, def. = cwd
      Only used if disk == 0
    """
    ################################################################
    if disk > 0:
        flist = os.listdir(FITSdisks[disk - 1])
        dirlist = "FITS Directory listing for disk "+str(disk)+\
                  ":"+FITSdisks[disk-1]+"\n"
    else:  # current directory
        if dir == None:
            dir = "./"
        flist = os.listdir(dir)
        dirlist = "File listing for directory " + dir + "\n"
    i = 0
    for f in flist:
        dirlist = dirlist + string.rjust(str(i), 6) + " " + f + "\n"
        i = i + 1
    # User pager
    pydoc.ttypager(dirlist)
예제 #17
0
파일: pager.py 프로젝트: 5monkeys/bpython
def page_internal(data):
    """A more than dumb pager function."""
    if hasattr(pydoc, 'ttypager'):
        pydoc.ttypager(data)
    else:
        sys.stdout.write(data)
예제 #18
0
 def update_event(self, inp=-1):
     self.set_output_val(0, pydoc.ttypager(self.input(0)))
예제 #19
0
def page_internal(data):
    """A more than dumb pager function."""
    if hasattr(pydoc, 'ttypager'):
        pydoc.ttypager(data)
    else:
        sys.stdout.write(data)
예제 #20
0
파일: AIPSTask.py 프로젝트: mauch/Obit
    def __display_adverbs(self, adverbs, file=None):
        """Display task ADVERBS values and descriptions"""
        inpList = self._short_help
        inpList = inpList + "Adverbs     Values                        "+\
                  "           Comments\n"
        inpList = inpList + "------------------------------------------"+\
                  "-----------------------------------------------------\n"

        for adverb in adverbs:
            #if self.__dict__[adverb] == '':
            #    print "'%s': ''" % adverb
            #else:
            #    value = PythonList(self.__dict__[adverb])
            #    print "'%s': %s" % (adverb, value)
            #    pass
            #continue
            i = 0
            j = 0
            hlps = self._hlp_dict[adverb]
            hlp = hlps[j]
            value = PythonList(self.__dict__[adverb])
            s1 = str(adverb)+"             "
            # Python is SO hateful
            if str(value).startswith('['):  # list
                # How many nonzero/nonblank entries
                ecount = count_entries(value)
                s2=""
                while i<ecount and 2+len(s2)+len(str(value[i])[:47])<50:
                    s2 = s2 + str(value[i])[:47]+", "
                    i = i+1
                # remove final comma
                if i==ecount:
                    s2 = s2[:len(s2)-2]
                # Left justify
                s2 = s2 + "                                         "
                inpList = inpList + "%12s%50s%s\n" % (s1[:11], s2[:49], hlp)
                # Loop until done with values
                doh = 0
                while i<ecount:
                    # continuation of description?
                    j = j+1
                    if j<len(hlps):
                        hlp =  hlps[j]
                    else:
                        hlp = " "
                    s2=""
                    while i<ecount and 2+len(s2)+len(str(value[i])[:47])<50:
                        s2 = s2 + str(value[i])[:47]+", "
                        i = i+1
                    # remove final comma
                    if i==ecount:
                        s2 = s2[:len(s2)-2]
                    # Left justify
                    s2 = s2 + "                                         "
                    inpList = inpList + "            %50s%s\n" % (s2[:49], hlp)
                    doh += 1;
                    if doh>ecount:
                        break
            else:  # Scalar
                s2 = str(value)+"                                   "
                inpList = inpList + "%12s%50s%s\n" % (s1[:11], s2[:49], hlp)
                    
            # Any more parameter description lines?
            s1 = "     "
            s2 = "     "
            j = j + 1
            while j<len(hlps):
                hlp =  hlps[j]
                j = j + 1
                inpList = inpList + "%12s%50s%s\n" % (s1, s2, hlp)

        if file:
            fd = open(file, "a")
            fd.write(inpList)
            fd.close()
        else:
            pydoc.ttypager(inpList)
        del inpList