Jump to content


Photo

Method to install IPK with python


  • Please log in to reply
12 replies to this topic

#1 area51online

  • Member
  • 14 posts

+1
Neutral

Posted 21 June 2013 - 17:06

Hi
 
I'm a absoulute beginner in python and now I have got a problem, my plugin should download a IPK file and install it.
I got it that the IPK file will downloaded, but I fail in the attempt to install the IPK file, so that the label "status"
sets another text while installing.
 
I already tried it with >> os.system(/tmp/enigma2-plugin-skins-pvmc-skin_1.0_all.ipk) << but the text wasn't setting.
And with this method you are not able to make an callback, right?
 
It would be great if someone give me a tip for a useful command?
 
from Screens.Screen import Screen
from Components.Label import Label
from Components.ProgressBar import ProgressBar
from Components.ActionMap import ActionMap
from Tools.Downloader import downloadWithProgress

class MyMetrixUpdater(Screen):
	skin = """
	<screen position="center,center" size="840,160" flags="wfNoBorder" backgroundColor="background">
		<widget name="status" position="20,10" size="800,70" transparent="1" font="RegularLight;46" foregroundColor="foreground" backgroundColor="background" valign="center" halign="left" noWrap="1" />
		<widget name="progress" position="0,88" size="840,6" transparent="1" alphatest="blend" pixmap="MetrixFullHD/white.png" borderWidth="0" />
		<widget name="key_red" position="20,100" size="10,60" backgroundColor="red" />
		<widget name="key_green" position="20,100" size="10,60" backgroundColor="green" />
		<widget name="key" position="40,100" size="400,60" transparent="1" font="RegularSemilight2;38" foregroundColor="foreground" backgroundColor="background" valign="center" halign="left" noWrap="1" />
	</screen>
	"""
	def __init__(self, session):
		Screen.__init__(self, session)

		self["key_red"] = Label()
		self["key_red"].hide()
		self["key_green"] = Label()
		self["key_green"].show()

		self["actions"] = ActionMap(["OkCancelActions","ColorActions"],
		{
			"ok": self.ok,
			"cancel": self.exit,
			"green": self.startUpdate,
			"red": self.stopUpdate
		}, -1)

		self["key"] = Label(_("Start update"))
		self["status"] = Label(_("Press green to start update!"))
		self["progress"] = ProgressBar()
		self["progress"].hide()

	def ok(self):
		self.close()

	def exit(self):
		self.close()

	def startUpdate(self):
		self["key"].setText(_("Abort"))
		self["key_red"].show()
		self["key_green"].hide()
		self["status"].setText(_("Download files..."))
		localurl = '/tmp/enigma2-plugin-skins-pvmc-skin_1.0_all.ipk'
		sourceurl = 'http://metrixfullhd.w1.ms5.eu/dl-counter/download/enigma2-plugin-skins-pvmc-skin_1.0_all.ipk'
		self.download = downloadWithProgress(sourceurl,localurl)
		self.download.addProgress(self.downloadProgress)
		self.download.start().addCallback(self.downloadFinished).addErrback(self.downloadFailed)

	def stopUpdate(self):
		self["status"].setText(_("Update is aborting..."))

	def downloadFinished(self, string=""):
		self["status"].setText(_("Download successfully!"))
		
	def downloadFailed(self, failure_instance=None, error_message=""):
		text = _("Error downloading files!")
		if error_message == "" and failure_instance is not None:
			error_message = failure_instance.getErrorMessage()
			text += ": " + error_message
		self["status"].setText(text)

	def downloadProgress(self, recvbytes, totalbytes):
		progress = int(100 * recvbytes / float(totalbytes))
		self["progress"].setValue(int(progress))
		self["progress"].show()

 

Sorry, for my english
 
regards
area51

ET9200 with WDC WD30EURS-63S 3TB - OpenPli 4.0 and Kernel 3.8.7


Re: Method to install IPK with python #2 betacentauri

  • PLi® Core member
  • 7,185 posts

+323
Excellent

Posted 21 June 2013 - 17:35

The command to install a ipk is

opkg install <ipk file>

 

I'm also not a python expert. So something like this:

os.system(opkg install /tmp/enigma2-plugin-skins-pvmc-skin_1.0_all.ipk) or perhaps

os.system("opkg install /tmp/enigma2-plugin-skins-pvmc-skin_1.0_all.ipk")


Xtrend ET-9200, ET-8000, ET-10000, OpenPliPC on Ubuntu 12.04

Re: Method to install IPK with python #3 area51online

  • Member
  • 14 posts

+1
Neutral

Posted 21 June 2013 - 17:50

Thanks

 

but like I wrote, I already tried it with os.system and it works but with it I can't make a callback to change the status text.

So i am looking for another way ;)

 

Edit: Sorry, forget to write the opkg install command above.


Edited by area51online, 21 June 2013 - 17:51.

ET9200 with WDC WD30EURS-63S 3TB - OpenPli 4.0 and Kernel 3.8.7


Re: Method to install IPK with python #4 mfaraj57

  • Senior Member
  • 1,605 posts

+286
Excellent

Posted 21 June 2013 - 18:31

you can use  p=os.popen (command)

p.readlines

but i do not know if still valid in phython 2.7



Re: Method to install IPK with python #5 mfaraj57

  • Senior Member
  • 1,605 posts

+286
Excellent

Posted 21 June 2013 - 18:45

also may direct the log to txt file like this

 

os.system('opkg install /tmp/*.ipk >/tmp/log.txt')



Re: Method to install IPK with python #6 athoik

  • PLi® Core member
  • 8,458 posts

+327
Excellent

Posted 21 June 2013 - 20:39

Why don't you write a script that will be called using console?

 

python part

 

from Screens.Console import Console
 
url_sc = "/usr/lib/enigma2/python/Plugins/Extensions/PluginName/update.sh"
 
self.session.open(Console,_("Install "),["%s update" % url_sc])

 

script part (must be executable chmod +x)

 

#!/bin/sh
cd /tmp
echo -------------------------------------------------------------------------
echo $1
echo -------------------------------------------------------------------------
case $1 in
############# update #############
"update")
    URL="http://x/y/z.ipk"
    echo -n "Downloading new ipk..."
    if wget -q -O /tmp/z.ipk $URL; then
        opkg install /tmp/z.ipk
        echo -n "... ipk updated."
    else
        echo "error!"
    fi
    ;;
*)
    echo "error"
    ;;
esac
exit 0

Wavefield T90: 0.8W - 1.9E - 4.8E - 13E - 16E - 19.2E - 23.5E - 26E - 33E - 39E - 42E - 45E on EMP Centauri DiseqC 16/1
Unamed: 13E Quattro - 9E Quattro on IKUSI MS-0916

Re: Method to install IPK with python #7 area51online

  • Member
  • 14 posts

+1
Neutral

Posted 22 June 2013 - 14:39

I also tried that. But I want to that no other screen will open, just that you see the status in the label like - Install Updatefiles...

I read something with - from Components.Ipkg import IpkgComponent - or something like - self.session.cmd(CMD_INSTALL... thats written in the Ipkg.py under the Components folder.

 

But can I use that for my project and how could I use it?

 

Else I just use a timer that automatically change the label.


ET9200 with WDC WD30EURS-63S 3TB - OpenPli 4.0 and Kernel 3.8.7


Re: Method to install IPK with python #8 MiLo

  • PLi® Core member
  • 14,045 posts

+298
Excellent

Posted 23 June 2013 - 19:08

Whatever you do, AVOID using "os.system" at any cost. It will FAIL to work, there's no real explanation why. The "popen" calls have the exact same problem. Only "Console" works.

 

Look at the plugin installer for code that installs an ipk, it's in the "Screens" subdir. Ipkg.py is indeed a wrapper that can be used as well. It's used by the "software update" routine.


Real musicians never die - they just decompose

Re: Method to install IPK with python #9 area51online

  • Member
  • 14 posts

+1
Neutral

Posted 24 June 2013 - 14:55

thanks for your tip, i will try it!


ET9200 with WDC WD30EURS-63S 3TB - OpenPli 4.0 and Kernel 3.8.7


Re: Method to install IPK with python #10 Pr2

  • PLi® Contributor
  • 6,074 posts

+257
Excellent

Posted 24 June 2013 - 15:58

When you create an ipk you can define dependencies, why not simply use this feature?

This will install the missing dependencies while installing your own ipk.


Edited by Pr2, 24 June 2013 - 16:03.

NO SUPPORT by PM, it is a forum make your question public so everybody can benefit from the question/answer.
If you think that my answer helps you, you can press the up arrow in bottom right of the answer.

Wanna help with OpenPLi Translation? Please read our Wiki Information for translators

Sat: Hotbird 13.0E, Astra 19.2E, Eutelsat5A 5.0W
VU+ Solo 4K: 2*DVB-S2 + 2*DVB-C/T/T2 (used in DVB-C) & Duo 4K: 2*DVB-S2X + DVB-C (FBC)

AB-Com: PULSe 4K 1*DVB-S2X (+ DVB-C/T/T2)
Edision OS Mio 4K: 1*DVB-S2X + 1*DVB-C/T/T2
 


Re: Method to install IPK with python #11 athoik

  • PLi® Core member
  • 8,458 posts

+327
Excellent

Posted 24 June 2013 - 20:11

When you create an ipk you can define dependencies, why not simply use this feature?

This will install the missing dependencies while installing your own ipk.

 

But what if dependencies don't exist on feeds?


Wavefield T90: 0.8W - 1.9E - 4.8E - 13E - 16E - 19.2E - 23.5E - 26E - 33E - 39E - 42E - 45E on EMP Centauri DiseqC 16/1
Unamed: 13E Quattro - 9E Quattro on IKUSI MS-0916

Re: Method to install IPK with python #12 MiLo

  • PLi® Core member
  • 14,045 posts

+298
Excellent

Posted 25 June 2013 - 11:06

But what if dependencies don't exist on feeds?

Ask.
Real musicians never die - they just decompose

Re: Method to install IPK with python #13 area51online

  • Member
  • 14 posts

+1
Neutral

Posted 25 June 2013 - 14:22

Now I finally find a result:

 

def startUpdate(self):
		self["key"].setText(_("Abort"))
		self["key_green"].hide()
		self["key_red"].show()
		self["status"].setText(_("Download files..."))
		self.dlfile = '/tmp/enigma2-plugin-extensions-testforupdater_' + self.version + '_all.ipk'
		sourceurl = 'http://metrixfullhd.w1.ms5.eu/dl-counter/download/enigma2-plugin-extensions-testforupdater_' + self.version + '_all.ipk'
		self.download = downloadWithProgress(sourceurl,self.dlfile)
		self.download.addProgress(self.downloadProgress)
		self.download.start().addCallback(self.downloadFinished).addErrback(self.downloadFailed)

def downloadFinished(self, string=""):
		self["status"].setText(_("Install update..."))
		from Screens.Ipkg import Ipkg
		from Components.Ipkg import IpkgComponent
		self.cmdList = [(IpkgComponent.CMD_INSTALL, {'package': self.dlfile})]
		self.session.openWithCallback(self.installFinished, Ipkg, cmdList=self.cmdList)

 

Now the file will downloaded and automatically installed, with a status text and a progressbar!

 

Many thanks to everybody who gives a reply and thanks to MiLo for the useful tip with it I find the result ;) !


ET9200 with WDC WD30EURS-63S 3TB - OpenPli 4.0 and Kernel 3.8.7



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users