Esempio n. 1
0
    def __init__(self, path_or_url_or_hash=None, path_module=os.path):
        self.path = None
        self.url = None
        self.short_hash = None

        s = path_or_url_or_hash
        if s:
            maybe_url = urlparse(s)

            if path_module.exists(s):
                self.path = path_module.abspath(s)
                self.short_hash = cinesync.short_hash(self.path)
            elif maybe_url and maybe_url.scheme and maybe_url.hostname:
                # The argument could be parsed as a URI (use it as a URL)
                self.url = maybe_url.geturl()
            elif re.match('^[0-9a-f]{40}$', s):
                # Length is 40 characters and consists of all hex digits; assume this is a short hash
                self.short_hash = s
            else:
                # Finally, assume it's a file path
                self.path = path_module.abspath(s)
Esempio n. 2
0
 def test_short_hash_with_small_file(self):
     hash = cinesync.short_hash(os.path.join('test', 'small.txt'))
     self.assertEqual(hash, '1e40efb84050f92618e2c430742f44254771cf6b')
Esempio n. 3
0
 def test_short_hash_with_big_file(self):
     hash = cinesync.short_hash('/Volumes/Oyama/Streams/cineSync Test Files/movies/nasa_shuttle_m420p.mov')
     self.assertEqual(hash, '08e5628d51b14278f73f36afebf0506afc2bfcf8')