def open_page(address, port, secure, path=""): if secure: rsrc = 'https' else: rsrc = 'http' os.system('%s %s://%s:%s%s 1>&2 > /dev/null &'%(browser(), rsrc, address, port, path))
def open_page(address, port, secure, path=""): if secure: rsrc = "https" else: rsrc = "http" os.system("%s %s://%s:%s%s 1>&2 > /dev/null &" % (browser(), rsrc, address, port, path))
def view(self): if not self._viewer is None: viewer = self._viewer else: viewer = browser() os.system('%s "%s"&'%(viewer, self._filename))
def trac(directory='sage_trac', port=10000, address='localhost', open_viewer=False, auto_reload=False, easy_setup=False, options=''): r""" Start a Trac server, creating a new project, if necessary. An "optional" Sage package trac-x.y.z.spkg must already be installed. (Use optional_packages() to get the exact name.) INPUT: - ``directory`` - a string (default: 'sage_trac'); name of the project directory - ``port`` - an integer (default: 10000); the server's port number - ``address`` - a string (default: 'localhost'); the server's address - ``open_viewer`` - a bool (default: False); whether to open a browser at the server's address - ``auto_reload`` - a bool (default: False); whether the server should restart automatically when *its* sources are modified - ``easy_setup`` - a bool (default: False); **if** creating a new project, whether to enable optional plug-ins. See :func:`trac_create_instance`. - ``options`` - a string (default: ''); command-line options to pass directly to tracd """ from sage.misc.superseded import deprecation deprecation( 16759, "This Sage Trac Server interface is deprecated, you can just run the Trac server outside of Sage" ) if not os.path.exists(directory): trac_create_instance(directory, easy_setup=easy_setup) url = 'http://%s:%s' % (address, port) if open_viewer: cmd = 'sleep 2 && %s ' % browser() + url + ' 1>&2 >/dev/null &' os.system(cmd) passwd = os.path.join(directory, 'conf/passwd') if not os.path.exists(passwd) or len(open(passwd).read()) < 2: print("*" * 80) print( "Create new accounts with the htdigest command (part of Apache):") print("\nTo add a new user with name username:"******" cd %s" % os.path.abspath(os.path.join(directory, 'conf'))) print(" htdigest passwd %s <username>" % address) print("\nTo grant full admin permissions to a user:"******" %s %s permission add <username> TRAC_ADMIN" % (os.path.join( SAGE_LOCAL, 'bin', 'trac-admin'), os.path.abspath(directory))) print("\nThen restart the trac server.") print("*" * 80) open(passwd, 'w').close() print("Open your web browser to " + url) print("Starting a Trac server...") if auto_reload: options += ' --auto-reload ' cmd = 'tracd %s --port %s --hostname %s --auth *,%s,%s "%s" ' % ( options, port, address, passwd, address, directory) print(cmd) os.system(cmd)
def trac(directory = 'sage_trac', port = 10000, address = 'localhost', open_viewer = False, auto_reload = False, easy_setup = False, options = ''): r""" Start a Trac server, creating a new project, if necessary. An "optional" Sage package trac-x.y.z.spkg must already be installed. (Use optional_packages() to get the exact name.) INPUT: - ``directory`` - a string (default: 'sage_trac'); name of the project directory - ``port`` - an integer (default: 10000); the server's port number - ``address`` - a string (default: 'localhost'); the server's address - ``open_viewer`` - a bool (default: False); whether to open a browser at the server's address - ``auto_reload`` - a bool (default: False); whether the server should restart automatically when *its* sources are modified - ``easy_setup`` - a bool (default: False); **if** creating a new project, whether to enable optional plug-ins. See :func:`trac_create_instance`. - ``options`` - a string (default: ''); command-line options to pass directly to tracd """ if not os.path.exists(directory): trac_create_instance(directory, easy_setup = easy_setup) url = 'http://%s:%s' % (address, port) if open_viewer: cmd = 'sleep 2 && %s ' % browser() + url + ' 1>&2 >/dev/null &' os.system(cmd) passwd = os.path.join(directory, 'conf/passwd') if not os.path.exists(passwd) or len(open(passwd).read()) < 2: print "*" * 80 print "Create new accounts with the htdigest command (part of Apache):" print "\nTo add a new user with name username:"******" cd %s" % os.path.abspath(os.path.join(directory, 'conf')) print " htdigest passwd %s <username>" % address print "\nTo grant full admin permissions to a user:"******" %s %s permission add <username> TRAC_ADMIN" % (os.path.join(SAGE_LOCAL, 'bin','trac-admin'), os.path.abspath(directory)) print "\nThen restart the trac server." print "*" * 80 open(passwd,'w').close() print "Open your web browser to " + url print "Starting a Trac server..." if auto_reload: options += ' --auto-reload ' cmd ='tracd %s --port %s --hostname %s --auth *,%s,%s "%s" ' % (options, port, address, passwd, address, directory) print cmd os.system(cmd)
def svg(self, filename=None, view=True): """ Compiles the latex code with pdflatex and converts to a svg file. INPUT: - ``filename`` -- string (default:``None``), the output filename. If ``None``, it saves the file in a temporary directory. - ``view`` -- bool (default:``True``), whether to open the file in a browser. This option is ignored and automatically set to ``False`` if ``filename`` is not ``None``. OUTPUT: string, path to svg file EXAMPLES:: sage: from slabbe import TikzPicture sage: V = [[1,0,1],[1,0,0],[1,1,0],[0,0,-1],[0,1,0],[-1,0,0],[0,1,1],[0,0,1],[0,-1,0]] sage: P = Polyhedron(vertices=V).polar() sage: s = P.projection().tikz([674,108,-731],112) sage: t = TikzPicture(s) sage: _ = t.svg() # not tested :: sage: from sage.misc.temporary_file import tmp_filename sage: filename = tmp_filename('temp','.svg') sage: _ = t.svg(filename) # long time (2s) ACKNOWLEDGEMENT: The code was adapted and taken from the module :mod:`sage.misc.latex.py`. """ if not have_program('pdf2svg'): raise RuntimeError("pdf2svg does not seem to be installed. " "Install it for example with ``brew install pdf2svg``" " or ``apt-get install pdf2svg``.") # subprocess stuff from subprocess import check_call, PIPE _filename_pdf = self.pdf(filename=None, view=False) _filename, ext = os.path.splitext(_filename_pdf) _filename_svg = _filename+'.svg' # convert to svg cmd = ['pdf2svg', _filename_pdf, _filename_svg] cmd = ' '.join(cmd) check_call(cmd, shell=True, stdout=PIPE, stderr=PIPE) # move the svg into the good location if filename: filename = os.path.abspath(filename) cmd = ['mv', _filename_svg, filename] check_call(cmd, stdout=PIPE, stderr=PIPE) return filename # open the tmp svg elif view: from sage.misc.viewer import browser cmd = [browser(), _filename_svg] cmd = ' '.join(cmd) check_call(cmd, shell=True, stdout=PIPE, stderr=PIPE) return _filename_svg