Python3 on Lubuntu: importing Gstreamer Editing Services - python

I am trying to make a simple python program using GTK and gstreamer. For this purpose, I need the GES (Gstreamer Editing Services) but I seem to be unable to correctly install the dependencies I need.
So far, I have installed (sudo apt-get install...) gstreamer1.0 which works fine. I have done the same thing with libges-1.0-dev and libges-1.0-0. However, when I try to import GES (from gi.repository import GES) in my python script, I get the following error:
ImportError: cannot import name GES, introspection typelib not found
I am guessing that I am missing something about how to actually install the package, but it seems that I just don't quite know my way around python and Linux as well as I should.

Run the following to verify all Prerequisites:
def Prerequisites():
import re
from subprocess import check_output, CalledProcessError, STDOUT
Desired = {'u':'Unknow', 'i':'Install', 'r':'Remove', 'h':'Hold'}
Status = {'n':'Not', 'i':'Inst', 'c':'Conf-files', 'u':'Unpacked', 'f':'halF-conf', 'h':'Half-inst', 'w':'trig-aWait', 't':'Trig-pend'}
re_pip3 = re.compile('(.+?): (.*?)\n', re.S + re.MULTILINE)
re_dpkg = re.compile('(.+?)\n', re.S + re.MULTILINE)
for n, package in enumerate(["python-gst-1.0", "python-gst-1.0", "gir1.2-gstreamer-1.0", "gir1.2-gst-plugins-base-1.0",
"gstreamer1.0-plugins-good", "gstreamer1.0-plugins-ugly", "gstreamer1.0-tools"]):
try:
if n in [0]:
output = check_output("pip3 show {}".format(package), shell=True, stderr=STDOUT).decode()
print('OK: Name: {s[Name]}, Version: {s[Version]}, Location: {s[Location]}'.
format(s=dict(re_pip3.findall(output))))
else:
output = check_output("dpkg -l {}".format(package), shell=True, stderr=STDOUT).decode()
for p in re_dpkg.findall(output)[6:]:
if p[0:2] == 'ii':
print('OK: {} - Desired:{},\tStatus:{}'.format(p, Desired[p[0]], Status[p[1]]))
else:
print('[FAIL] {} - Desired:{},\tStatus:{}'.format(p, Desired[p[0]], Status[p[1]]))
except CalledProcessError as exp:
print('[FAIL] {} - CalledProcessError: {}'.format(package, exp.output.decode()[:-1] or exp))
Please confirm that you want to do something like this: Simple
Dependencies:
* GStreamer core
* gst-plugins-base
GStreamervModules
Installing from local archives
This should be ok: "the only relevant result seems to be (gstreamer-player)"
Try the following:
from gsp import GstreamerPlayer
player = GstreamerPlayer(None)
player.queue("/path/to/audio.mp3")
The project site gives this:
Prerequisites
Debian/Ubuntu/Rasbian:
sudo apt-get install python-gst-1.0 \
gir1.2-gstreamer-1.0 gir1.2-gst-plugins-base-1.0 \
gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly \
gstreamer1.0-tools

Related

Check if python script running from another python script linux

I have actualy python script running on background, you can see how it's displayed when i use command "ps -aux" :
root 405 0.0 2.6 34052 25328 ? S 09:52 0:04 python3 -u /opt/flask_server/downlink_server/downlink_manager.py
i want to check if this script are running from another python script, so i try to us psutil module, but it just detect that python3 are running but not my script precisely !
there is my python script :
import os
import psutil
import time
import logging
import sys
for process in psutil.process_iter():
if process.cmdline() == ['python3', '/opt/flask_server/downlink_server/downlink_manager.py']:
print('Process found: exiting.')
It's look like simple, but trust me, i already try other function proposed on another topic, like this :
def find_procs_by_name(name):
"Return a list of processes matching 'name'."
ls = []
for p in psutil.process_iter(attrs=["name", "exe", "cmdline"]):
if name == p.info['name'] or \
p.info['exe'] and os.path.basename(p.info['exe']) == name or \
p.info['cmdline'] and p.info['cmdline'][0] == name:
ls.append(p)
return ls
ls = find_procs_by_name("downlink_manager.py")
But this function didn't fin my script, it's work, when i search python3 but not the name of the script.
Of course i try to put all the path of the script but nothing, can you please hepl me ?
I resolve the issue with this modification :
import psutil
proc_iter = psutil.process_iter(attrs=["pid", "name", "cmdline"])
process = any("/opt/flask_server/downlink_server/downlink_manager.py" in p.info["cmdline"] for p in proc_iter)
print(process)

drmaa error with sun grid engine - No active session

Hi I've installed gridengine on a 4-node cluster using the following command:
sudo apt-get install gridengine-client gridengine-qmon gridengine-exec gridengine-master
sudo apt-get install gridengine-exec gridengine-client
And it returned:
SGE_ROOT: /var/lib/gridengine
SGE_CELL: bms
I've therefore done all the necessary step to configure the gridengine and it works.
However I want to run my job using python drmaa library and I've installed on the master node:
sudo apt-get install libdrmaa-dev
pip install drmaa
So if i query the system with following script:
#!/usr/bin/env python
import drmaa
def main():
"""Query the system."""
s = drmaa.Session()
s.initialize()
print 'A DRMAA object was created'
print 'Supported contact strings: ' + s.contact
print 'Supported DRM systems: ' + str(s.drmsInfo)
print 'Supported DRMAA implementations: ' + str(s.drmaaImplementation)
print 'Version ' + str(s.version)
print 'Exiting'
s.exit()
if __name__=='__main__':
main()
It returns:
A DRMAA object was created
Supported contact strings: session=NGS-1.9217.1679116461
Supported DRM systems: GE 6.2u5
Supported DRMAA implementations: GE 6.2u5
Version 1.0
Exiting
But if I try to run a job with the script suggested by the link:
http://code.google.com/p/drmaa-python/wiki/Tutorial#Running_a_Job
It returns
drmaa.errors.NoActiveSessionException: code 5: No active session
Could anyone help me?
What's wrong.
The drmaa library looks like is able to communicate with gridengine but it cannot run a job.
Why it raise this error?
I would really appreciate any kind of help.
you will find that the example of running job using DRMAA does not initialize the session so just add s.initialize() after creating new session s = drmaa.Session() as following:
#!/usr/bin/env python
import drmaa
import os
def main():
"""Submit a job.
Note, need file called sleeper.sh in current directory.
"""
s = drmaa.Session()
s.initialize()
print 'Creating job template'
jt = s.createJobTemplate()
jt.remoteCommand = os.getcwd() + '/sleeper.sh'
jt.args = ['42','Simon says:']
jt.joinFiles=True
jobid = s.runJob(jt)
print 'Your job has been submitted with id ' + jobid
print 'Cleaning up'
s.deleteJobTemplate(jt)
s.exit()
if __name__=='__main__':
main()

Run epydoc and/or pylint builders from scons file

How would I create builders that runs epydoc or/and pylint from a scons built?
You can use the Command() builder instead of creating your own builder.
For instance, you could execute epydoc as follows:
# SCons will substitute $SOURCE and $TARGET accordingly
# add any extra cmd line args you need to the cmd string
cmd = 'epydoc $SOURCE $TARGET'
env.Command(target = yourTarget, source = yourSourceFile_s, action = cmd)
Here is what I ended up using, based on Brady's answer.
## Create epydoc!
import os.path
if os.path.isfile('/usr/bin/epydoc'):
sources = Split("__init__.py ook/ eek/ fubar/")
cmd = "epydoc -q --name 'Isotek Python Module collection' " + \
"--html --inheritance listed --graph all -o docs --css white " + \
"--parse-only --debug $SOURCES"
env.Command(target = Dir('docs'), source = sources, action = cmd)
else:
print "WARNING -- Cannot run epydoc so documentation will not be generated."
print "WARNING -- To install epydoc run 'sudo yum -y install epydoc'."
Note that I am running on fedora and do not need to worry about the code running elsewhere thus I can assume the path and how to install epydoc. A more general edit is welcome.
Here is another method, probably more portable to large projects.
First, define epydoc.py in site_scons/site_tools (or where ever you have those) to be:
# -*- coding: utf-8 -*-
import SCons.Builder
import SCons.Action
def complain_epydoc(target, source, env):
print 'INFORMATION: epydoc binary was not found (see above). Documentation has not been built.'
def generate(env):
env['EPYDOC'] = find_epydoc(env)
if env['EPYDOC'] != None:
opts = '--quiet --html --inheritance listed --graph all --css white --parse-only '
env['EPYDOCCOM'] = '$EPYDOC ' + opts + '-o $TARGET $SOURCES'
env['BUILDERS']['epydoc'] = SCons.Builder.Builder(action=env['EPYDOCCOM'])
else:
env['BUILDERS']['epydoc'] = SCons.Builder.Builder(action=env.Action(complain_epydoc))
def find_epydoc(env):
b=env.WhereIs('epydoc')
if b == None:
print 'Searching for epydoc: not found. Documentation will not be built'
else:
print 'Searching for epydoc: ', b
return b
def exists(env):
if find_epydoc(env) == None:
return 0
return 1
In the main SConstruct file, add:
import epdoc
env.Tool("epydoc")
Then, in your SConstruct file or SConscript files, you can build documentation like so:
Alias('epydoc', env.epydoc(source=python_code_files, target=Dir('docs')))
Note: you could do the same thing for ctags and pylint, just to name a few.

Find rpm dependencies using python yum/rpm API?

It seems like it should be available, but I just can't seem to find it.
Something like:
pkg = rpm.Package(name="some package")
dependencies = pkg.dependencies()
Is there something like this available, that would be cleaner than what I'm doing now?
Currently, I'm wrapping the rpm command with subprocess and manually parsing the output:
cmd = "rpm -qRp {file} | sort | uniq".format(file=filename)
cmd_output = subprocess.check_output(cmd, shell=True)
# ... long parse of cmd_output
Following scipt will list all Requires from a package provided on commandline (full path to rpm file):
import os
import rpm
import sys
ts = rpm.TransactionSet()
fd = os.open(sys.argv[1], os.O_RDONLY)
h = ts.hdrFromFdno(fd)
os.close(fd)
for dep in h[rpm.RPMTAG_REQUIRENAME]:
print dep
Or alternatively to work with package in rpm database:
import os
import rpm
import sys
ts = rpm.TransactionSet()
mi = ts.dbMatch('name', sys.argv[1])
for ind in range(mi.count()):
h = mi.next()
for dep in h[rpm.RPMTAG_REQUIRENAME]:
print dep

Python analog of Unix 'which'

In *nix systems one can use which to find out the full path to a command. For example:
$ which python
/usr/bin/python
or whereis to show all possible locations for a given command
$ whereis python
python: /bin/python.exe /bin/python2.5-config /usr/bin/python.exe /usr/bin/python2.5-config /lib/python2.4 /lib/python2.5 /usr/lib/python2.4 /usr/lib/python2.5 /usr/include/python2.4 /usr/include/python2.5 /usr/share/man/man1/python.1
Is there an easy way to find out the location of a module in the PYTHONPATH. Something like:
>>> which (sys)
'c:\\Python25\Lib\site-packages'
If you do:
modulename.__file__
You will get a full path return of that exact module. For example, importing django:
>>>> import django
>>> django.__file__
'/home/bartek/.virtualenvs/safetyville/lib/python2.6/site-packages/django/__init__.pyc'
Edit: I recommend seeing the comments below for some good insight if you haven't had a chance to.
This is a bit kludgy but you can type python pywhich os django PIL:
import os, os.path
import sys
def pywhich(mod):
for p in sys.path:
try:
if any(p.startswith(mod + '.py') for p in os.listdir(p)):
return os.path.join(p, mod)
except OSError:
pass
return "Not found"
if __name__ == '__main__':
for arg in sys.argv[1:]:
print arg, pywhich(arg)

Categories

Resources