예제 #1
0
def get_remote_file(filename, verbose=True):
    """
    INPUT:
        filename -- the URL of a file on the web, e.g.,
             "http://modular.math.washington.edu/myfile.txt"
        verbose -- whether to display download status

    OUTPUT:
        creates a file in the temp directory and returns the
        absolute path to that file.

    EXAMPLES:
        sage: g = get_remote_file("http://sagemath.org/ack.html", verbose=False)   # optional -- requires the internet
        sage: len(open(g).read())   # optional and randomly growing.
        10198                  
    """
    if verbose:
        print "Attempting to load remote file: " + filename
    from misc import tmp_filename
    temp_name = tmp_filename() + '.' + os.path.splitext(filename)[1][1:]
    # IMPORTANT -- urllib takes a long time to load,
    # so do not import it in the module scope.
    import urllib 
    global cur
    cur = 0
    if verbose:
        sys.stdout.write("Loading: [")
        sys.stdout.flush()
        urllib.urlretrieve(filename, temp_name, report_hook)
        print "]"
    else:
        urllib.urlretrieve(filename, temp_name)
    return temp_name
예제 #2
0
def get_remote_file(filename, verbose=True):
    """
    INPUT:
        filename -- the URL of a file on the web, e.g.,
             "http://modular.math.washington.edu/myfile.txt"
        verbose -- whether to display download status

    OUTPUT:
        creates a file in the temp directory and returns the
        absolute path to that file.

    EXAMPLES:
        sage: g = get_remote_file("http://sagemath.org/ack.html", verbose=False)   # optional -- requires the internet
        sage: len(open(g).read())   # optional and randomly growing.
        10198                  
    """
    if verbose:
        print "Attempting to load remote file: " + filename
    import misc

    temp_name = misc.tmp_filename() + '.' + os.path.splitext(filename)[1][1:]
    # IMPORTANT -- urllib takes a long time to load,
    # so do not import it in the module scope.
    import urllib
    global cur
    cur = 0
    if verbose:
        sys.stdout.write("Loading: [")
        sys.stdout.flush()
        urllib.urlretrieve(filename, temp_name, report_hook)
        print "]"
    else:
        urllib.urlretrieve(filename, temp_name)
    return temp_name
예제 #3
0
파일: hg.py 프로젝트: regmi/femhub_notebook
 def serve(self, port=8200, address='localhost',
           open_viewer=True, options=''):
     """
     Start a web server for this repository.
     
     This server is very nice - you can browse all files in the
     repository, see their changelogs, see who wrote any given line,
     etc. Very nice.
     
     INPUT:
     
     
     -  ``port`` - port that the server will listen on
     
     -  ``address`` - (default: 'localhost') address to
        listen on
     
     -  ``open_viewer`` - boolean (default: True); whether
        to pop up the web page
     
     -  ``options`` - a string passed directly to hg's serve
        command.
     """
     if open_viewer:
         cmd = 'sleep 1; %s http://%s:%s 1>&2 >/dev/null'%(browser(),
                                                           address, port)
         t = tmp_filename()
         open(t,'w').write(cmd)
         P = os.path.abspath(t)
         os.system('chmod +x %s; %s &'%(P, P))
         
     print_open_msg(address, port)
     self('serve --address %s --port %s  %s'%(address, port, options))
     print_open_msg(address, port)            
예제 #4
0
 def serve(self, port=8200, address='localhost',
           open_viewer=True, options=''):
     """
     Start a web server for this repository.
     
     This server is very nice - you can browse all files in the
     repository, see their changelogs, see who wrote any given line,
     etc. Very nice.
     
     INPUT:
     
     
     -  ``port`` - port that the server will listen on
     
     -  ``address`` - (default: 'localhost') address to
        listen on
     
     -  ``open_viewer`` - boolean (default: True); whether
        to pop up the web page
     
     -  ``options`` - a string passed directly to hg's serve
        command.
     """
     if open_viewer:
         cmd = 'sleep 1; %s http://%s:%s 1>&2 >/dev/null'%(browser(),
                                                           address, port)
         t = tmp_filename()
         open(t,'w').write(cmd)
         P = os.path.abspath(t)
         os.system('chmod +x %s; %s &'%(P, P))
         
     print_open_msg(address, port)
     self('serve --address %s --port %s  %s'%(address, port, options))
     print_open_msg(address, port)            
예제 #5
0
 def eval(self, x, globals={}, locals={}):
     if self._curdir is None:
         self._curdir = os.path.abspath(".")
     t = tmp_filename()
     out = tmp_filename()
     w = open(t, "w")
     w.write('cd "%s"\n' % self._curdir)
     w.write(x)
     w.write("\npwd\n")
     w.close()
     os.system('chmod +x "%s"; "%s" > "%s"' % (t, t, out))
     os.unlink(t)
     s = open(out).read()
     os.unlink(out)
     t = s.split("\n")
     self._curdir = os.path.abspath(t[-1])
     return "\n".join(t[:-1])