Completed
Pull Request — master (#127)
by Jasper
01:07
created

Location.toDictionary()   A

Complexity

Conditions 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 6
rs 9.4285
1
import socket
2
3
4
class Location(object):
5
    """Represents the location of a file."""
6
7
    def __init__(self, locationString):
8
        if ':' in locationString:
9
            parts = locationString.split(':')
10
            self.hostname = parts[0]
11
            self.path = parts[1]
12
        else:
13
            self.hostname = socket.gethostname()
14
            self.path = locationString
15
16
    def toDictionary(self):
17
        d = {}
18
        d['path'] = self.path
19
        d['hostname'] = self.hostname
20
        d['location'] = str(self)
21
        return d
22
23
    def toUrl(self):
24
        return 'file://{0}{1}'.format(self.hostname, self.path)
25
26
    def __str__(self):
27
        return self.toString()
28
29
    def toString(self):
30
        return ':'.join([self.hostname, self.path])
31