script.module.libtorrent/python_libtorrent/public.py

71 lines
2.8 KiB
Python
Raw Normal View History

2015-07-11 12:00:55 +03:00
#-*- coding: utf-8 -*-
'''
Torrenter v2 plugin for XBMC/Kodi
Copyright (C) 2015 srg70, RussakHH, DiMartino
'''
import os
2015-07-11 23:49:53 +03:00
#UPDATE IT FROM functions
2015-07-11 12:00:55 +03:00
def get_libname(platform):
libname=[]
2015-07-11 23:49:53 +03:00
if platform['system'] in ['darwin', 'linux_x86', 'linux_x86_64']:
2015-07-11 12:00:55 +03:00
libname=['libtorrent.so']
elif platform['system'] == 'windows':
libname=['libtorrent.pyd']
2015-07-11 23:49:53 +03:00
elif platform['system'] == 'android_armv7':
2015-07-11 12:00:55 +03:00
libname=['libtorrent.so', 'liblibtorrent.so']
return libname
class Public:
def __init__( self ):
self.platforms=[{'system':'darwin'},
{'system':'linux_x86'},
{'system':'linux_x86_64'},
{'system':'windows'},
2015-07-11 23:49:53 +03:00
{'system':'android_armv7'}]
2015-07-11 12:00:55 +03:00
self.root=os.path.dirname(__file__)
self._generate_size_file()
def _generate_size_file( self ):
for platform in self.platforms:
for libname in get_libname(platform):
self.libname=libname
self.platform=platform
self.libdir = os.path.join(self.root, self.platform['system'])
self.libpath = os.path.join(self.libdir, self.libname)
self.sizepath=self.libpath+'.size.txt'
self.zipname=self.libname+'.zip'
self.zippath=os.path.join(self.libdir, self.zipname)
if os.path.exists(self.libpath):
if not os.path.exists(self.sizepath):
print platform['system']+'/'+self.libname+' NO SIZE'
self._makezip()
elif not os.path.exists(self.zippath):
print platform['system']+'/'+self.libname+' NO ZIP'
self._makezip()
else:
size=str(os.path.getsize(self.libpath))
size_old=open( self.sizepath, "r" ).read()
if size_old!=size:
print platform['system']+'/'+self.libname+' NOT EQUAL'
self._makezip()
else:
print platform['system']+'/'+self.libname+' NO ACTION'
else:
print platform['system']+'/'+self.libname+' NO LIB'
def _makezip(self):
open( self.sizepath, "w" ).write( str(os.path.getsize(self.libpath)) )
os.chdir(self.libdir)
os.system('del %s' % (self.zipname))
os.system('"C:\\Program Files\\7-Zip\\7z.exe" a %s.zip %s' %
(self.libname, self.libname))
os.chdir(self.root)
#os.system('"C:\\Program Files\\7-Zip\\7z.exe" a %s.zip %s' %
# (self.platform['system']+os.sep+self.libname, self.platform['system']+os.sep+self.libname))
if ( __name__ == "__main__" ):
# start
2015-07-11 23:49:53 +03:00
#TODO: publicate
2015-07-11 12:00:55 +03:00
Public()