Completed
Push — master ( 9821e6...398a65 )
by Jasper
8s
created

Location.__ne__()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 2
rs 10
1
import socket, os.path
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
            path = parts[1]
12
        else:
13
            self.hostname = socket.gethostname()
14
            path = locationString
15
        self.path = os.path.abspath(path)
16
17
    def toDictionary(self):
18
        d = {}
19
        d['path'] = self.path
20
        d['hostname'] = self.hostname
21
        d['location'] = str(self)
22
        return d
23
24
    def toUrl(self):
25
        return 'file://{0}{1}'.format(self.hostname, self.path)
26
27
    def __str__(self):
28
        return self.toString()
29
30
    def toString(self):
31
        return ':'.join([self.hostname, self.path])
32
33
    def __eq__(self, other):
34
        if isinstance(other, self.__class__):
35
            return str(self) == str(other)
36
        else:
37
            return False
38
39
    def __ne__(self, other):
40
        return not self.__eq__(other)
41