Python os.getcwdu() Examples

The following are code examples for showing how to use os.getcwdu(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.

Example 1
Project: aws-cfn-plex   Author: lordmuffin   File: frontend.py    (license) View Source Project 6 votes vote down vote up
def make_paths_absolute(pathdict, keys, base_path=None):
    """
    Interpret filesystem path settings relative to the `base_path` given.

    Paths are values in `pathdict` whose keys are in `keys`.  Get `keys` from
    `OptionParser.relative_path_settings`.
    """
    if base_path is None:
        base_path = os.getcwdu() # type(base_path) == unicode
        # to allow combining non-ASCII cwd with unicode values in `pathdict`
    for key in keys:
        if key in pathdict:
            value = pathdict[key]
            if isinstance(value, list):
                value = [make_one_path_absolute(base_path, path)
                         for path in value]
            elif value:
                value = make_one_path_absolute(base_path, value)
            pathdict[key] = value 
Example 2
Project: AshsSDK   Author: thehappydinoa   File: frontend.py    (license) View Source Project 6 votes vote down vote up
def make_paths_absolute(pathdict, keys, base_path=None):
    """
    Interpret filesystem path settings relative to the `base_path` given.

    Paths are values in `pathdict` whose keys are in `keys`.  Get `keys` from
    `OptionParser.relative_path_settings`.
    """
    if base_path is None:
        base_path = os.getcwdu() # type(base_path) == unicode
        # to allow combining non-ASCII cwd with unicode values in `pathdict`
    for key in keys:
        if key in pathdict:
            value = pathdict[key]
            if isinstance(value, list):
                value = [make_one_path_absolute(base_path, path)
                         for path in value]
            elif value:
                value = make_one_path_absolute(base_path, value)
            pathdict[key] = value 
Example 3
Project: zippy   Author: securesystemslab   File: test_fixers.py    (license) View Source Project 6 votes vote down vote up
def test_basic(self):
        b = """os.getcwdu"""
        a = """os.getcwd"""
        self.check(b, a)

        b = """os.getcwdu()"""
        a = """os.getcwd()"""
        self.check(b, a)

        b = """meth = os.getcwdu"""
        a = """meth = os.getcwd"""
        self.check(b, a)

        b = """os.getcwdu(args)"""
        a = """os.getcwd(args)"""
        self.check(b, a) 
Example 4
Project: Solfege   Author: RannyeriDev   File: dataparser.py    (license) View Source Project 6 votes vote down vote up
def include(self):
        self._lexer.scan_any() # scan include
        self._lexer.scan_any() # scan (
        try:
            filename = self._lexer.scan('STRING')
        except:
            print >> sys.stderr, "Warning: The file '%s' uses old style syntax for the include command." % self.m_filename
            print >> sys.stderr, 'This is not fatal now but will be in the future. You should change the code\nfrom include(filename) to include("filename")\n'
            filename = self._lexer.scan('NAME')
        fn = os.path.join(self.m_location, filename)
       
        if not os.path.exists(fn):
            fn = os.path.join(os.getcwdu(), u'exercises/standard/lesson-files', filename)
        s = open(fn, 'rU').read()
        p = Dataparser()
        p.m_location = self.m_location
        p.parse_string(s)
        self._lexer.scan(')')
        return pt.IncludeStatement(p.tree) 
Example 5
Project: Solfege   Author: RannyeriDev   File: filesystem.py    (license) View Source Project 6 votes vote down vote up
def _get_home_dir():
    ''' Try to find user's home directory, otherwise return current directory.'''
    path1 = os.path.expanduser("~")
    try:
        path2 = os.environ["HOME"]
    except KeyError:
        path2 = ""
  
    try:
        path3 = os.environ["USERPROFILE"]
    except KeyError:
        path3 = ""

    if not os.path.exists(path1):
        
        if not os.path.exists(path2):
          
            if not os.path.exists(path3):
                return os.getcwdu()
          
            else: return path3
        
        else: return path2
    
    else: return path1 
Example 6
Project: oil   Author: oilshell   File: test_unicode_file.py    (license) View Source Project 6 votes vote down vote up
def _do_directory(self, make_name, chdir_name, encoded):
        if os.path.isdir(make_name):
            os.rmdir(make_name)
        os.mkdir(make_name)
        try:
            with change_cwd(chdir_name):
                if not encoded:
                    cwd_result = os.getcwdu()
                    name_result = make_name
                else:
                    cwd_result = os.getcwd().decode(TESTFN_ENCODING)
                    name_result = make_name.decode(TESTFN_ENCODING)

                cwd_result = unicodedata.normalize("NFD", cwd_result)
                name_result = unicodedata.normalize("NFD", name_result)

                self.assertEqual(os.path.basename(cwd_result),name_result)
        finally:
            os.rmdir(make_name)

    # The '_test' functions 'entry points with params' - ie, what the
    # top-level 'test' functions would be if they could take params 
Example 7
Project: oil   Author: oilshell   File: test_fixers.py    (license) View Source Project 6 votes vote down vote up
def test_basic(self):
        b = """os.getcwdu"""
        a = """os.getcwd"""
        self.check(b, a)

        b = """os.getcwdu()"""
        a = """os.getcwd()"""
        self.check(b, a)

        b = """meth = os.getcwdu"""
        a = """meth = os.getcwd"""
        self.check(b, a)

        b = """os.getcwdu(args)"""
        a = """os.getcwd(args)"""
        self.check(b, a) 
Example 8
Project: beg-django-e-commerce   Author: Apress   File: compilemessages.py    (license) View Source Project 6 votes vote down vote up
def updatemessages():
    from django.conf import settings
    if not settings.USE_I18N:
        return
    from django.core.management.commands.compilemessages import compile_messages
    if any([needs_update(path) for path in settings.LOCALE_PATHS]):
        compile_messages()
    LOCALE_PATHS = settings.LOCALE_PATHS
    settings.LOCALE_PATHS = ()
    cwd = os.getcwdu()
    for app in settings.INSTALLED_APPS:
        path = os.path.dirname(__import__(app, {}, {}, ['']).__file__)
        locale = os.path.join(path, 'locale')
        if os.path.isdir(locale):
            # Copy Python translations into JavaScript translations
            update_js_translations(locale)
            if needs_update(locale):
                os.chdir(path)
                compile_messages()
    settings.LOCALE_PATHS = LOCALE_PATHS
    os.chdir(cwd) 
Example 9
Project: python2-tracer   Author: extremecoders-re   File: test_unicode_file.py    (license) View Source Project 6 votes vote down vote up
def _do_directory(self, make_name, chdir_name, encoded):
        if os.path.isdir(make_name):
            os.rmdir(make_name)
        os.mkdir(make_name)
        try:
            with change_cwd(chdir_name):
                if not encoded:
                    cwd_result = os.getcwdu()
                    name_result = make_name
                else:
                    cwd_result = os.getcwd().decode(TESTFN_ENCODING)
                    name_result = make_name.decode(TESTFN_ENCODING)

                cwd_result = unicodedata.normalize("NFD", cwd_result)
                name_result = unicodedata.normalize("NFD", name_result)

                self.assertEqual(os.path.basename(cwd_result),name_result)
        finally:
            os.rmdir(make_name)

    # The '_test' functions 'entry points with params' - ie, what the
    # top-level 'test' functions would be if they could take params 
Example 10
Project: python2-tracer   Author: extremecoders-re   File: test_fixers.py    (license) View Source Project 6 votes vote down vote up
def test_basic(self):
        b = """os.getcwdu"""
        a = """os.getcwd"""
        self.check(b, a)

        b = """os.getcwdu()"""
        a = """os.getcwd()"""
        self.check(b, a)

        b = """meth = os.getcwdu"""
        a = """meth = os.getcwd"""
        self.check(b, a)

        b = """os.getcwdu(args)"""
        a = """os.getcwd(args)"""
        self.check(b, a) 
Example 11
Project: STaaS   Author: CESNET   File: warden_server.py    (license) View Source Project 6 votes vote down vote up
def getDebug(self):
        return {
            "environment": self.req.env,
            "client": self.req.client.__dict__,
            "database": self.db.get_debug(),
            "system": {
                "uname": os.uname()
            },
            "process": {
                "cwd": os.getcwdu(),
                "pid": os.getpid(),
                "ppid": os.getppid(),
                "pgrp": os.getpgrp(),
                "uid": os.getuid(),
                "gid": os.getgid(),
                "euid": os.geteuid(),
                "egid": os.getegid(),
                "groups": os.getgroups()
            }
        } 
Example 12
Project: chalktalk_docs   Author: loremIpsum1771   File: frontend.py    (license) View Source Project 6 votes vote down vote up
def make_paths_absolute(pathdict, keys, base_path=None):
    """
    Interpret filesystem path settings relative to the `base_path` given.

    Paths are values in `pathdict` whose keys are in `keys`.  Get `keys` from
    `OptionParser.relative_path_settings`.
    """
    if base_path is None:
        base_path = os.getcwdu() # type(base_path) == unicode
        # to allow combining non-ASCII cwd with unicode values in `pathdict`
    for key in keys:
        if key in pathdict:
            value = pathdict[key]
            if isinstance(value, list):
                value = [make_one_path_absolute(base_path, path)
                         for path in value]
            elif value:
                value = make_one_path_absolute(base_path, value)
            pathdict[key] = value 
Example 13
Project: pefile.pypy   Author: cloudtracer   File: test_fixers.py    (license) View Source Project 6 votes vote down vote up
def test_basic(self):
        b = """os.getcwdu"""
        a = """os.getcwd"""
        self.check(b, a)

        b = """os.getcwdu()"""
        a = """os.getcwd()"""
        self.check(b, a)

        b = """meth = os.getcwdu"""
        a = """meth = os.getcwd"""
        self.check(b, a)

        b = """os.getcwdu(args)"""
        a = """os.getcwd(args)"""
        self.check(b, a) 
Example 14
Project: ouroboros   Author: pybee   File: test_fixers.py    (license) View Source Project 6 votes vote down vote up
def test_basic(self):
        b = """os.getcwdu"""
        a = """os.getcwd"""
        self.check(b, a)

        b = """os.getcwdu()"""
        a = """os.getcwd()"""
        self.check(b, a)

        b = """meth = os.getcwdu"""
        a = """meth = os.getcwd"""
        self.check(b, a)

        b = """os.getcwdu(args)"""
        a = """os.getcwd(args)"""
        self.check(b, a) 
Example 15
Project: alfred-mpd   Author: deanishe   File: workflow.py    (license) View Source Project 5 votes vote down vote up
def workflowdir(self):
        """Path to workflow's root directory (where ``info.plist`` is).

        :returns: full path to workflow root directory
        :rtype: ``unicode``

        """
        if not self._workflowdir:
            # Try the working directory first, then the directory
            # the library is in. CWD will be the workflow root if
            # a workflow is being run in Alfred
            candidates = [
                os.path.abspath(os.getcwdu()),
                os.path.dirname(os.path.abspath(os.path.dirname(__file__)))]

            # climb the directory tree until we find `info.plist`
            for dirpath in candidates:

                # Ensure directory path is Unicode
                dirpath = self.decode(dirpath)

                while True:
                    if os.path.exists(os.path.join(dirpath, 'info.plist')):
                        self._workflowdir = dirpath
                        break

                    elif dirpath == '/':
                        # no `info.plist` found
                        break

                    # Check the parent directory
                    dirpath = os.path.dirname(dirpath)

                # No need to check other candidates
                if self._workflowdir:
                    break

            if not self._workflowdir:
                raise IOError("'info.plist' not found in directory tree")

        return self._workflowdir 
Example 16
Project: epubcheck   Author: titusz   File: cli.py    (BSD 2-Clause "Simplified" License) View Source Project 5 votes vote down vote up
def create_parser():
    """Creat a commandline parser for epubcheck

    :return Argumentparser:
    """

    parser = ArgumentParser(
        prog='epubcheck',
        description="EpubCheck v%s - Validate your ebooks" % __version__
    )

    # Arguments
    parser.add_argument(
        'path',
        nargs='?',
        default=getcwd(),
        help="Path to EPUB-file or folder for batch validation. "
             "The current directory will be processed if this argument "
             "is not specified."
    )

    # Options
    parser.add_argument(
        '-x', '--xls', nargs='?', type=FileType(mode='wb'),
        const='epubcheck_report.xls',
        help='Create a detailed Excel report.'
    )

    parser.add_argument(
        '-c', '--csv', nargs='?', type=FileType(mode='wb'),
        const='epubcheck_report.csv',
        help='Create a CSV report.'
    )

    parser.add_argument(
        '-r', '--recursive', action='store_true',
        help='Recurse into subfolders.'
    )

    return parser 
Example 17
Project: kinect-2-libras   Author: inessadl   File: ntpath.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
def abspath(path):
        """Return the absolute version of a path."""
        if not isabs(path):
            if isinstance(path, unicode):
                cwd = os.getcwdu()
            else:
                cwd = os.getcwd()
            path = join(cwd, path)
        return normpath(path) 
Example 18
Project: kinect-2-libras   Author: inessadl   File: ntpath.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
def abspath(path):
        """Return the absolute version of a path."""

        if path: # Empty path must return current working directory.
            try:
                path = _getfullpathname(path)
            except WindowsError:
                pass # Bad path - return unchanged.
        elif isinstance(path, unicode):
            path = os.getcwdu()
        else:
            path = os.getcwd()
        return normpath(path)

# realpath is a no-op on systems without islink support 
Example 19
Project: kinect-2-libras   Author: inessadl   File: posixpath.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
def abspath(path):
    """Return an absolute path."""
    if not isabs(path):
        if isinstance(path, unicode):
            cwd = os.getcwdu()
        else:
            cwd = os.getcwd()
        path = join(cwd, path)
    return normpath(path)


# Return a canonical path (i.e. the absolute location of a file on the
# filesystem). 
Example 20
Project: kinect-2-libras   Author: inessadl   File: macpath.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
def abspath(path):
    """Return an absolute path."""
    if not isabs(path):
        if isinstance(path, unicode):
            cwd = os.getcwdu()
        else:
            cwd = os.getcwd()
        path = join(cwd, path)
    return normpath(path)

# realpath is a no-op on systems without islink support 
Example 21
Project: kinect-2-libras   Author: inessadl   File: os2emxpath.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
def abspath(path):
    """Return the absolute version of a path"""
    if not isabs(path):
        if isinstance(path, unicode):
            cwd = os.getcwdu()
        else:
            cwd = os.getcwd()
        path = join(cwd, path)
    return normpath(path)

# realpath is a no-op on systems without islink support 
Example 22
Project: senf   Author: quodlibet   File: _stdlib.py    (MIT License) View Source Project 5 votes vote down vote up
def getcwd():
    """Like `os.getcwd` but returns a `fsnative` path

    Returns:
        `fsnative`
    """

    if is_win and PY2:
        return os.getcwdu()
    return os.getcwd() 
Example 23
Project: swjtu-pyscraper   Author: Desgard   File: ntpath.py    (MIT License) View Source Project 5 votes vote down vote up
def abspath(path):
        """Return the absolute version of a path."""
        if not isabs(path):
            if isinstance(path, _unicode):
                cwd = os.getcwdu()
            else:
                cwd = os.getcwd()
            path = join(cwd, path)
        return normpath(path) 
Example 24
Project: swjtu-pyscraper   Author: Desgard   File: ntpath.py    (MIT License) View Source Project 5 votes vote down vote up
def abspath(path):
        """Return the absolute version of a path."""

        if path: # Empty path must return current working directory.
            try:
                path = _getfullpathname(path)
            except WindowsError:
                pass # Bad path - return unchanged.
        elif isinstance(path, _unicode):
            path = os.getcwdu()
        else:
            path = os.getcwd()
        return normpath(path)

# realpath is a no-op on systems without islink support 
Example 25
Project: swjtu-pyscraper   Author: Desgard   File: posixpath.py    (MIT License) View Source Project 5 votes vote down vote up
def abspath(path):
    """Return an absolute path."""
    if not isabs(path):
        if isinstance(path, _unicode):
            cwd = os.getcwdu()
        else:
            cwd = os.getcwd()
        path = join(cwd, path)
    return normpath(path)


# Return a canonical path (i.e. the absolute location of a file on the
# filesystem). 
Example 26
Project: workflows.kyoyue   Author: wizyoung   File: workflow.py    (MIT License) View Source Project 5 votes vote down vote up
def workflowdir(self):
        """Path to workflow's root directory (where ``info.plist`` is).

        :returns: full path to workflow root directory
        :rtype: ``unicode``

        """
        if not self._workflowdir:
            # Try the working directory first, then the directory
            # the library is in. CWD will be the workflow root if
            # a workflow is being run in Alfred
            candidates = [
                os.path.abspath(os.getcwdu()),
                os.path.dirname(os.path.abspath(os.path.dirname(__file__)))]

            # climb the directory tree until we find `info.plist`
            for dirpath in candidates:

                # Ensure directory path is Unicode
                dirpath = self.decode(dirpath)

                while True:
                    if os.path.exists(os.path.join(dirpath, 'info.plist')):
                        self._workflowdir = dirpath
                        break

                    elif dirpath == '/':
                        # no `info.plist` found
                        break

                    # Check the parent directory
                    dirpath = os.path.dirname(dirpath)

                # No need to check other candidates
                if self._workflowdir:
                    break

            if not self._workflowdir:
                raise IOError("'info.plist' not found in directory tree")

        return self._workflowdir 
Example 27
Project: CodingDojo   Author: ComputerSocietyUNB   File: _os.py    (license) View Source Project 5 votes vote down vote up
def abspathu(path):
        """
        Version of os.path.abspath that uses the unicode representation
        of the current working directory, thus avoiding a UnicodeDecodeError
        in join when the cwd has non-ASCII characters.
        """
        if not isabs(path):
            path = join(os.getcwdu(), path)
        return normpath(path) 
Example 28
Project: hostapd-mana   Author: adde88   File: ntpath.py    (license) View Source Project 5 votes vote down vote up
def abspath(path):
        """Return the absolute version of a path."""
        if not isabs(path):
            if isinstance(path, unicode):
                cwd = os.getcwdu()
            else:
                cwd = os.getcwd()
            path = join(cwd, path)
        return normpath(path) 
Example 29
Project: hostapd-mana   Author: adde88   File: ntpath.py    (license) View Source Project 5 votes vote down vote up
def abspath(path):
        """Return the absolute version of a path."""

        if path: # Empty path must return current working directory.
            try:
                path = _getfullpathname(path)
            except WindowsError:
                pass # Bad path - return unchanged.
        elif isinstance(path, unicode):
            path = os.getcwdu()
        else:
            path = os.getcwd()
        return normpath(path)

# realpath is a no-op on systems without islink support 
Example 30
Project: hostapd-mana   Author: adde88   File: posixpath.py    (license) View Source Project 5 votes vote down vote up
def abspath(path):
    """Return an absolute path."""
    if not isabs(path):
        if isinstance(path, _unicode):
            cwd = os.getcwdu()
        else:
            cwd = os.getcwd()
        path = join(cwd, path)
    return normpath(path)


# Return a canonical path (i.e. the absolute location of a file on the
# filesystem). 
Example 31
Project: hostapd-mana   Author: adde88   File: macpath.py    (license) View Source Project 5 votes vote down vote up
def abspath(path):
    """Return an absolute path."""
    if not isabs(path):
        if isinstance(path, unicode):
            cwd = os.getcwdu()
        else:
            cwd = os.getcwd()
        path = join(cwd, path)
    return normpath(path)

# realpath is a no-op on systems without islink support 
Example 32
Project: hostapd-mana   Author: adde88   File: os2emxpath.py    (license) View Source Project 5 votes vote down vote up
def abspath(path):
    """Return the absolute version of a path"""
    if not isabs(path):
        if isinstance(path, unicode):
            cwd = os.getcwdu()
        else:
            cwd = os.getcwd()
        path = join(cwd, path)
    return normpath(path)

# realpath is a no-op on systems without islink support 
Example 33
Project: Sci-Finder   Author: snverse   File: ntpath.py    (license) View Source Project 5 votes vote down vote up
def abspath(path):
        """Return the absolute version of a path."""
        if not isabs(path):
            if isinstance(path, _unicode):
                cwd = os.getcwdu()
            else:
                cwd = os.getcwd()
            path = join(cwd, path)
        return normpath(path) 
Example 34
Project: Sci-Finder   Author: snverse   File: ntpath.py    (license) View Source Project 5 votes vote down vote up
def abspath(path):
        """Return the absolute version of a path."""

        if path: # Empty path must return current working directory.
            try:
                path = _getfullpathname(path)
            except WindowsError:
                pass # Bad path - return unchanged.
        elif isinstance(path, _unicode):
            path = os.getcwdu()
        else:
            path = os.getcwd()
        return normpath(path)

# realpath is a no-op on systems without islink support 
Example 35
Project: Sci-Finder   Author: snverse   File: posixpath.py    (license) View Source Project 5 votes vote down vote up
def abspath(path):
    """Return an absolute path."""
    if not isabs(path):
        if isinstance(path, _unicode):
            cwd = os.getcwdu()
        else:
            cwd = os.getcwd()
        path = join(cwd, path)
    return normpath(path)


# Return a canonical path (i.e. the absolute location of a file on the
# filesystem). 
Example 36
Project: Sci-Finder   Author: snverse   File: ntpath.py    (license) View Source Project 5 votes vote down vote up
def abspath(path):
        """Return the absolute version of a path."""
        if not isabs(path):
            if isinstance(path, _unicode):
                cwd = os.getcwdu()
            else:
                cwd = os.getcwd()
            path = join(cwd, path)
        return normpath(path) 
Example 37
Project: Sci-Finder   Author: snverse   File: ntpath.py    (license) View Source Project 5 votes vote down vote up
def abspath(path):
        """Return the absolute version of a path."""

        if path: # Empty path must return current working directory.
            try:
                path = _getfullpathname(path)
            except WindowsError:
                pass # Bad path - return unchanged.
        elif isinstance(path, _unicode):
            path = os.getcwdu()
        else:
            path = os.getcwd()
        return normpath(path)

# realpath is a no-op on systems without islink support 
Example 38
Project: GoToMeetingTools   Author: plongitudes   File: workflow.py    (license) View Source Project 5 votes vote down vote up
def workflowdir(self):
        """Path to workflow's root directory (where ``info.plist`` is).

        :returns: full path to workflow root directory
        :rtype: ``unicode``

        """
        if not self._workflowdir:
            # Try the working directory first, then the directory
            # the library is in. CWD will be the workflow root if
            # a workflow is being run in Alfred
            candidates = [
                os.path.abspath(os.getcwdu()),
                os.path.dirname(os.path.abspath(os.path.dirname(__file__)))]

            # climb the directory tree until we find `info.plist`
            for dirpath in candidates:

                # Ensure directory path is Unicode
                dirpath = self.decode(dirpath)

                while True:
                    if os.path.exists(os.path.join(dirpath, 'info.plist')):
                        self._workflowdir = dirpath
                        break

                    elif dirpath == '/':
                        # no `info.plist` found
                        break

                    # Check the parent directory
                    dirpath = os.path.dirname(dirpath)

                # No need to check other candidates
                if self._workflowdir:
                    break

            if not self._workflowdir:
                raise IOError("'info.plist' not found in directory tree")

        return self._workflowdir 
Example 39
Project: radar   Author: amoose136   File: workflow.py    (license) View Source Project 5 votes vote down vote up
def workflowdir(self):
        """Path to workflow's root directory (where ``info.plist`` is).

        :returns: full path to workflow root directory
        :rtype: ``unicode``

        """
        if not self._workflowdir:
            # Try the working directory first, then the directory
            # the library is in. CWD will be the workflow root if
            # a workflow is being run in Alfred
            candidates = [
                os.path.abspath(os.getcwdu()),
                os.path.dirname(os.path.abspath(os.path.dirname(__file__)))]

            # climb the directory tree until we find `info.plist`
            for dirpath in candidates:

                # Ensure directory path is Unicode
                dirpath = self.decode(dirpath)

                while True:
                    if os.path.exists(os.path.join(dirpath, 'info.plist')):
                        self._workflowdir = dirpath
                        break

                    elif dirpath == '/':
                        # no `info.plist` found
                        break

                    # Check the parent directory
                    dirpath = os.path.dirname(dirpath)

                # No need to check other candidates
                if self._workflowdir:
                    break

            if not self._workflowdir:
                raise IOError("'info.plist' not found in directory tree")

        return self._workflowdir 
Example 40
Project: alfred-workflows   Author: arthurhammer   File: workflow.py    (license) View Source Project 5 votes vote down vote up
def workflowdir(self):
        """Path to workflow's root directory (where ``info.plist`` is).

        :returns: full path to workflow root directory
        :rtype: ``unicode``

        """
        if not self._workflowdir:
            # Try the working directory first, then the directory
            # the library is in. CWD will be the workflow root if
            # a workflow is being run in Alfred
            candidates = [
                os.path.abspath(os.getcwdu()),
                os.path.dirname(os.path.abspath(os.path.dirname(__file__)))]

            # climb the directory tree until we find `info.plist`
            for dirpath in candidates:

                # Ensure directory path is Unicode
                dirpath = self.decode(dirpath)

                while True:
                    if os.path.exists(os.path.join(dirpath, 'info.plist')):
                        self._workflowdir = dirpath
                        break

                    elif dirpath == '/':
                        # no `info.plist` found
                        break

                    # Check the parent directory
                    dirpath = os.path.dirname(dirpath)

                # No need to check other candidates
                if self._workflowdir:
                    break

            if not self._workflowdir:
                raise IOError("'info.plist' not found in directory tree")

        return self._workflowdir 
Example 41
Project: psyplot   Author: Chilipp   File: pycompat.py    (license) View Source Project 5 votes vote down vote up
def getcwd(*args, **kwargs):
        return os.getcwdu(*args, **kwargs) 
Example 42
Project: alfred-bear   Author: chrisbro   File: workflow.py    (license) View Source Project 5 votes vote down vote up
def workflowdir(self):
        """Path to workflow's root directory (where ``info.plist`` is).

        :returns: full path to workflow root directory
        :rtype: ``unicode``

        """
        if not self._workflowdir:
            # Try the working directory first, then the directory
            # the library is in. CWD will be the workflow root if
            # a workflow is being run in Alfred
            candidates = [
                os.path.abspath(os.getcwdu()),
                os.path.dirname(os.path.abspath(os.path.dirname(__file__)))]

            # climb the directory tree until we find `info.plist`
            for dirpath in candidates:

                # Ensure directory path is Unicode
                dirpath = self.decode(dirpath)

                while True:
                    if os.path.exists(os.path.join(dirpath, 'info.plist')):
                        self._workflowdir = dirpath
                        break

                    elif dirpath == '/':
                        # no `info.plist` found
                        break

                    # Check the parent directory
                    dirpath = os.path.dirname(dirpath)

                # No need to check other candidates
                if self._workflowdir:
                    break

            if not self._workflowdir:
                raise IOError("'info.plist' not found in directory tree")

        return self._workflowdir 
Example 43
Project: CrowdAnki   Author: Stvad   File: ntpath.py    (license) View Source Project 5 votes vote down vote up
def abspath(path):
        """Return the absolute version of a path."""
        if not isabs(path):
            if isinstance(path, _unicode):
                cwd = os.getcwdu()
            else:
                cwd = os.getcwd()
            path = join(cwd, path)
        return normpath(path) 
Example 44
Project: CrowdAnki   Author: Stvad   File: ntpath.py    (license) View Source Project 5 votes vote down vote up
def abspath(path):
        """Return the absolute version of a path."""

        if path: # Empty path must return current working directory.
            try:
                path = _getfullpathname(path)
            except WindowsError:
                pass # Bad path - return unchanged.
        elif isinstance(path, _unicode):
            path = os.getcwdu()
        else:
            path = os.getcwd()
        return normpath(path)

# realpath is a no-op on systems without islink support 
Example 45
Project: alfred-confluence   Author: skleinei   File: workflow.py    (license) View Source Project 5 votes vote down vote up
def workflowdir(self):
        """Path to workflow's root directory (where ``info.plist`` is).

        :returns: full path to workflow root directory
        :rtype: ``unicode``

        """
        if not self._workflowdir:
            # Try the working directory first, then the directory
            # the library is in. CWD will be the workflow root if
            # a workflow is being run in Alfred
            candidates = [
                os.path.abspath(os.getcwdu()),
                os.path.dirname(os.path.abspath(os.path.dirname(__file__)))]

            # climb the directory tree until we find `info.plist`
            for dirpath in candidates:

                # Ensure directory path is Unicode
                dirpath = self.decode(dirpath)

                while True:
                    if os.path.exists(os.path.join(dirpath, 'info.plist')):
                        self._workflowdir = dirpath
                        break

                    elif dirpath == '/':
                        # no `info.plist` found
                        break

                    # Check the parent directory
                    dirpath = os.path.dirname(dirpath)

                # No need to check other candidates
                if self._workflowdir:
                    break

            if not self._workflowdir:
                raise IOError("'info.plist' not found in directory tree")

        return self._workflowdir 
Example 46
Project: RPoint   Author: george17-meet   File: ntpath.py    (license) View Source Project 5 votes vote down vote up
def abspath(path):
        """Return the absolute version of a path."""
        if not isabs(path):
            if isinstance(path, _unicode):
                cwd = os.getcwdu()
            else:
                cwd = os.getcwd()
            path = join(cwd, path)
        return normpath(path) 
Example 47
Project: RPoint   Author: george17-meet   File: ntpath.py    (license) View Source Project 5 votes vote down vote up
def abspath(path):
        """Return the absolute version of a path."""

        if path: # Empty path must return current working directory.
            try:
                path = _getfullpathname(path)
            except WindowsError:
                pass # Bad path - return unchanged.
        elif isinstance(path, _unicode):
            path = os.getcwdu()
        else:
            path = os.getcwd()
        return normpath(path)

# realpath is a no-op on systems without islink support 
Example 48
Project: RPoint   Author: george17-meet   File: posixpath.py    (license) View Source Project 5 votes vote down vote up
def abspath(path):
    """Return an absolute path."""
    if not isabs(path):
        if isinstance(path, _unicode):
            cwd = os.getcwdu()
        else:
            cwd = os.getcwd()
        path = join(cwd, path)
    return normpath(path)


# Return a canonical path (i.e. the absolute location of a file on the
# filesystem). 
Example 49
Project: alfred_reviewboard   Author: lydian   File: workflow.py    (license) View Source Project 5 votes vote down vote up
def workflowdir(self):
        """Path to workflow's root directory (where ``info.plist`` is).

        :returns: full path to workflow root directory
        :rtype: ``unicode``

        """
        if not self._workflowdir:
            # Try the working directory first, then the directory
            # the library is in. CWD will be the workflow root if
            # a workflow is being run in Alfred
            candidates = [
                os.path.abspath(os.getcwdu()),
                os.path.dirname(os.path.abspath(os.path.dirname(__file__)))]

            # climb the directory tree until we find `info.plist`
            for dirpath in candidates:

                # Ensure directory path is Unicode
                dirpath = self.decode(dirpath)

                while True:
                    if os.path.exists(os.path.join(dirpath, 'info.plist')):
                        self._workflowdir = dirpath
                        break

                    elif dirpath == '/':
                        # no `info.plist` found
                        break

                    # Check the parent directory
                    dirpath = os.path.dirname(dirpath)

                # No need to check other candidates
                if self._workflowdir:
                    break

            if not self._workflowdir:
                raise IOError("'info.plist' not found in directory tree")

        return self._workflowdir 
Example 50
Project: habilitacion   Author: GabrielBD   File: ntpath.py    (license) View Source Project 5 votes vote down vote up
def abspath(path):
        """Return the absolute version of a path."""
        if not isabs(path):
            if isinstance(path, _unicode):
                cwd = os.getcwdu()
            else:
                cwd = os.getcwd()
            path = join(cwd, path)
        return normpath(path)