Exemplo n.º 1
0
    def __init__(self, config_type = None):
        self.config_type = config_type
        if config_type:
            config_ext = '.'+config_type
        else:
            config_ext = ''

        self.policy = policy.get_policy()
        dir_root = self.policy.root_path
        self.dir_root = dir_root

        self.dir_icons = os.path.join(dir_root,'icons')
        if not os.path.isdir(self.dir_icons):
            os.mkdir(self.dir_icons)

        self.dir_torrentcache = os.path.join(dir_root,'torrentcache')
        if not os.path.isdir(self.dir_torrentcache):
            os.mkdir(self.dir_torrentcache)

        self.dir_datacache = os.path.join(dir_root,'datacache')
        if not os.path.isdir(self.dir_datacache):
            os.mkdir(self.dir_datacache)

        self.dir_piececache = os.path.join(dir_root,'piececache')
        if not os.path.isdir(self.dir_piececache):
            os.mkdir(self.dir_piececache)

        self.configfile = os.path.join(dir_root,'config'+config_ext+'.ini')
        self.statefile = os.path.join(dir_root,'state'+config_ext)

        self.TorrentDataBuffer = {}
Exemplo n.º 2
0
 def __init__(self,tracker,media):
     self.user = tracker.user
     self.passwd = tracker.password
     self.url = media.link
     self.title = media.title
     pol = policy.get_policy()
     torrent_path = pol(policy.TORRENT_PATH)
Exemplo n.º 3
0
 def __init__(self,tracker,filter):
     self.tracker = tracker
     self.url = tracker.url
     self.user = tracker.user
     self.passwd = tracker.password
     self.filter = filter
     self.log = get_logger()
     self.policy = policy.get_policy()
Exemplo n.º 4
0
 def __init__(self,file,tag='MediaList',load=1):
     self.file = policy.get_policy().get_path(file)
     if load:
         try:
             self.obj = factory.from_file(self.file)
         except IOError:
             self.obj = List(tag)
     else:
         self.obj = List(tag)
Exemplo n.º 5
0
 def __init__(self,test_mode=0):
     self.test_mode = test_mode
     self.tracker_list = XMLWrapper(cpolicy.TRACKER_FILE,
                                    tag='TrackerList')
     self.interest_list = XMLWrapper(cpolicy.INTEREST_FILE,
                                     tag='InterestList')
     self.submitted_list = XMLWrapper(cpolicy.SUBMITTED_FILE)
     pol = policy.get_policy()
     self.webreq = WebServiceRequest((pol(policy.WEBSERVICE_IP),
                                      pol(policy.WEBSERVICE_PORT)),
                                      pol(policy.WEBSERVICE_ID))
     self.ignore_wait = pol(policy.IGNORE_WAITING_MEDIA)
     self.log = get_logger()
     self.wait_list = XMLWrapper(cpolicy.WAIT_FILE,
                                 load=(self.ignore_wait==0))
     self.failed_list = XMLWrapper(cpolicy.WAIT_FILE,
                                   load=0)
Exemplo n.º 6
0
	def UploadTorrent(self, rsp, cls, uls):
	
		from BitTorrent.download import Download
		from BitTorrent.bencode import bencode, bdecode
		from sha import sha
		
		if uls == 0:
			return
			
		if uls == 1:
			flag = 'pub'
		elif uls == 2:
			flag = 'prv'
	
		f = open(rsp, "rb")
		a = f.read()
		f.close()
		
		d = Download()
		rd = d.ParseResponseFile(rsp)
		
		infohash = sha(bencode(rd['info'])).hexdigest()

		p = policy.get_policy()

		try:
			cBTS = Server( p(policy.CBT_RPCURL) )
			status = cBTS.TorrentUpload(p(policy.CBT_LOGIN), p(policy.CBT_PASSWORD), {'tdata': a, 'tname':rsp, 'type': flag, 'hash': infohash, 'cat': cls}, self.userid )

			if status['status']:
				self.parent.parent.log.AddMsg('MakeTorrent', _('Torrent upload finished.'), 'info')
			else:
				self.parent.parent.log.AddMsg('MakeTorrent', _('Error') + ': ' + str(status['msg']), 'error')

			dlg = wx.MessageDialog(self.frame, message = status['msg'], caption = 'Info', style = wx.OK | wx.ICON_INFORMATION)
			dlg.ShowModal()
			dlg.Destroy()
			
		except Exception, e:
			dlg = wx.MessageDialog(self.frame, message = _('Error') + ' - ' + str(e), caption = _('Error'), style = wx.OK | wx.ICON_ERROR)
			dlg.ShowModal()
			dlg.Destroy()
Exemplo n.º 7
0
	def complete(self):
		
		#d2 = self.btconfig['completed_tor_dir']+"/"+f+'.torrent'
		
		p = policy.get_policy()
		path = p(policy.TORRENT_PATH)
		
		a = string.split(string.join(self.d), '\\')
		a.reverse()
		self.d2 = path+"\\"+a[0]+'.torrent'
		#~ print self.d2
		
		try:
			completedir(self.d, self.a, self.flag, self.valcallback, self.filecallback, self.pl, comment=self.comment, f2=self.d2)
			if not self.flag.isSet():
				self.currentLabel.SetLabel(_('Done!'))
				self.gauge.SetValue(1000)
				self.button.SetLabel(_('Upload torrent'))
		except (OSError, IOError), e:
			self.currentLabel.SetLabel(_('Error!'))
			self.button.SetLabel(_('Close'))
			dlg = wx.MessageDialog(self.frame, message = _('Error') + ' - ' + str(e), caption = _('Error'), style = wx.OK | wx.ICON_ERROR)
			dlg.ShowModal()
			dlg.Destroy()
Exemplo n.º 8
0
	def __init__(self, parent, id, addtorrentfunc=None):

		#~ wx.MDIChildFrame.__init__(self, parent, -1, 'Nowy torrent', size = wx.Size(400, 420), pos=wx.DefaultPosition, style= wx.MINIMIZE_BOX | wx.CLOSE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.STAY_ON_TOP)
		wx.MDIChildFrame.__init__(self, parent, id, title=_("New torrent"), size = (400,420), style = wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION)
		#~ self.Center(wx.BOTH)
		
		self.AddTorrent = addtorrentfunc
		self.parent = parent
		
		self.images = Images(".")
		self.SetIcon(self.images.GetImage("icn_crt"))
		
		if not self.parent.userid:
			self.SetSize((400,340))
		
		panel = wx.Panel(self, -1)
		dt = DropTarget(self)
		self.SetDropTarget(dt)
		
		gridSizer = wx.FlexGridSizer(cols = 1, vgap = 8, hgap = 8)
		gridSizer.AddGrowableCol(0)

		self.dirCtl = wx.TextCtrl(panel, -1, '')
		
		filebox = wx.StaticBox(panel, -1, _("Source file or directory (select or drag'n'drop here)"))
		filebox.SetFont(defFontN)
		fileboxer = wx.StaticBoxSizer(filebox, wx.VERTICAL)
		annbox = wx.StaticBox(panel, -1, _("Tracker URL"))
		annbox.SetFont(defFontN)
		annboxer = wx.StaticBoxSizer(annbox, wx.VERTICAL)
		commentbox = wx.StaticBox(panel, -1, _("Comment (optional)"))
		commentbox.SetFont(defFontN)
		commentboxer = wx.StaticBoxSizer(commentbox, wx.VERTICAL)
		piecebox = wx.StaticBox(panel, -1, _("Piece size"))
		piecebox.SetFont(defFontN)
		pieceboxer = wx.StaticBoxSizer(piecebox, wx.VERTICAL)
		
		b = wx.BoxSizer(wx.HORIZONTAL)
		button = wx.Button(panel, -1, _('Create from file') )
		button.SetFont(defFontN)
		b.Add(button, 0, wx.EXPAND)
		EVT_BUTTON(self, button.GetId(), self.select)
		#~ b.Add(5, 5, 0, wx.EXPAND)
		c = wx.Button(panel, -1, _('Create from directory') )
		c.SetFont(defFontN)
		b.Add(c, 0, wx.EXPAND)
		EVT_BUTTON(self, c.GetId(), self.selectdir)
		
		
		fileboxer.Add(self.dirCtl, 1, wx.EXPAND|wx.TOP, 2)
		fileboxer.Add((-1,5))
		fileboxer.Add(b, 1, wx.EXPAND)
		gridSizer.Add(fileboxer, 1, wx.EXPAND)

		try:
			p = policy.get_policy()
			value = p(policy.CBT_TRACKER)
		except:
			value = 'http://'+tracker_host+':'+str(tracker_port)+'/announce'
		
		self.annCtl = wxTextCtrl(panel, -1, value)
		annboxer.Add(self.annCtl, 1, wx.EXPAND|wx.TOP, 2)
		gridSizer.Add(annboxer, 1, wx.EXPAND)

		self.commentCtl = wx.TextCtrl(panel, -1, '', style=wx.TE_MULTILINE)
		commentboxer.Add(self.commentCtl, 1, wx.EXPAND|wx.TOP, 2)
		gridSizer.Add(commentboxer, 1, wx.EXPAND)
		
		self.piece_length = wx.Choice(panel, -1, choices = ['2048 KB', '1024 KB', '512 KB', '256 KB', '128 KB'])
		self.piece_length.SetSelection(2)
		self.piece_length.SetFont(defFontN)
		pieceboxer.Add(self.piece_length, 1, wx.EXPAND|wx.TOP, 2)
		gridSizer.Add(pieceboxer, 1, wx.EXPAND)

		#------------------------------------------------------------
		
		if self.parent.userid:
		
			catbox = wx.StaticBox(panel, -1, _("Additional settings") )
			catbox.SetFont(defFontN)
			catboxer = wx.StaticBoxSizer(catbox, wx.VERTICAL)
			
			self.cat_list_choices = ['mp3 (ep)', 'mp3 (cd)', 'mp3 (mix)', 'video', 'nasze wypociny', 'programy', 'inne']
			self.cat_list = wx.Choice(panel, -1, choices = self.cat_list_choices)
			self.cat_list.SetSelection(0)
			self.cat_list.SetFont(defFontN)
			
			self.upl_list_choices = [_('Do not publish this torrent'), _('Public torrent'), _('Private torrent') ]
			self.upl_list = wx.Choice(panel, -1, choices = self.upl_list_choices)
			self.upl_list.SetSelection(0)
			self.upl_list.SetFont(defFontN)
			
			catboxer.Add(self.upl_list, 4, wx.EXPAND|wx.TOP, 4)
			catboxer.Add(self.cat_list, 4, wx.EXPAND|wx.TOP, 4)
			gridSizer.Add(catboxer, -1, wx.EXPAND)
		
		#------------------------------------------------------------
		
		buttons = wxBoxSizer(wx.HORIZONTAL)
		self.nextbutt = wx.Button(panel, -1, _('Continue'))
		self.nextbutt.SetFont(defFontB)
		EVT_BUTTON(self, self.nextbutt.GetId(), self.complete)
		self.cancelbutt = wx.Button(panel, -1, _('Close'))
		self.cancelbutt.SetFont(defFontN)
		EVT_BUTTON(self, self.cancelbutt.GetId(), self.cancel)
		#border.Add(b2, 0, wxALIGN_CENTER | wxSOUTH, 20)
		buttons.Add(self.nextbutt)
		buttons.Add(self.cancelbutt)
		gridSizer.Add(buttons, 1, wx.ALIGN_CENTER)
		
		border = wx.BoxSizer(wx.VERTICAL)
		border.Add(gridSizer, 0, wx.EXPAND | wx.ALL, 8)
		#~ border.Add(10, 10, 1, wx.EXPAND)

		panel.SetSizer(border)
		panel.SetAutoLayout(True)
Exemplo n.º 9
0
 def filename(self):
     torrent_path = policy.get_policy().get(policy.TORRENT_PATH)
     media_file = os.path.join(torrent_path,
                               asciiquote(self.title)+'.torrent')
     return media_file
Exemplo n.º 10
0
 def filename(self):
     torrent_path = policy.get_policy().get(policy.TORRENT_PATH)
     name = asciiquote('%s-%s' % (self.title,self.episode))
     media_file = os.path.join(torrent_path,name+'.torrent')
     return media_file
Exemplo n.º 11
0
import string, urllib, types, socket, re, base64, os
import urllib2, socket
from urllib2 import URLError

from BitQueue import timeoutsocket
from aurllib import urlopen
from BitQueue import policy as qpolicy

policy = qpolicy.get_policy()

bt_mimetype = "x-bittorrent"
content_dipo = re.compile('.*attachment;.*"filename=(?P<filename>.*)".*')

import sys

reserved_chars = [os.sep, "_"]
if sys.platform != "win32":
    reserved_chars.append(":")


def string(s):
    if type(s) == type(""):
        s = s.decode("iso-8859-1")
    return s


def asciiquote(s):
    s = urllib.unquote(s)
    n_s = ""
    for c in s:
        if ord(c) < 32 or ord(c) > 127 or c in reserved_chars: