How to use the leo.core.leoGlobals.os_path_exists function in leo

To help you get started, we’ve selected a few leo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github leo-editor / leo-editor / leo / plugins / mod_read_dir_outline.py View on Github external
def importDir (self,dir,compteurglobal):

        """ La routine récursive de lecture des fichiers """

        if not g.os_path_exists(dir):
            if language == 'french':
                g.es("Ce répertoire n'existe pas: %s" + dir)
            else:
                g.es("No such Directory: %s" + dir)
            return compteurglobal

        head,tail = g.os_path_split(dir)
        c = self.c ; current = c.p
        try:
            #ici, on liste le contenu du répertoire
            body=""
            #@+<< listdir >>
            #@+node:ekr.20050301083306.11: *4* << listdir >>
            try:
                fichiers = os.listdir(dir)
                dossiers = []
github leo-editor / leo-editor / leo / core / leoApp.py View on Github external
def initWrapperLeoFile (self,c,fn):
        '''
        Create an empty file if the external fn is empty.

        Otherwise, create an @edit or @file node for the external file.
        '''
        # lm = self
        # Use the config params to set the size and location of the window.
        frame = c.frame
        frame.setInitialWindowGeometry()
        frame.deiconify()
        frame.lift()
        frame.resizePanesToRatio(frame.ratio,frame.secondary_ratio)
            # Resize the _new_ frame.
        if not g.os_path_exists(fn):
            p = c.rootPosition()
            # Create an empty @edit node unless fn is an .leo file.
            p.h = g.shortFileName(fn) if fn.endswith('.leo') else '@edit %s' % fn
            c.selectPosition(p)
        elif c.looksLikeDerivedFile(fn):
            # 2011/10/10: Create an @file node.
            p = c.importCommands.importDerivedFiles(parent=c.rootPosition(),
                paths=[fn],command=None) # Not undoable.
            if p and p.hasBack():
                p.back().doDelete()
                p = c.rootPosition()
            if not p: return None
        else:
            # Create an @edit node.
            s,e = g.readFileIntoString(fn)
            if s is None: return None
github leo-editor / leo-editor / leo / commands / commanderHelpCommands.py View on Github external
def openLeoPy(self, event=None):
    """Open leoPy.leo in a new Leo window."""
    c = self
    names = ('leoPy.leo', 'LeoPyRef.leo',) # Used in error message.
    for name in names:
        fileName = g.os_path_finalize_join(g.app.loadDir, "..", "core", name)
        # Only call g.openWithFileName if the file exists.
        if g.os_path_exists(fileName):
            c2 = g.openWithFileName(fileName, old_c=c)
            if c2: return
    g.es('not found:', ', '.join(names))
#@+node:ekr.20061018094539: *3* c_help.openLeoScripts
github leo-editor / leo-editor / leo / core / leoExternalFiles.py View on Github external
def create_temp_file(self, c, ext, p):
        '''
        Create the temp file used by open-with if necessary.
        Add the corresponding ExternalFile instance to self.files
        '''
        path = self.temp_file_path(c, p, ext)
        exists = g.os_path_exists(path)
        # Compute encoding and s.
        d2 = c.scanAllDirectives(p)
        encoding = d2.get('encoding', None)
        if encoding is None:
            encoding = c.config.default_derived_file_encoding
        s = g.toEncodedString(p.b, encoding, reportErrors=True)
        # Write the file *only* if it doesn't exist.
        # No need to read the file: recomputing s above suffices.
        if not exists:
            try:
                f = open(path, 'wb')
                f.write(s)
                f.flush()
                f.close()
            except IOError:
                g.error('exception creating temp file: %s' % path)
github leo-editor / leo-editor / leo / core / leoColorizer.py View on Github external
def isValidLanguage(self, language):
        """True if language exists in leo/modes."""
        fn = g.os_path_join(g.app.loadDir, '..', 'modes', f"{language}.py")
        return g.os_path_exists(fn)
    #@+node:ekr.20170127142001.7: *4* bjc.useSyntaxColoring & helper
github leo-editor / leo-editor / leo / core / leoApp.py View on Github external
def getDefaultFile (self):

        # Get the name of the workbook.
        fn = g.app.config.getString('default_leo_file')
        fn = g.os_path_finalize(fn)
        if not fn: return
        # g.trace(g.os_path_exists(fn),fn)
        if g.os_path_exists(fn):
            return fn
        elif g.os_path_isabs(fn):
            # Create the file.
            g.error('Using default leo file name:\n%s' % (fn))
            return fn
        else:
            # It's too risky to open a default file if it is relative.
            return None
    #@+node:ekr.20120219154958.10484: *5* LM.initApp
github leo-editor / leo-editor / leo / plugins / screenshots.py View on Github external
if not sc.screenshot_tree:
            sc.make_at_url_node_for_built_slide()
            return # Don't take any screenshot!
        # '@url screenshot' inhibits taking the screenshot.
        if not sc.find_node(sc.slide_node, '@url screenshot'):
            if sc.take_screen_shot():
                sc.make_at_url_node_for_screenshot()
            else:
                g.error('can not make screen shot:', p.h)
                sc.make_at_url_node_for_built_slide()
                return
        # "@url working file" inhibits making a new working file.
        if sc.find_node(sc.slide_node, '@url working file'):
            # Make a new output file *only* if the working file is newer.
            if (
                g.os_path_exists(sc.working_fn) and
                sc.output_fn and
                os.path.getmtime(sc.working_fn) >
                os.path.getmtime(sc.output_fn)
            ):
                sc.make_output_file()
            else:
                # Make sure this has been made.
                sc.make_at_url_node_for_output_file()
        else:
            # Make the working file and output file
            sc.make_working_file()
            if sc.edit_flag:
                sc.edit_working_file()
            sc.make_output_file()
        # Build slide after creating the output file ;-)
        sc.make_at_url_node_for_built_slide()
github leo-editor / leo-editor / leo / plugins / rst3.py View on Github external
else:
            g.error('unknown docutils extension: %s' % (self.ext))
            return ''

        # Make the stylesheet path relative to the directory containing the output file.
        rel_stylesheet_path = self.getOption('stylesheet_path') or ''

        # New in Leo 4.5: The rel_stylesheet_path is relative to the open directory.
        stylesheet_path = g.os_path_finalize_join(
            self.c.frame.openDirectory,rel_stylesheet_path)

        path = g.os_path_finalize_join(
            stylesheet_path,self.getOption('stylesheet_name'))

        res = ""
        if g.os_path_exists(path):
            if self.ext != '.pdf':
                overrides['stylesheet'] = path
                overrides['stylesheet_path'] = None
        elif styleSheetArgsDict:
            g.es_print('using publish_argv_for_missing_stylesheets',
                styleSheetArgsDict)
            overrides.update(styleSheetArgsDict)
                # MWC add args to settings
        elif rel_stylesheet_path == stylesheet_path:
            g.error('stylesheet not found: %s' % (path))
        else:
            g.error('stylesheet not found\n',path)
            if self.path:g.es_print('@path:', self.path)
            g.es_print('open path:',self.c.frame.openDirectory)
            if rel_stylesheet_path:
                g.es_print('relative path:', rel_stylesheet_path)
github leo-editor / leo-editor / leo / plugins / qt_gui.py View on Github external
def find_icon_path(self, setting):
        """Return the path to the open/close indicator icon."""
        c = self.c
        s = c.config.getString(setting)
        if not s:
            return None  # Not an error.
        for directory in self.compute_icon_directories():
            path = g.os_path_finalize_join(directory, s)
            if g.os_path_exists(path):
                return path
        g.es_print('no icon found for:', setting)
        return None
    #@+node:ekr.20180316091920.1: *3* ssm.Settings
github leo-editor / leo-editor / leo / core / leoApp.py View on Github external
def destroyOpenWithFileWithDict (self,theDict):

        '''
        A helper for app.destroyAllOpenWithFiles and
        app.destroyOpenWithFilesForFrame.
        '''

        path = theDict.get("path")
        if path and g.os_path_exists(path):
            try:
                os.remove(path)
                g.pr("deleting temp file: %s" % g.shortFileName(path))
            except:
                g.pr("can not delete temp file: %s" % path)

        # Remove theDict from the list so the gc can recycle the Leo window!
        g.app.openWithFiles.remove(theDict)
    #@+node:ekr.20031218072017.2615: *3* app.destroyWindow