You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
3.8 KiB

from couchpotato.core.logger import CPLog
14 years ago
import hashlib
import os.path
import platform
import random
14 years ago
import re
import string
FreeBSD init commit 0bd182ebb5d9da183d7d3950c77418cf02dd8706 Merge: 5fac3d7 dadbd0f Author: Ruud <ruud@crashdummy.nl> Date: Thu May 31 20:21:17 2012 +0200 Merge branch 'master' of https://github.com/jallakim/CouchPotatoServer into jallakim-master Conflicts: init/freebsd commit 5fac3d708d2af21e5834aea9bb7224139beb75f0 Merge: 0ba2e57 95e5282 Author: Ruud <ruud@crashdummy.nl> Date: Thu May 31 19:30:18 2012 +0200 Merge branch 'refs/heads/develop' commit dadbd0f1fd61fe6c8a233b823bbf4ed29a9032f0 Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 22:35:27 2012 +0200 Useless Use of Cat Award (-: commit 9fe11355a9671a1f38a6b982b50034f075c34b8d Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 22:30:26 2012 +0200 Ooops. PORT and CPAPI got mixed around in FreeBSD init-script. commit e39be8970ca0a4365ff15e6d8b3d64864c2bbdc4 Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 22:25:46 2012 +0200 Cosmetics again. commit 5cca98db31caaf6ca7032a3d948c4feb6ca30e2e Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 22:22:54 2012 +0200 Check that settings.conf exists in FreeBSD init-script commit d1e98602d8d86200431ff1d109d89853fb6ea243 Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 22:16:47 2012 +0200 FreeBSD init-script fetches variables from CP's settings.conf commit 42dbe607cfeca13efc76e6db7c5df4907bf7fc80 Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 16:02:46 2012 +0200 Should work for all FreeBSD versions now. commit f0bcf6a0f5c401a1f96f98ef35b82c3e45f05e11 Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 15:17:53 2012 +0200 Don't 'import sys' before we need it commit 8e13fcd0d137e304b5c49aaec4397ca58c2ef431 Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 15:09:58 2012 +0200 Cosmetics! (-: commit 04af454c0362dcabb1cec06863f1defabf7a3736 Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 15:05:32 2012 +0200 Added /data/ to .gitignore Used as data-dir if CouchPotato is installed on FreeBSD. commit 055d47d7b4a9401fcab1e4cdb319c3e95a91e1ca Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 15:04:36 2012 +0200 Fixed getDataDir so that it works for FreeBSD9. Assumes that '/usr/local/couchpotato/' is where CouchPotato resides. commit 4859f1b9f23e1d994e7fca24e25bae0226717006 Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 15:03:26 2012 +0200 Fixed the FreeBSD init-script. commit 0ba2e579f9658dfbf7ab65245bee9a04d1c09473 Merge: fdf0d2d a2a3896 Author: Ruud <ruud@crashdummy.nl> Date: Sun May 20 23:50:54 2012 +0200 Merge branch 'master' of github.com:RuudBurger/CouchPotatoServer commit fdf0d2d5b403bad860a06475b1dafce7c28e2da5 Author: Ruud Burger <ruud@crashdummy.nl> Date: Thu Apr 26 10:57:34 2012 +0300 Use master branch to update master.. commit a2a3896b1fe16bdc4d7d32af330a123645e93dba Merge: 5017b01 19640a9 Author: Ruud <ruud@crashdummy.nl> Date: Sun May 20 19:57:05 2012 +0200 Merge branch 'refs/heads/develop' commit 5017b019344b19a2e7dafe7c3114d01306166722 Merge: d4a5483 f2f524c Author: Ruud <ruud@crashdummy.nl> Date: Tue May 15 23:23:25 2012 +0200 Merge branch 'master' of github.com:RuudBurger/CouchPotatoServer commit d4a5483fa034d960bb7160a076ee11507e3bdc78 Author: Ruud Burger <ruud@crashdummy.nl> Date: Thu Apr 26 10:57:34 2012 +0300 Use master branch to update master.. commit f2f524c4e446814448a4a1a3c8e385b8beb1e5c6 Merge: 577aed3 edbeb02 Author: Ruud <ruud@crashdummy.nl> Date: Tue May 15 23:16:12 2012 +0200 Merge branch 'refs/heads/develop' commit 577aed3a754ae783c3224bbc8e051164f981309f Merge: cb975f6 176f4b0 Author: Ruud <ruud@crashdummy.nl> Date: Mon May 14 23:36:53 2012 +0200 Merge branch 'refs/heads/develop' commit cb975f61801f83cc8b16f3785195eb23cc967aff Merge: 3e369c5 a71fb1a Author: Ruud <ruud@crashdummy.nl> Date: Mon May 14 20:23:05 2012 +0200 Merge branch 'refs/heads/develop' commit 3e369c583851d14fe5d6cd292c63a4c1e603f634 Merge: d89130d 0847ffd Author: Ruud <ruud@crashdummy.nl> Date: Sun May 13 12:56:37 2012 +0200 Merge branch 'refs/heads/develop' commit d89130dc308a1017b6d9bb0038d0d615a333ad8f Merge: ee5e1d1 c34f392 Author: Ruud <ruud@crashdummy.nl> Date: Sat May 12 00:36:03 2012 +0200 Merge branch 'refs/heads/develop' commit ee5e1d19d1e19f7ad4b3cc33e8642f606b3f4043 Merge: 7d2eb23 b2be9ef Author: Ruud <ruud@crashdummy.nl> Date: Wed May 9 22:19:29 2012 +0200 Merge branch 'refs/heads/develop' commit 7d2eb2376f55cec38b1fd581b1df74e97d6e75f6 Merge: 40ff984 ba8fef3 Author: Ruud Burger <ruud@crashdummy.nl> Date: Mon May 7 13:35:13 2012 -0700 Merge pull request #228 from sirchia/twitterDirectMessage Added support for direct messages in twitter notifications commit 40ff984e192a4d7d7dcf177d009960073ea49346 Merge: 1f3e22c 7ca509c Author: Ruud <ruud@crashdummy.nl> Date: Mon May 7 22:26:55 2012 +0200 Merge branch 'refs/heads/develop' commit ba8fef3c87484e4898a196ef9b25c69be68f9825 Author: Riccardo Sirchia <sirchia.r@gmail.com> Date: Sun May 6 18:02:51 2012 +0200 Added support for direct messages in twitter notifications commit 1f3e22c4ed4e36c809045beae404cdc0a941fda9 Merge: 89315cb 74226f0 Author: Ruud <ruud@crashdummy.nl> Date: Fri May 4 17:27:36 2012 +0200 Merge branch 'refs/heads/develop' commit 89315cb2912bcdf4d8ac4f375a562f7d8966acd5 Merge: 829b3cf f6de117 Author: Ruud <ruud@crashdummy.nl> Date: Fri May 4 17:27:12 2012 +0200 Merge branch 'refs/heads/develop' commit 829b3cfb3bd7d9a8d4b6d4ac09231b4c735fc1d1 Merge: e3cc15d 1345e98 Author: Ruud <ruud@crashdummy.nl> Date: Wed May 2 21:40:01 2012 +0200 Merge branch 'refs/heads/develop' commit e3cc15d2b638ed88404f3f1902361249fb306245 Merge: ca87f2c c161bdd Author: Ruud <ruud@crashdummy.nl> Date: Sun Apr 29 00:00:14 2012 +0200 Merge branch 'refs/heads/develop' commit ca87f2c231eb5095efba749c39a221e274c238fb Merge: e929af7 c7bc0f4 Author: Ruud <ruud@crashdummy.nl> Date: Sat Apr 28 23:14:18 2012 +0200 Merge branch 'refs/heads/develop' commit e929af76d056af7210d09e807ce8a17305003407 Merge: b22763b d1c2869 Author: Ruud Burger <ruud@crashdummy.nl> Date: Fri Apr 27 02:04:35 2012 -0700 Merge pull request #152 from garlandkr/master Removed group setting for init commit d1c2869f2cb4b3fac555cce732e92bb8fec97363 Author: Ken Garland <garlandkr@gmail.com> Date: Thu Apr 26 23:30:33 2012 -0300 Removed RUN_AS for group, don't assume the default group is the same as the username. Specifying group is not needed anyways. commit b22763b37d7780140698725a0ed2632e2eb7a7c2 Author: Ruud Burger <ruud@crashdummy.nl> Date: Thu Apr 26 10:57:34 2012 +0300 Use master branch to update master..
13 years ago
import sys
14 years ago
log = CPLog(__name__)
def getUserDir():
try:
import pwd
os.environ['HOME'] = pwd.getpwuid(os.geteuid()).pw_dir
except:
pass
return os.path.expanduser('~')
def getDownloadDir():
user_dir = getUserDir()
# OSX
if 'darwin' in platform.platform().lower():
return os.path.join(user_dir, 'Downloads')
if os.name == 'nt':
return os.path.join(user_dir, 'Downloads')
return user_dir
def getDataDir():
# Windows
if os.name == 'nt':
return os.path.join(os.environ['APPDATA'], 'CouchPotato')
user_dir = getUserDir()
# OSX
if 'darwin' in platform.platform().lower():
return os.path.join(user_dir, 'Library', 'Application Support', 'CouchPotato')
FreeBSD init commit 0bd182ebb5d9da183d7d3950c77418cf02dd8706 Merge: 5fac3d7 dadbd0f Author: Ruud <ruud@crashdummy.nl> Date: Thu May 31 20:21:17 2012 +0200 Merge branch 'master' of https://github.com/jallakim/CouchPotatoServer into jallakim-master Conflicts: init/freebsd commit 5fac3d708d2af21e5834aea9bb7224139beb75f0 Merge: 0ba2e57 95e5282 Author: Ruud <ruud@crashdummy.nl> Date: Thu May 31 19:30:18 2012 +0200 Merge branch 'refs/heads/develop' commit dadbd0f1fd61fe6c8a233b823bbf4ed29a9032f0 Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 22:35:27 2012 +0200 Useless Use of Cat Award (-: commit 9fe11355a9671a1f38a6b982b50034f075c34b8d Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 22:30:26 2012 +0200 Ooops. PORT and CPAPI got mixed around in FreeBSD init-script. commit e39be8970ca0a4365ff15e6d8b3d64864c2bbdc4 Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 22:25:46 2012 +0200 Cosmetics again. commit 5cca98db31caaf6ca7032a3d948c4feb6ca30e2e Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 22:22:54 2012 +0200 Check that settings.conf exists in FreeBSD init-script commit d1e98602d8d86200431ff1d109d89853fb6ea243 Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 22:16:47 2012 +0200 FreeBSD init-script fetches variables from CP's settings.conf commit 42dbe607cfeca13efc76e6db7c5df4907bf7fc80 Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 16:02:46 2012 +0200 Should work for all FreeBSD versions now. commit f0bcf6a0f5c401a1f96f98ef35b82c3e45f05e11 Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 15:17:53 2012 +0200 Don't 'import sys' before we need it commit 8e13fcd0d137e304b5c49aaec4397ca58c2ef431 Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 15:09:58 2012 +0200 Cosmetics! (-: commit 04af454c0362dcabb1cec06863f1defabf7a3736 Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 15:05:32 2012 +0200 Added /data/ to .gitignore Used as data-dir if CouchPotato is installed on FreeBSD. commit 055d47d7b4a9401fcab1e4cdb319c3e95a91e1ca Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 15:04:36 2012 +0200 Fixed getDataDir so that it works for FreeBSD9. Assumes that '/usr/local/couchpotato/' is where CouchPotato resides. commit 4859f1b9f23e1d994e7fca24e25bae0226717006 Author: Joachim Tingvold <joachim@tingvold.com> Date: Wed May 30 15:03:26 2012 +0200 Fixed the FreeBSD init-script. commit 0ba2e579f9658dfbf7ab65245bee9a04d1c09473 Merge: fdf0d2d a2a3896 Author: Ruud <ruud@crashdummy.nl> Date: Sun May 20 23:50:54 2012 +0200 Merge branch 'master' of github.com:RuudBurger/CouchPotatoServer commit fdf0d2d5b403bad860a06475b1dafce7c28e2da5 Author: Ruud Burger <ruud@crashdummy.nl> Date: Thu Apr 26 10:57:34 2012 +0300 Use master branch to update master.. commit a2a3896b1fe16bdc4d7d32af330a123645e93dba Merge: 5017b01 19640a9 Author: Ruud <ruud@crashdummy.nl> Date: Sun May 20 19:57:05 2012 +0200 Merge branch 'refs/heads/develop' commit 5017b019344b19a2e7dafe7c3114d01306166722 Merge: d4a5483 f2f524c Author: Ruud <ruud@crashdummy.nl> Date: Tue May 15 23:23:25 2012 +0200 Merge branch 'master' of github.com:RuudBurger/CouchPotatoServer commit d4a5483fa034d960bb7160a076ee11507e3bdc78 Author: Ruud Burger <ruud@crashdummy.nl> Date: Thu Apr 26 10:57:34 2012 +0300 Use master branch to update master.. commit f2f524c4e446814448a4a1a3c8e385b8beb1e5c6 Merge: 577aed3 edbeb02 Author: Ruud <ruud@crashdummy.nl> Date: Tue May 15 23:16:12 2012 +0200 Merge branch 'refs/heads/develop' commit 577aed3a754ae783c3224bbc8e051164f981309f Merge: cb975f6 176f4b0 Author: Ruud <ruud@crashdummy.nl> Date: Mon May 14 23:36:53 2012 +0200 Merge branch 'refs/heads/develop' commit cb975f61801f83cc8b16f3785195eb23cc967aff Merge: 3e369c5 a71fb1a Author: Ruud <ruud@crashdummy.nl> Date: Mon May 14 20:23:05 2012 +0200 Merge branch 'refs/heads/develop' commit 3e369c583851d14fe5d6cd292c63a4c1e603f634 Merge: d89130d 0847ffd Author: Ruud <ruud@crashdummy.nl> Date: Sun May 13 12:56:37 2012 +0200 Merge branch 'refs/heads/develop' commit d89130dc308a1017b6d9bb0038d0d615a333ad8f Merge: ee5e1d1 c34f392 Author: Ruud <ruud@crashdummy.nl> Date: Sat May 12 00:36:03 2012 +0200 Merge branch 'refs/heads/develop' commit ee5e1d19d1e19f7ad4b3cc33e8642f606b3f4043 Merge: 7d2eb23 b2be9ef Author: Ruud <ruud@crashdummy.nl> Date: Wed May 9 22:19:29 2012 +0200 Merge branch 'refs/heads/develop' commit 7d2eb2376f55cec38b1fd581b1df74e97d6e75f6 Merge: 40ff984 ba8fef3 Author: Ruud Burger <ruud@crashdummy.nl> Date: Mon May 7 13:35:13 2012 -0700 Merge pull request #228 from sirchia/twitterDirectMessage Added support for direct messages in twitter notifications commit 40ff984e192a4d7d7dcf177d009960073ea49346 Merge: 1f3e22c 7ca509c Author: Ruud <ruud@crashdummy.nl> Date: Mon May 7 22:26:55 2012 +0200 Merge branch 'refs/heads/develop' commit ba8fef3c87484e4898a196ef9b25c69be68f9825 Author: Riccardo Sirchia <sirchia.r@gmail.com> Date: Sun May 6 18:02:51 2012 +0200 Added support for direct messages in twitter notifications commit 1f3e22c4ed4e36c809045beae404cdc0a941fda9 Merge: 89315cb 74226f0 Author: Ruud <ruud@crashdummy.nl> Date: Fri May 4 17:27:36 2012 +0200 Merge branch 'refs/heads/develop' commit 89315cb2912bcdf4d8ac4f375a562f7d8966acd5 Merge: 829b3cf f6de117 Author: Ruud <ruud@crashdummy.nl> Date: Fri May 4 17:27:12 2012 +0200 Merge branch 'refs/heads/develop' commit 829b3cfb3bd7d9a8d4b6d4ac09231b4c735fc1d1 Merge: e3cc15d 1345e98 Author: Ruud <ruud@crashdummy.nl> Date: Wed May 2 21:40:01 2012 +0200 Merge branch 'refs/heads/develop' commit e3cc15d2b638ed88404f3f1902361249fb306245 Merge: ca87f2c c161bdd Author: Ruud <ruud@crashdummy.nl> Date: Sun Apr 29 00:00:14 2012 +0200 Merge branch 'refs/heads/develop' commit ca87f2c231eb5095efba749c39a221e274c238fb Merge: e929af7 c7bc0f4 Author: Ruud <ruud@crashdummy.nl> Date: Sat Apr 28 23:14:18 2012 +0200 Merge branch 'refs/heads/develop' commit e929af76d056af7210d09e807ce8a17305003407 Merge: b22763b d1c2869 Author: Ruud Burger <ruud@crashdummy.nl> Date: Fri Apr 27 02:04:35 2012 -0700 Merge pull request #152 from garlandkr/master Removed group setting for init commit d1c2869f2cb4b3fac555cce732e92bb8fec97363 Author: Ken Garland <garlandkr@gmail.com> Date: Thu Apr 26 23:30:33 2012 -0300 Removed RUN_AS for group, don't assume the default group is the same as the username. Specifying group is not needed anyways. commit b22763b37d7780140698725a0ed2632e2eb7a7c2 Author: Ruud Burger <ruud@crashdummy.nl> Date: Thu Apr 26 10:57:34 2012 +0300 Use master branch to update master..
13 years ago
# FreeBSD
if 'freebsd' in sys.platform:
return os.path.join('/usr/local/', 'couchpotato', 'data')
# Linux
return os.path.join(user_dir, '.couchpotato')
def isDict(object):
14 years ago
return isinstance(object, dict)
def mergeDicts(a, b):
assert isDict(a), isDict(b)
14 years ago
dst = a.copy()
stack = [(dst, b)]
while stack:
current_dst, current_src = stack.pop()
for key in current_src:
if key not in current_dst:
current_dst[key] = current_src[key]
else:
if isDict(current_src[key]) and isDict(current_dst[key]):
14 years ago
stack.append((current_dst[key], current_src[key]))
elif isinstance(current_src[key], list) and isinstance(current_dst[key], list):
current_dst[key].extend(current_src[key])
current_dst[key] = removeListDuplicates(current_dst[key])
14 years ago
else:
current_dst[key] = current_src[key]
return dst
def removeListDuplicates(seq):
checked = []
for e in seq:
if e not in checked:
checked.append(e)
return checked
def flattenList(l):
if isinstance(l, list):
return sum(map(flattenList, l))
else:
return l
14 years ago
def md5(text):
return hashlib.md5(text).hexdigest()
def sha1(text):
return hashlib.sha1(text).hexdigest()
14 years ago
def getExt(filename):
return os.path.splitext(filename)[1][1:]
def cleanHost(host):
if not host.startswith(('http://', 'https://')):
host = 'http://' + host
if not host.endswith('/'):
host += '/'
return host
14 years ago
def getImdb(txt, check_inside = True):
if check_inside and os.path.isfile(txt):
output = open(txt, 'r')
txt = output.read()
output.close()
try:
14 years ago
id = re.findall('(tt\d{7})', txt)[0]
return id
except IndexError:
pass
return False
14 years ago
def tryInt(s):
try: return int(s)
except: return 0
14 years ago
def tryFloat(s):
try: return float(s) if '.' in s else tryInt(s)
except: return 0
14 years ago
def natsortKey(s):
return map(tryInt, re.findall(r'(\d+|\D+)', s))
def natcmp(a, b):
return cmp(natsortKey(a), natsortKey(b))
def getTitle(library_dict):
try:
try:
return library_dict['titles'][0]['title']
except:
try:
for title in library_dict.titles:
if title.default:
return title.title
except:
log.error('Could not get title for %s', library_dict.identifier)
return None
log.error('Could not get title for %s', library_dict['identifier'])
return None
except:
log.error('Could not get title for library item: %s', library_dict)
return None
def randomString(size = 8, chars = string.ascii_uppercase + string.digits):
return ''.join(random.choice(chars) for x in range(size))
def splitString(str, split_on = ','):
return [x.strip() for x in str.split(split_on)]