| Total Complexity | 6 |
| Total Lines | 27 |
| Duplicated Lines | 0 % |
| 1 | import socket |
||
| 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 |