Python os.pardir() Examples

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

Example 1
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: state.py    (MIT License) View Source Project 7 votes vote down vote up
def __init__(self):
		now = datetime.datetime.now()
		self.py2 = py.is_py2() #truth test Python 2 interpreter
		self.py3 = py.is_py3() #truth test Python 3 interpreter
		self.py_major = py.py_major_version() #Python major version
		self.py_minor = py.py_minor_version() #Python minor version
		self.py_patch = py.py_patch_version() #Python patch version
		self.os = sys.platform #user operating system
		self.cwd = cwd() #current (present) working directory
		self.parent_dir = os.pardir
		self.default_path = os.defpath
		self.user_path = os.path.expanduser("~")
		self.string_encoding = sys.getdefaultencoding()
		self.file_encoding = sys.getfilesystemencoding()
		self.hour = now.hour
		self.min = now.minute
		self.year = now.year
		self.day = now.day
		self.month = now.month
		self.second = now.second 
Example 2
Project: python-   Author: secondtonone1   File: site.py    (license) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    builtins.copyright = _Printer("copyright", sys.copyright)
    if _is_jython:
        builtins.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    elif _is_pypy:
        builtins.credits = _Printer(
            "credits",
            "PyPy is maintained by the PyPy developers: http://pypy.org/")
    else:
        builtins.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    builtins.license = _Printer(
        "license", "See http://www.python.org/%.3s/license.html" % sys.version,
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 3
Project: my-first-blog   Author: AnkurBegining   File: bdist_egg.py    (license) View Source Project 6 votes vote down vote up
def zap_pyfiles(self):
        log.info("Removing .py files from temporary directory")
        for base, dirs, files in walk_egg(self.bdist_dir):
            for name in files:
                path = os.path.join(base, name)

                if name.endswith('.py'):
                    log.debug("Deleting %s", path)
                    os.unlink(path)

                if base.endswith('__pycache__'):
                    path_old = path

                    pattern = r'(?P<name>.+)\.(?P<magic>[^.]+)\.pyc'
                    m = re.match(pattern, name)
                    path_new = os.path.join(base, os.pardir, m.group('name') + '.pyc')
                    log.info("Renaming file from [%s] to [%s]" % (path_old, path_new))
                    try:
                        os.remove(path_new)
                    except OSError:
                        pass
                    os.rename(path_old, path_new) 
Example 4
Project: kinect-2-libras   Author: inessadl   File: site.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    __builtin__.copyright = _Printer("copyright", sys.copyright)
    if sys.platform[:4] == 'java':
        __builtin__.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    elif sys.platform == 'cli':
        __builtin__.credits = _Printer(
            "credits",
            "IronPython is maintained by the IronPython developers (www.ironpython.net).")
    else:
        __builtin__.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    __builtin__.license = _Printer(
        "license", "See http://www.python.org/%.3s/license.html" % sys.version,
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 5
Project: simple_rl   Author: david-abel   File: basic_test.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
def main():
    # Add examples to path.
    parent_dir = os.path.abspath(os.path.join(os.getcwd(), os.pardir))
    sys.path.insert(0, parent_dir)

    # Grab all example files.
    example_dir = os.path.join(os.getcwd(), "..", "examples")
    example_files = [f for f in os.listdir(example_dir) if os.path.isfile(os.path.join(example_dir, f)) and "py" == f.split(".")[-1] and "init" not in f and "viz_exam" not in f]

    print("\n" + "="*32)
    print("== Running", len(example_files), "simple_rl tests ==")
    print("="*32 + "\n")
    total_passed = 0

    for i, ex in enumerate(example_files):
        print("\t [Test", str(i + 1) + "] ", ex + ": ",)
        result = run_example(os.path.join(example_dir, ex))
        if result:
            total_passed += 1
            print("\t\tPASS.")
        else:
            print("\t\tFAIL.")
    print("\nResults:", total_passed, "/", len(example_files), "passed.") 
Example 6
Project: Blender-WMO-import-export-scripts   Author: WowDevTools   File: addon_updater.py    (GNU General Public License v3.0) View Source Project 6 votes vote down vote up
def create_backup(self):
        if self._verbose:print("Backing up current addon folder")
        local = os.path.join(self._updater_path,"backup")
        tempdest = os.path.join(self._addon_root,
                        os.pardir,
                        self._addon+"_updater_backup_temp")

        if os.path.isdir(local) == True:
            shutil.rmtree(local)
        if self._verbose:print("Backup destination path: ",local)

        # make the copy
        shutil.copytree(self._addon_root,tempdest)
        shutil.move(tempdest,local)

        # save the date for future ref
        now = datetime.now()
        self._json["backup_date"] = "{m}-{d}-{yr}".format(
                m=now.strftime("%B"),d=now.day,yr=now.year)
        self.save_updater_json() 
Example 7
Project: Blender-WMO-import-export-scripts   Author: WowDevTools   File: addon_updater.py    (GNU General Public License v3.0) View Source Project 6 votes vote down vote up
def restore_backup(self):
        if self._verbose:print("Restoring backup")

        if self._verbose:print("Backing up current addon folder")
        backuploc = os.path.join(self._updater_path,"backup")
        tempdest = os.path.join(self._addon_root,
                        os.pardir,
                        self._addon+"_updater_backup_temp")
        tempdest = os.path.abspath(tempdest)

        # make the copy
        shutil.move(backuploc,tempdest)
        shutil.rmtree(self._addon_root)
        os.rename(tempdest,self._addon_root)

        self._json["backup_date"] = ""
        self._json["just_restored"] = True
        self._json["just_updated"] = True
        self.save_updater_json()

        self.reload_addon() 
Example 8
Project: swjtu-pyscraper   Author: Desgard   File: site.py    (MIT License) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    builtins.copyright = _Printer("copyright", sys.copyright)
    if _is_jython:
        builtins.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    elif _is_pypy:
        builtins.credits = _Printer(
            "credits",
            "PyPy is maintained by the PyPy developers: http://pypy.org/")
    else:
        builtins.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    builtins.license = _Printer(
        "license", "See http://www.python.org/%.3s/license.html" % sys.version,
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 9
Project: sndlatr   Author: Schibum   File: __init__.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
def __open_resource(name):
    """Open a resource from the zoneinfo subdir for reading.

    Uses the pkg_resources module if available and no standard file
    found at the calculated location.
    """
    name_parts = name.lstrip('/').split('/')
    for part in name_parts:
        if part == os.path.pardir or os.path.sep in part:
            raise ValueError('Bad path segment: %r' % part)
    filename = os.path.join(os.path.dirname(__file__),
                            'zoneinfo', *name_parts)
    if not os.path.exists(filename) and resource_stream is not None:
        # http://bugs.launchpad.net/bugs/383171 - we avoid using this
        # unless absolutely necessary to help when a broken version of
        # pkg_resources is installed.
        return resource_stream(__name__, 'zoneinfo/' + name)
    return open(filename, 'rb') 
Example 10
Project: PTE   Author: pwn2winctf   File: localserver.py    (MIT License) View Source Project 6 votes vote down vote up
def main(port=8000):
    thisdir = os.path.dirname(os.path.realpath(__file__))
    rootdir = os.path.realpath(os.path.join(thisdir, os.pardir, os.pardir))
    subdir = SubRepo.get_path()

    ctf = os.path.basename(rootdir)
    submissions = os.path.basename(Settings.submissions_project)

    routes = [
        ('/%s' % ctf, rootdir),
        ('/%s' % submissions, subdir),
    ]

    forbidden = {
        LocalSettings.path(),
        TeamSecrets.path(),
    }

    HandlerClass = handler(routes, '/%s' % ctf, forbidden)

    server_address = ('localhost', port)
    httpd = HTTPServer(server_address, HandlerClass)
    sa = httpd.socket.getsockname()
    print("Serving HTTP on", sa[0], "port", sa[1], "...")
    httpd.serve_forever() 
Example 11
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: site.py    (MIT License) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    builtins.copyright = _Printer("copyright", sys.copyright)
    if _is_jython:
        builtins.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    elif _is_pypy:
        builtins.credits = _Printer(
            "credits",
            "PyPy is maintained by the PyPy developers: http://pypy.org/")
    else:
        builtins.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    builtins.license = _Printer(
        "license", "See http://www.python.org/%.3s/license.html" % sys.version,
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 12
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: site.py    (MIT License) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    builtins.copyright = _Printer("copyright", sys.copyright)
    if _is_jython:
        builtins.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    elif _is_pypy:
        builtins.credits = _Printer(
            "credits",
            "PyPy is maintained by the PyPy developers: http://pypy.org/")
    else:
        builtins.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    builtins.license = _Printer(
        "license", "See http://www.python.org/%.3s/license.html" % sys.version,
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 13
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: state.py    (MIT License) View Source Project 6 votes vote down vote up
def __init__(self):
		now = datetime.datetime.now()
		self.py2 = py.is_py2() #truth test Python 2 interpreter
		self.py3 = py.is_py3() #truth test Python 3 interpreter
		self.py_major = py.py_major_version() #Python major version
		self.py_minor = py.py_minor_version() #Python minor version
		self.py_patch = py.py_patch_version() #Python patch version
		self.os = sys.platform #user operating system
		self.cwd = cwd() #current (present) working directory
		self.parent_dir = os.pardir
		self.default_path = os.defpath
		self.user_path = os.path.expanduser("~")
		self.string_encoding = sys.getdefaultencoding()
		self.file_encoding = sys.getfilesystemencoding()
		self.hour = now.hour
		self.min = now.minute
		self.year = now.year
		self.day = now.day
		self.month = now.month
		self.second = now.second 
Example 14
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: site.py    (MIT License) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    builtins.copyright = _Printer("copyright", sys.copyright)
    if _is_jython:
        builtins.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    elif _is_pypy:
        builtins.credits = _Printer(
            "credits",
            "PyPy is maintained by the PyPy developers: http://pypy.org/")
    else:
        builtins.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    builtins.license = _Printer(
        "license", "See http://www.python.org/%.3s/license.html" % sys.version,
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 15
Project: jira_worklog_scanner   Author: pgarneau   File: site.py    (license) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    builtins.copyright = _Printer("copyright", sys.copyright)
    if _is_jython:
        builtins.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    elif _is_pypy:
        builtins.credits = _Printer(
            "credits",
            "PyPy is maintained by the PyPy developers: http://pypy.org/")
    else:
        builtins.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    builtins.license = _Printer(
        "license", "See http://www.python.org/%.3s/license.html" % sys.version,
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 16
Project: ave   Author: sonyxperiadev   File: apk.py    (BSD 3-Clause "New" or "Revised" License) View Source Project 6 votes vote down vote up
def t1(w):
    pretty = '%s t1' % __file__
    print(pretty)
    root_path = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir)
    rel_path = os.path.join(root_path, "handset/jobs/tests/testdata/galatea-v-1.apk")
    apk_path = os.path.abspath(rel_path)
    if not apk_path:
        print('FAIL %s: could not download apk' % pretty)
        return False

    try:
        package_name = w.get_package_name(apk_path) # apk
        if not package_name:
            print(
                'FAIL %s: Could not get package name of apk: %s'
                % (pretty, apk_path)
            )
            return False
    except Exception, e:
        print('FAIL %s: %s' % (pretty, str(e)))
        return False

    return True

# check that get_aapt_path return an existing path 
Example 17
Project: ave   Author: sonyxperiadev   File: apk.py    (BSD 3-Clause "New" or "Revised" License) View Source Project 6 votes vote down vote up
def t1(w):
    pretty = '%s t1' % __file__
    print(pretty)
    root_path = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir)
    rel_path = os.path.join(root_path, "handset/jobs/tests/testdata/galatea-v-1.apk")
    apk_path = os.path.abspath(rel_path)
    if not apk_path:
        print('FAIL %s: could not download apk' % pretty)
        return False

    try:
        package_name = w.get_package_name(apk_path) # apk
        if not package_name:
            print(
                'FAIL %s: Could not get package name of apk: %s'
                % (pretty, apk_path)
            )
            return False
    except Exception, e:
        print('FAIL %s: %s' % (pretty, str(e)))
        return False

    return True

# check that get_aapt_path return an existing path 
Example 18
Project: health-mosconi   Author: GNUHealth-Mosconi   File: jsonrpc.py    (license) View Source Project 6 votes vote down vote up
def translate_path(self, path):
        """Translate a /-separated PATH to the local filename syntax.

        Components that mean special things to the local file system
        (e.g. drive or directory names) are ignored.  (XXX They should
        probably be diagnosed.)

        """
        # abandon query parameters
        path = path.split('?', 1)[0]
        path = path.split('#', 1)[0]
        path = posixpath.normpath(urllib.unquote(path))
        words = path.split('/')
        words = filter(None, words)
        path = config.get('jsonrpc', 'data')
        for word in words:
            drive, word = os.path.splitdrive(word)
            head, word = os.path.split(word)
            if word in (os.curdir, os.pardir):
                continue
            path = os.path.join(path, word)
        return path 
Example 19
Project: CodingDojo   Author: ComputerSocietyUNB   File: site.py    (license) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    builtins.copyright = _Printer("copyright", sys.copyright)
    if _is_jython:
        builtins.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    elif _is_pypy:
        builtins.credits = _Printer(
            "credits",
            "PyPy is maintained by the PyPy developers: http://pypy.org/")
    else:
        builtins.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    builtins.license = _Printer(
        "license", "See http://www.python.org/%.3s/license.html" % sys.version,
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 20
Project: zanph   Author: zanph   File: site.py    (license) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    builtins.copyright = _Printer("copyright", sys.copyright)
    if _is_jython:
        builtins.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    elif _is_pypy:
        builtins.credits = _Printer(
            "credits",
            "PyPy is maintained by the PyPy developers: http://pypy.org/")
    else:
        builtins.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    builtins.license = _Printer(
        "license", "See http://www.python.org/%.3s/license.html" % sys.version,
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 21
Project: hostapd-mana   Author: adde88   File: site.py    (license) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    __builtin__.copyright = _Printer("copyright", sys.copyright)
    if sys.platform[:4] == 'java':
        __builtin__.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    else:
        __builtin__.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    __builtin__.license = _Printer(
        "license", "See http://www.python.org/psf/license/",
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 22
Project: hostapd-mana   Author: adde88   File: common.py    (license) View Source Project 6 votes vote down vote up
def bestrelpath(self, dest):
        """ return a string which is a relative path from self
            (assumed to be a directory) to dest such that
            self.join(bestrelpath) == dest and if not such
            path can be determined return dest.
        """
        try:
            if self == dest:
                return os.curdir
            base = self.common(dest)
            if not base:  # can be the case on windows
                return str(dest)
            self2base = self.relto(base)
            reldest = dest.relto(base)
            if self2base:
                n = self2base.count(self.sep) + 1
            else:
                n = 0
            l = [os.pardir] * n
            if reldest:
                l.append(reldest)
            target = dest.sep.join(l)
            return target
        except AttributeError:
            return str(dest) 
Example 23
Project: hostapd-mana   Author: adde88   File: SimpleHTTPServer.py    (license) View Source Project 6 votes vote down vote up
def translate_path(self, path):
        """Translate a /-separated PATH to the local filename syntax.

        Components that mean special things to the local file system
        (e.g. drive or directory names) are ignored.  (XXX They should
        probably be diagnosed.)

        """
        # abandon query parameters
        path = path.split('?',1)[0]
        path = path.split('#',1)[0]
        # Don't forget explicit trailing slash when normalizing. Issue17324
        trailing_slash = path.rstrip().endswith('/')
        path = posixpath.normpath(urllib.unquote(path))
        words = path.split('/')
        words = filter(None, words)
        path = os.getcwd()
        for word in words:
            drive, word = os.path.splitdrive(word)
            head, word = os.path.split(word)
            if word in (os.curdir, os.pardir): continue
            path = os.path.join(path, word)
        if trailing_slash:
            path += '/'
        return path 
Example 24
Project: Sci-Finder   Author: snverse   File: site.py    (license) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    builtins.copyright = _Printer("copyright", sys.copyright)
    if _is_jython:
        builtins.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    elif _is_pypy:
        builtins.credits = _Printer(
            "credits",
            "PyPy is maintained by the PyPy developers: http://pypy.org/")
    else:
        builtins.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    builtins.license = _Printer(
        "license", "See http://www.python.org/%.3s/license.html" % sys.version,
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 25
Project: Sci-Finder   Author: snverse   File: site.py    (license) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    builtins.copyright = _Printer("copyright", sys.copyright)
    if _is_jython:
        builtins.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    elif _is_pypy:
        builtins.credits = _Printer(
            "credits",
            "PyPy is maintained by the PyPy developers: http://pypy.org/")
    else:
        builtins.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    builtins.license = _Printer(
        "license", "See http://www.python.org/%.3s/license.html" % sys.version,
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 26
Project: Face-Recognition   Author: irmowan   File: vgg16.py    (license) View Source Project 6 votes vote down vote up
def __init__(self, vgg16_npy_path=None, trainable=True):
        if vgg16_npy_path is None:
            path = inspect.getfile(VGG16)
            path = os.path.abspath(os.path.join(path, os.pardir))
            path = os.path.join(path, "vgg16.npy")
            vgg16_npy_path = path
            print(path)
        self.trainable = trainable
        self.imgs = tf.placeholder(tf.float32, [None, 224, 224, 3], name='images')
        self.labels = tf.placeholder(tf.float32, [None, FLAGS.num_classes], name='labels')
        self.var_dict = {}
        self.temp_value = None
        self.data_dict = None
        with open(vgg16_npy_path, 'rb') as f:
            self.data_dict = np.load(vgg16_npy_path, encoding='latin1').item()
        # # self.data_dict = pickle.load(f)
        #    pickle.dump(self.data_dict, f, protocol=2) 
        self.lrn_rate = 0.01
        print("npy file loaded")
        self.build()
        self.loss_layer() 
Example 27
Project: ascii-art-py   Author: blinglnav   File: site.py    (license) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    builtins.copyright = _Printer("copyright", sys.copyright)
    if _is_jython:
        builtins.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    elif _is_pypy:
        builtins.credits = _Printer(
            "credits",
            "PyPy is maintained by the PyPy developers: http://pypy.org/")
    else:
        builtins.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    builtins.license = _Printer(
        "license", "See http://www.python.org/%.3s/license.html" % sys.version,
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 28
Project: Scrum   Author: prakharchoudhary   File: site.py    (license) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    builtins.copyright = _Printer("copyright", sys.copyright)
    if _is_jython:
        builtins.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    elif _is_pypy:
        builtins.credits = _Printer(
            "credits",
            "PyPy is maintained by the PyPy developers: http://pypy.org/")
    else:
        builtins.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    builtins.license = _Printer(
        "license", "See http://www.python.org/%.3s/license.html" % sys.version,
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 29
Project: radar   Author: amoose136   File: gnu.py    (license) View Source Project 6 votes vote down vote up
def get_library_dirs(self):
        opt = []
        if sys.platform[:5] != 'linux':
            d = self.get_libgcc_dir()
            if d:
                # if windows and not cygwin, libg2c lies in a different folder
                if sys.platform == 'win32' and not d.startswith('/usr/lib'):
                    d = os.path.normpath(d)
                    path = os.path.join(d, "lib%s.a" % self.g2c)
                    if not os.path.exists(path):
                        root = os.path.join(d, *((os.pardir,)*4))
                        d2 = os.path.abspath(os.path.join(root, 'lib'))
                        path = os.path.join(d2, "lib%s.a" % self.g2c)
                        if os.path.exists(path):
                            opt.append(d2)
                opt.append(d)
        return opt 
Example 30
Project: cert-tools   Author: blockchain-certificates   File: create_issuer.py    (license) View Source Project 6 votes vote down vote up
def get_config():
    base_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
    p = configargparse.getArgumentParser(default_config_files=[os.path.join(base_dir, 'conf.ini')]) 
    p.add('-c', '--my-config', required=True, is_config_file=True, help='config file path')
    p.add_argument('-k', '--issuer_address', type=str, required=True, help='the issuer\'s Bitcoin address that will be used to issue the certificates')
    p.add_argument('-r', '--revocation_address', type=str, required=True, help='the issuer\'s Bitcoin revocation address that can be used to revocate the certificates')
    p.add_argument('-d', '--issuer_id', type=str, required=True, help='the issuer\'s publicly accessible identification file; i.e. URL of the file generated by this tool')

    p.add_argument('-u', '--issuer_url', type=str, help='the issuers main URL address')
    p.add_argument('-l', '--issuer_certs_url', type=str, help='the issuer\'s URL address of the certificates')
    p.add_argument('-n', '--issuer_name', type=str, help='the issuer\'s name')
    p.add_argument('-e', '--issuer_email', type=str, help='the issuer\'s email')
    p.add_argument('-m', '--issuer_logo_file', type=str, help='the issuer\' logo image')
    p.add_argument('-o', '--output_file', type=str, help='the output file to save the issuer\'s identification file')
    args, _ = p.parse_known_args()

    return args 
Example 31
Project: cert-tools   Author: blockchain-certificates   File: create_revocation_addresses.py    (license) View Source Project 6 votes vote down vote up
def get_config():
    base_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
    p = configargparse.getArgumentParser(default_config_files=[os.path.join(base_dir, 'conf.ini')])
    p.add('-c', '--my-config', required=False, is_config_file=True, help='config file path')
    p.add_argument('-k', '--extended_public_key', type=str, required=True,
                   help='the HD extended public key used to generate the revocation addresses')
    p.add_argument('-p', '--key_path', type=str,
                   help='the key path used to derive the child key under which the addresses will be generated')
    p.add_argument('-n', '--number_of_addresses', type=int, default=10,
                   help='the number of revocation addresses to generate')
    p.add_argument('-o', '--output_file', type=str, help='the output file to save the revocation addresses')
    p.add_argument('-u', '--use_uncompressed', action='store_true', default=False,
                   help='whether to use uncompressed bitcoin addresses')
    args, _ = p.parse_known_args()

    return args 
Example 32
Project: Texty   Author: sarthfrey   File: __init__.py    (license) View Source Project 6 votes vote down vote up
def open_resource(name):
    """Open a resource from the zoneinfo subdir for reading.

    Uses the pkg_resources module if available and no standard file
    found at the calculated location.
    """
    name_parts = name.lstrip('/').split('/')
    for part in name_parts:
        if part == os.path.pardir or os.path.sep in part:
            raise ValueError('Bad path segment: %r' % part)
    filename = os.path.join(os.path.dirname(__file__),
                            'zoneinfo', *name_parts)
    if not os.path.exists(filename) and resource_stream is not None:
        # http://bugs.launchpad.net/bugs/383171 - we avoid using this
        # unless absolutely necessary to help when a broken version of
        # pkg_resources is installed.
        return resource_stream(__name__, 'zoneinfo/' + name)
    return open(filename, 'rb') 
Example 33
Project: deckhand   Author: att-comdev   File: test_api_initialization.py    (license) View Source Project 6 votes vote down vote up
def setUp(self):
        super(TestApi, self).setUp()
        # Mock the API resources.
        for resource in (buckets, health, revision_diffing, revision_documents,
                         revision_tags, revisions, rollback, validations,
                         versions):
            class_names = self._get_module_class_names(resource)
            for class_name in class_names:
                resource_obj = self.patchobject(
                    resource, class_name, autospec=True)
                setattr(self, utils.to_snake_case(class_name), resource_obj)

        # Mock the location of the configuration files for API initialization.
        curr_path = os.path.dirname(os.path.realpath(__file__))
        repo_path = os.path.join(
            curr_path, os.pardir, os.pardir, os.pardir, os.pardir)
        temp_config_files = [
            os.path.join(repo_path, 'etc', 'deckhand', 'deckhand.conf.sample'),
            os.path.join(repo_path, 'etc', 'deckhand', 'deckhand-paste.ini')
        ]
        mock_get_config_files = self.patchobject(
            api, '_get_config_files', autospec=True)
        mock_get_config_files.return_value = temp_config_files 
Example 34
Project: ivaochdoc   Author: ivaoch   File: site.py    (license) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    builtins.copyright = _Printer("copyright", sys.copyright)
    if _is_jython:
        builtins.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    elif _is_pypy:
        builtins.credits = _Printer(
            "credits",
            "PyPy is maintained by the PyPy developers: http://pypy.org/")
    else:
        builtins.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    builtins.license = _Printer(
        "license", "See http://www.python.org/%.3s/license.html" % sys.version,
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 35
Project: bpy_lambda   Author: bcongdon   File: addon_updater.py    (license) View Source Project 6 votes vote down vote up
def create_backup(self):
		if self._verbose:print("Backing up current addon folder")
		local = os.path.join(self._updater_path,"backup")
		tempdest = os.path.join(self._addon_root,
						os.pardir,
						self._addon+"_updater_backup_temp")

		if os.path.isdir(local) == True:
			shutil.rmtree(local)
		if self._verbose:print("Backup destination path: ",local)

		# make the copy
		shutil.copytree(self._addon_root,tempdest)
		shutil.move(tempdest,local)

		# save the date for future ref
		now = datetime.now()
		self._json["backup_date"] = "{m}-{d}-{yr}".format(
				m=now.strftime("%B"),d=now.day,yr=now.year)
		self.save_updater_json() 
Example 36
Project: bpy_lambda   Author: bcongdon   File: addon_updater.py    (license) View Source Project 6 votes vote down vote up
def restore_backup(self):
		if self._verbose:print("Restoring backup")

		if self._verbose:print("Backing up current addon folder")
		backuploc = os.path.join(self._updater_path,"backup")
		tempdest = os.path.join(self._addon_root,
						os.pardir,
						self._addon+"_updater_backup_temp")
		tempdest = os.path.abspath(tempdest)

		# make the copy
		shutil.move(backuploc,tempdest)
		shutil.rmtree(self._addon_root)
		os.rename(tempdest,self._addon_root)

		self._json["backup_date"] = ""
		self._json["just_restored"] = True
		self._json["just_updated"] = True
		self.save_updater_json() 

		self.reload_addon() 
Example 37
Project: true_review   Author: lucadealfaro   File: __init__.py    (license) View Source Project 6 votes vote down vote up
def open_resource(self, name):
        """Open a resource from the zoneinfo subdir for reading.

        Uses the pkg_resources module if available and no standard file
        found at the calculated location.
        """
        name_parts = name.lstrip('/').split('/')
        for part in name_parts:
            if part == os.path.pardir or os.path.sep in part:
                raise ValueError('Bad path segment: %r' % part)
        filename = os.path.join(os.path.dirname(__file__),
                                'zoneinfo', *name_parts)
        if not os.path.exists(filename) and resource_stream is not None:
            # http://bugs.launchpad.net/bugs/383171 - we avoid using this
            # unless absolutely necessary to help when a broken version of
            # pkg_resources is installed.
            return resource_stream(__name__, 'zoneinfo/' + name)
        return open(filename, 'rb') 
Example 38
Project: django   Author: alexsukhrin   File: site.py    (license) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    builtins.copyright = _Printer("copyright", sys.copyright)
    if _is_jython:
        builtins.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    elif _is_pypy:
        builtins.credits = _Printer(
            "credits",
            "PyPy is maintained by the PyPy developers: http://pypy.org/")
    else:
        builtins.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    builtins.license = _Printer(
        "license", "See http://www.python.org/%.3s/license.html" % sys.version,
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 39
Project: RPoint   Author: george17-meet   File: site.py    (license) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    builtins.copyright = _Printer("copyright", sys.copyright)
    if _is_jython:
        builtins.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    elif _is_pypy:
        builtins.credits = _Printer(
            "credits",
            "PyPy is maintained by the PyPy developers: http://pypy.org/")
    else:
        builtins.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    builtins.license = _Printer(
        "license", "See http://www.python.org/%.3s/license.html" % sys.version,
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 40
Project: kaleidoscope   Author: blenderskool   File: addon_updater.py    (license) View Source Project 6 votes vote down vote up
def create_backup(self):
		if self._verbose:print("Backing up current addon folder")
		local = os.path.join(self._updater_path,"backup")
		tempdest = os.path.join(self._addon_root,
						os.pardir,
						self._addon+"_updater_backup_temp")

		if os.path.isdir(local) == True:
			shutil.rmtree(local)
		if self._verbose:print("Backup destination path: ",local)

		# make the copy
		shutil.copytree(self._addon_root,tempdest)
		shutil.move(tempdest,local)

		# save the date for future ref
		now = datetime.now()
		self._json["backup_date"] = "{m}-{d}-{yr}".format(
				m=now.strftime("%B"),d=now.day,yr=now.year)
		self.save_updater_json() 
Example 41
Project: kaleidoscope   Author: blenderskool   File: addon_updater.py    (license) View Source Project 6 votes vote down vote up
def restore_backup(self):
		if self._verbose:print("Restoring backup")

		if self._verbose:print("Backing up current addon folder")
		backuploc = os.path.join(self._updater_path,"backup")
		tempdest = os.path.join(self._addon_root,
						os.pardir,
						self._addon+"_updater_backup_temp")
		tempdest = os.path.abspath(tempdest)

		# make the copy
		shutil.move(backuploc,tempdest)
		shutil.rmtree(self._addon_root)
		os.rename(tempdest,self._addon_root)

		self._json["backup_date"] = ""
		self._json["just_restored"] = True
		self._json["just_updated"] = True
		self.save_updater_json() 

		self.reload_addon() 
Example 42
Project: isni-reconcile   Author: cmh2166   File: site.py    (license) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    builtins.copyright = _Printer("copyright", sys.copyright)
    if _is_jython:
        builtins.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    elif _is_pypy:
        builtins.credits = _Printer(
            "credits",
            "PyPy is maintained by the PyPy developers: http://pypy.org/")
    else:
        builtins.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    builtins.license = _Printer(
        "license", "See http://www.python.org/%.3s/license.html" % sys.version,
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 43
Project: habilitacion   Author: GabrielBD   File: site.py    (license) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    builtins.copyright = _Printer("copyright", sys.copyright)
    if _is_jython:
        builtins.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    elif _is_pypy:
        builtins.credits = _Printer(
            "credits",
            "PyPy is maintained by the PyPy developers: http://pypy.org/")
    else:
        builtins.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    builtins.license = _Printer(
        "license", "See http://www.python.org/%.3s/license.html" % sys.version,
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 44
Project: Intranet-Penetration   Author: yuxiaokui   File: site.py    (license) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    __builtin__.copyright = _Printer("copyright", sys.copyright)
    if sys.platform[:4] == 'java':
        __builtin__.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    else:
        __builtin__.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    __builtin__.license = _Printer(
        "license", "See https://www.python.org/psf/license/",
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 45
Project: Intranet-Penetration   Author: yuxiaokui   File: SimpleHTTPServer.py    (license) View Source Project 6 votes vote down vote up
def translate_path(self, path):
        """Translate a /-separated PATH to the local filename syntax.

        Components that mean special things to the local file system
        (e.g. drive or directory names) are ignored.  (XXX They should
        probably be diagnosed.)

        """
        # abandon query parameters
        path = path.split('?',1)[0]
        path = path.split('#',1)[0]
        # Don't forget explicit trailing slash when normalizing. Issue17324
        trailing_slash = path.rstrip().endswith('/')
        path = posixpath.normpath(urllib.unquote(path))
        words = path.split('/')
        words = filter(None, words)
        path = os.getcwd()
        for word in words:
            drive, word = os.path.splitdrive(word)
            head, word = os.path.split(word)
            if word in (os.curdir, os.pardir): continue
            path = os.path.join(path, word)
        if trailing_slash:
            path += '/'
        return path 
Example 46
Project: flasky   Author: RoseOu   File: site.py    (license) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    builtins.copyright = _Printer("copyright", sys.copyright)
    if _is_jython:
        builtins.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    elif _is_pypy:
        builtins.credits = _Printer(
            "credits",
            "PyPy is maintained by the PyPy developers: http://pypy.org/")
    else:
        builtins.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    builtins.license = _Printer(
        "license", "See http://www.python.org/%.3s/license.html" % sys.version,
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 47
Project: MKFQ   Author: maojingios   File: site.py    (license) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    __builtin__.copyright = _Printer("copyright", sys.copyright)
    if sys.platform[:4] == 'java':
        __builtin__.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    else:
        __builtin__.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    __builtin__.license = _Printer(
        "license", "See https://www.python.org/psf/license/",
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir]) 
Example 48
Project: MKFQ   Author: maojingios   File: SimpleHTTPServer.py    (license) View Source Project 6 votes vote down vote up
def translate_path(self, path):
        """Translate a /-separated PATH to the local filename syntax.

        Components that mean special things to the local file system
        (e.g. drive or directory names) are ignored.  (XXX They should
        probably be diagnosed.)

        """
        # abandon query parameters
        path = path.split('?',1)[0]
        path = path.split('#',1)[0]
        # Don't forget explicit trailing slash when normalizing. Issue17324
        trailing_slash = path.rstrip().endswith('/')
        path = posixpath.normpath(urllib.unquote(path))
        words = path.split('/')
        words = filter(None, words)
        path = os.getcwd()
        for word in words:
            drive, word = os.path.splitdrive(word)
            head, word = os.path.split(word)
            if word in (os.curdir, os.pardir): continue
            path = os.path.join(path, word)
        if trailing_slash:
            path += '/'
        return path 
Example 49
Project: hakkuframework   Author: 4shadoww   File: server.py    (license) View Source Project 6 votes vote down vote up
def translate_path(self, path):
        """Translate a /-separated PATH to the local filename syntax.

        Components that mean special things to the local file system
        (e.g. drive or directory names) are ignored.  (XXX They should
        probably be diagnosed.)

        """
        # abandon query parameters
        path = path.split('?',1)[0]
        path = path.split('#',1)[0]
        path = posixpath.normpath(urllib_parse.unquote(path))
        words = path.split('/')
        words = filter(None, words)
        path = os.getcwd()
        for word in words:
            drive, word = os.path.splitdrive(word)
            head, word = os.path.split(word)
            if word in (os.curdir, os.pardir): continue
            path = os.path.join(path, word)
        return path 
Example 50
Project: flickr_downloader   Author: Denisolt   File: site.py    (license) View Source Project 6 votes vote down vote up
def setcopyright():
    """Set 'copyright' and 'credits' in __builtin__"""
    builtins.copyright = _Printer("copyright", sys.copyright)
    if _is_jython:
        builtins.credits = _Printer(
            "credits",
            "Jython is maintained by the Jython developers (www.jython.org).")
    elif _is_pypy:
        builtins.credits = _Printer(
            "credits",
            "PyPy is maintained by the PyPy developers: http://pypy.org/")
    else:
        builtins.credits = _Printer("credits", """\
    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.""")
    here = os.path.dirname(os.__file__)
    builtins.license = _Printer(
        "license", "See http://www.python.org/%.3s/license.html" % sys.version,
        ["LICENSE.txt", "LICENSE"],
        [os.path.join(here, os.pardir), here, os.curdir])