Beispiel #1
0
def showDownloadDash(request,cloudItem,t):
	""" Displays the dashboard of the download """

	data = {}

	try:
		ci = checkCloudItem(cloudItem,request.user.id)
		at = checkAccessToken(t,ci)
		data['showToken'] = True
		data['credVerified'] = "Not started"
		data['metaWait'] = "Not started"
		data['downSize'] = "Not started"
		data['fileWait'] = "Not started"
		data['verificationWait'] = "Not started"
		data['objID'] = ci.id
		data['tokenID'] = at.id
		data['form'] = TSCredentialsForm()

		#button has been clicked
		if request.method == "POST":

			subForm = TSCredentialsForm(request.POST)

			if subForm.is_valid():
				down = Download.objects.get(tokenID=at)
				down.threadStatus = constConfig.THREAD_CLICKED
				down.save()
				pwd = subForm.cleaned_data['pwd']
				account = subForm.cleaned_data['uname']

				#start the celery asynchronous task
				download.delay(down,account,pwd)
			else:
				raise Exception("Invalid form")

		#default check to start the periodically ajax function
		try:
			# check to start 
			down = Download.objects.get(tokenID=at)
		except Download.DoesNotExist:
			#store a new download that has not been clicked yet
			down = Download(threadStatus=constConfig.THREAD_NOTCLICKED,tokenID=at,folder=sessionName(t))
			down.save()

		if down:
			data['down'] = down
			data['downStatus'] = down.threadStatus
			data['downMessage'] = down.threadMessage

	except Exception as e:
		data['errors'] = formatException(e)
	
	return render_to_response("dashboard/down.html", data, context_instance=RequestContext(request))
Beispiel #2
0
def downloads_new():
    download = Download()
    form = DownloadForm(request.form, download)
    if form.validate_on_submit():
        f = request.files['url']
        if f:
            filename = secure_filename(f.filename)
            f.save(os.path.join(neobug.config['UPLOAD_FOLDER'], filename))
            form.populate_obj(download)
            download.url = 'static/uploads/' + filename
            download.save()
        return redirect('/downloads')
    return render_template('downloads_new.html',
                           form=form)
Beispiel #3
0
    def run(self):
        print 'Download Manager Started ...'
        while True:
            if self.stop_flag:
                self.stop_downlods()
                break

            while not self.queue.empty():
                req = self.queue.get()
                dl = Download()
                dl.link = req['link']
                dl.username = req.get('username')
                dl.password = req.get('password')
                dl.save(force_insert=True)
                print dl
                if len(self.pool) < config.MAX_JOBS:
                    self.start_new_download(dl)

            sleep(2)
Beispiel #4
0
def new_download():
    if request.method == 'POST':
        dl_url = request.form.get('dl_url').strip()
        path = request.form.get('path').strip()
        username = request.form.get('username')
        password = request.form.get('password')
        dl_account = request.form.get('dl_account')

        dl = Download(url=dl_url, path=path)
        if username:
            dl.username = username
        if password:
            dl.password = password

        if dl_account != 'None':
            dl.account = DownloadAccount.select().where(
                DownloadAccount.pk == int(dl_account))[0]

        dl.save()
        flash('New download added successfully.', 'alert-success')
        return redirect(url_for('index'))
    return render_template('new_download.html',
                           dl_accounts=DownloadAccount.select())
Beispiel #5
0
class DynamicLink:
    """
    create and access dynamic links form outsite of this app
    """
    def __init__(self, slug, file_path, timeout_hours=None, max_clicks=None):
        """creates a new dynamic link"""
        self.new_link = Download()
        self.new_link.slug = slug
        self.new_link.file_path = file_path

        if timeout_hours:
            self.new_link.timeout_hours = timeout_hours
        if max_clicks:
            self.new_link.max_clicks = max_clicks

        self.new_link.save()

    def get_link_key(self):
        """get his unique key"""
        return self.new_link.link_key

    def get_link_url(self, request, langcode='lg'):
        """access his url"""
        return file_link_url(request, self.new_link, langcode)
Beispiel #6
0
class DynamicLink:
    """
    create and access dynamic links form outsite of this app
    """
    def __init__(self, slug, file_path, timeout_hours=None, max_clicks=None):
        """creates a new dynamic link"""
        self.new_link = Download()
        self.new_link.slug = slug
        self.new_link.file_path = file_path

        if timeout_hours:
            self.new_link.timeout_hours = timeout_hours
        if max_clicks:
            self.new_link.max_clicks = max_clicks

        self.new_link.save()

    def get_link_key(self):
        """get his unique key"""
        return self.new_link.link_key

    def get_link_url(self, request, langcode='lg'):
        """access his url"""
        return file_link_url(request, self.new_link, langcode)