Jor*_*Lis 11 software-center python
如何在 Ubuntu 软件中心展示我自己的个性化横幅展品?
我见过一些URL定义/usr/share/software-center/softwarecenter/enums.py
和/usr/share/software-center/softwarecenter/distro/Ubuntu.py
至今。
我还尝试跟踪从视图到核心的代码。但我迷路了。_append_banner_adds
调用SoftwareCenterAgent
。它调用SpawnHelper
. 然后我迷路了。还有一些电话,SimpleFileDownloader
但我无法跟踪它们。
另外,我在调试日志中注意到了这个条目。
2013-02-08 15:07:43,731 - softwarecenter.simplefiledownloader - DEBUG - download_file: http://software-center.ubuntu.com/site_media/exhibits/2012/12/SC_banner_Mixxx_2.png None True
Run Code Online (Sandbox Code Playgroud)
是否有关于如何实施的文档?一些简单的方法来更改默认横幅并以干净的方式放置我自己的横幅将非常有帮助。
我想我可以简单地重写该_append_banner_adds
函数,但我在 python 上并不是非常多产,如果可能的话,我想理解和使用 Ubuntu 正在使用的相同方法。
打开/usr/share/software-center/softwarecenter/backend/scagent.py
并编辑此函数的开头,使其显示:
def query_exhibits(self):
import urllib, json
class Obj:
def __init__(self, obj):
self.obj = obj
def __getattr__(self, name):
if name[:2] == "__": return object.__getattr__(self, name)
return self.obj[name]
self.emit("exhibits", [Obj(x) for x in json.loads(urllib.urlopen("http://localhost:8800/cgi-bin/bannerlist.py").read())])
return
Run Code Online (Sandbox Code Playgroud)
其余的你可以保持原样,它永远不会到达。
如果你想在你的<iframe>
, 编辑
/usr/share/software-center/softwarecenter/ui/gtk3/widgets/exhibits.py
并找到settings.set_property("enable-scripts", False)
。更改False
为True
。
现在 make/var/www/cgi-bin/bannerlist.py
并使其可执行:
#!/usr/bin/env python
import json
print("Content-type: application/json\n")
print(json.dumps([
{
"html": "<iframe src='file:/tmp/test.html'></iframe>",
"title_translated": "Hey dawg",
"click_url": "http://4chan.org",
"package_names": ("gimp"),
"banner_urls": ["file:/"],
"published": True
},
{
"html": "<iframe src='http://localhost:8800/cgi-bin/banner.py'></iframe>",
"title_translated": "Hey dawg",
"click_url": "http://4chan.org",
"package_names": ("gimp"),
"banner_urls": ["file:/"],
"published": True
}
]))
Run Code Online (Sandbox Code Playgroud)
这演示了生成的横幅列表。
现在 make/var/www/cgi-bin/banner.py
并使其可执行:
#!/usr/bin/env python3
import time
print("Content-type: image/svg+xml\n")
print("""
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<rect width="300" height="100"
style="fill:rgba(0,0,255,0.5);stroke-width:1;stroke:rgba(0,0,0,0.5)"/>
<text x="0" y="25" fill="black">Time is """ + str(time.time()) + """</text>
</svg>
""")
Run Code Online (Sandbox Code Playgroud)
这演示了生成的横幅。
您可能需要清除软件中心缓存。您可以使用rm -rf ~/.cache/software-center
.
显然,您需要放入一些东西/tmp/test.html
才能使第一个横幅起作用。
您还需要一个运行在 8800 上的网络服务器,cgi-bin
以便它工作。如果你没有这个,请在 Bash 中运行:
cd /var/www
python -c "import BaseHTTPServer as h, CGIHTTPServer as c;
i = c.CGIHTTPRequestHandler;
i.cgi_directories = ['/cgi-bin'];
h.HTTPServer(('', 8800),i).serve_forever()"
Run Code Online (Sandbox Code Playgroud)
您需要设置样式iframe
以使其填充空间,但您已经想通了。
归档时间: |
|
查看次数: |
446 次 |
最近记录: |