File: uri.py

package info (click to toggle)
gsettings-desktop-schemas 3.22.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,836 kB
  • ctags: 214
  • sloc: sh: 728; python: 200; ansic: 170; makefile: 103
file content (30 lines) | stat: -rw-r--r-- 699 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/python
#
# Simple utility script to get URI from a given path
#
# Author: Fan, Chun-wei
# Date: September 03, 2014

import os
import sys
import string

def get_abs_path(path):
    return os.path.abspath(path)

def get_abs_path_posix(path):
    path_mid = get_abs_path(path)
    return path_mid.replace('\\','/')

def get_uri_from_path(path):
    return '/' + get_abs_path_posix(path)

def main(argv):
    if len(argv) != 2:
        raise SystemExit('Error: Usage: python %s <path>' % __file__)
    if not os.path.exists(argv[1]):
        raise SystemExit('Error: Entered path does not exist')
    print(get_uri_from_path(argv[1]))

if __name__ == '__main__':
    sys.exit(main(sys.argv))