File: loc_compat.py

package info (click to toggle)
python-keyring 0.7.1-1%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 428 kB
  • sloc: python: 1,563; makefile: 29
file content (30 lines) | stat: -rw-r--r-- 999 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
import shutil
import stat
import sys

def relocate_file(old_location, new_location):
    """
    keyring 0.8 changes the default location for storage of
    file-based keyring locations. This function is invoked to move
    files stored in the old location to the new location.

    TODO: remove this function for keyring 1.0.
    """
    if not os.path.exists(old_location):
        # nothing to do; no legacy file found
        return

    if os.path.exists(new_location):
        print >> sys.stderr, ("Password file found in legacy "
            "location\n  %(old_location)s\nand new location\n"
            "  %(new_location)s\nOld location will be ignored."
            % vars())
        return

    # ensure the storage path exists
    if not os.path.isdir(os.path.dirname(new_location)):
        os.makedirs(os.path.dirname(new_location))
    os.chmod(os.path.dirname(new_location),
        stat.S_IWRITE | stat.S_IREAD | stat.S_IEXEC)
    shutil.move(old_location, new_location)