国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
How to Embed ViewCVS in Plone — plone.org
How to Embed ViewCVS in Plone

This How-to applies to: Any version.
This How-to is intended for: Server Administrators

An example of how to ‘persuade‘ ViewCVS to embed in a Plone page. Provides an account of how to do rewriting with Apache, converting ViewCVS, and adding externally created, dynamic content to Plone pages.

The original content of this how-to can be found at this location.

A working example can be found at this location.

I can‘t just paste the code, since your setup will be different from mine. And beware for those who want elegance, this is not the epitome of pretty code. It is just a plain quick hack that took under 2 hours to implement. I have no doubt this How-To will take me at least double that length of time. Furthermore, my deepest respect to the ViewCVS team for an excellent product. I am sorry that I had to do what I did to get it to work how I wanted it to. I would send you a patch but I am far too scared. And last but not least, Plone and Zope, absolutely killer products from the minds of geniuses.

The nature of the problem

The nice thing about Plone, and I have only been using it for 4 days, is that everything looks the same. I think the Human Computer Interface Designers would call this something like uniformity and consistency , and for me as the end user it is just lovely.

That is all well, but what about prepackaged scripts that don‘t look like plone, how can you embed them in a Plone page? ViewCVS is one such script. It is used almost universally for displaying CVS contents with HTML over HTTP for example. Incredibly, and if you checked the link, you will see that even Sourceforge display a naked ViewCVS page with no formatting. Yuck!

How are we going to fix it?

Well, there are about 14,000 solutions to this problem, and I really should have approached it in one of the other ways (like importing the mod-python viewcvs modules and using them, or even calling the cgi scripts directly) but instead, I decided to use my existing Apache based viewcvs setup.

I shall force viewCVS requests to be passed to a Zope request-handler which will independently request the actual ViewCVS content and embed it in a plone page.:

USER -> APACHE -> REWRITE -> ZOPE -> VIEWCVS(APACHE) -> ZOPE -> USER

Well that is it. If you understand that, you are done with this how-to. If you need more information on some or all of the steps that it took (and remember doing it takes very little actual time) please read on.

Requirements

  1. ViewCVS Note: you will not be able to run this copy of ViewCVS outside Plone after these changes, you will need to use another copy
  2. Plone
  3. Zope
  4. Apache with Rewrite and Proxy modules

Apache Rewriting

The plan is to have all requests to the root / on the server to be redirected to the Plone (Zope) server, while all requests to /local/ to be allowed to pass through to Apache. I understand this is a very common way of using Zope and Plone, and it certainly works fairly smoothly on my set up.

I am barely literate in Apache mod-rewrite, but the best I can do is to paste my example configuration and explain it. If you alreday have rewrite set up, you may need to review your config to see exactly what is going on.:

  RewriteEngine OnRewriteRule ^/local - [L]RewriteRule ^/(.*) http://localhost:8080/VirtualHostBase/http/aa.homelinux.com:80/VirtualHostRoot/$1 [P]

 

The first line turns rewriting on. The second line tells the server to stop processing and pass through to the local server - [L] any requests to /local. And the third line rewrite all other requests to that weird url on the local machine. If you don‘t know what they all mean, don‘t worry, just know that localhost:8080 is the location of the Zope server, and aa.homelinux.com:80 is the location of the Apache Server. Leave the other words as they are. They are needed by the virtual host monster.

Do it now, install a virtual host monster in the root of your Zope installation. It is in the dropdown box on the right. You don‘t need to edit this in any way. And while you are at it, if you have changed any Apache settings, restart the server.

ViewCVS

Currently, I have an alias for /local/cvs/ which points to my actual viewcvs directory using Apache2. If you haven‘t already set it up, a simple alias like this will usually do the job for making ViewCVS work with Apache:

  Alias /local/cvs /usr/lib/cgi-bin/viewcvs.cgi

 

Where /local/cvs/ is the browseable url for ViewCVS on the Apache server, and /usr/lib/cgi-bin/viewcvs.cgi is the actual location of ViewCVS on your filesystem. Before I put Plone in the mix, this is how the outside world would access ViewCVS.

When ViewCVS renders it‘s pages it sets up the url for the link and in our case it sets them up as:

  <servername>/<script location>/<parameters>

 

In order that we can force ViewCVS to change its links to point to:

  <servername>/<our Plone proxy>/<parameters>/

 

we must edit the code. The creation of the Plone proxy is discussed below. It is responsible for fetching actual ViewCVS pages and making them look Plone.

Editing your exact code may be different, my version is 1.0-dev from Debian Unstable. You need to find the main ViewCVS module, called /usr/lib/python2.3/site-packages/viewcvs/viewcvs.py on my installation. At approximately line 403, in the method get_link(), I have changed:

  url = self.script_name

 

to:

  url = ‘/cvs/vcvsproxy‘

 

or the location of a page template in your Plone site, eg /Portal/vcvsproxy from where you want to serve the ViewCVS Content.

(further elements are added to this url by the method)

Thus, if original links had been created to:

  <servername>/local/cvs/<parameters>

 

they would now point to:

  <servername>/cvs/vcsproxy/<parameters>

 

Check the change has worked. Refresh a ViewCVS page, and click on a link. They should all be broken and point to a zope page that isn‘t there. If they are broken, examin the links. Are they of the correct type discussed above? I repeat, your installation may be different from everyone else‘s, so examine them carefully. If you are done, you should now move on to creating the Plone proxy, a dynamic piece of Plone content.

Plone Basic Content Embedding

Did you remember to install a virual host monster in the root folder of your Zope?

You would expect that it is easy to make a random HTML page look like a Plone page from within a Plone site. You would be right, it is easy.

You have to:

  1. Create a page template.
  2. Set the default template for that form to be the template used by Plone.
  3. Add some kind of content to the page.

Creating a page template

Excuse me if you already know how to do this! Go to the drop down box on the left in the Zope Management Interface (usually at /manage on your Zope installation) and select "page template". You will be asked for an ID and set this to vcvsproxy or the value that you entered above for the new ViewCVS URLs.

Ok, done! Check it worked. Browse your Plone site to the ID of your newly added page template, and you should see the defualt template in place.

Setting the page template to use the default Plone template

Edit your newly created page template and in it‘s <html> tag insert:

  metal:use-macro="here/main_template/macros/master"

 

As you can probably see, this will make the page template use the default Plone template (here/main_template).

Ok, done! Check it worked. Browse the page again, and this time it should miraculously look like a Plone page.

Adding content to the page

There are a few ways which you can add content to this page and there are surely more that I will discover with time.

  1. Static content. This is the easiest way, and not much use to anyone! Frankly if you want to add a static content page to your Plone, do it through the web interface and write it in structured text. Exactly like I am doing right now.
  2. Dynamic content. This content can come from a number of sources. The two I have become familiar with are the "script (Python)" and the "external method". Both of these are python scripts. The difference between them is how you use them (although I am no expert) "script (python)" lives inside the Zope insance and can really only access components of the instance itself. It certainly cannot do things like import modules or open external files. It is probably much faster for this. External methods are methods within python modules that live outside the Zope insance and are capable of doing everything that Python can in terms of library imports. Thus you can do funky things like open files, or even as we shall see open external web-pages.

In the body of your page template you need to insert the tags:

  <div metal:fill-slot="main"><span tal:replace="structure here/getcvs" /></div>

 

  • The outer <div> element indicates that we would like the content to fill the main slot, the main content area of the page: metal:fill-slot="main"
  • The inner <span> element indicates that it would like itself replaced by the output of here/foo with: tal:replace="structure here/getcvs".
  • getcvs is the name of the script or external method we shall be calling. This guarantees that the external method will return an HTML-formatted string which will be embedded at the requested position in the page. (Note: for an External Method, this is the ID of the method itself, not the module within which it is).

External Methods

We will concentrate on External methods since we will be using one later. You will need to:

  1. Create the python module.
  2. Add the method to the Plone site.

Creating the Python module

Call it whatever you like with the extension .py (beware Windows users!). For our example we shall call it cvs.py. Your installation may differ from mine - the location of the module. I put mine in /var/lib/zope/instance/default/Extensions, and I am assured that this is a good place for it. It must be in the Extensions directory of your instance on your filesystem. You need one method at least in this module that takes an optional parameter (which we shall call self but as a note for Python programmers, this is not an instance of the method) and which will return a string. We shall call our method getcvs. At this stage we don‘t know what we are going to need in our module, we will just put in a test. Your module should look like this:

  def getcvs(self):return "<h1>Hello Plone World</h1>"

 

Adding the external method to your Plone site

In the dropdown box, select External Method. Enter the following options:

  ID                getcvsTITLE             The ViewCVS FetcherMODULE NAME       cvsFUNCTION NAME     getcvs

 

And you are done. Remember this page, you need to reload the method every time you make a change of it just by uploading the file again. Check the script works, by browsing the URL of your vcvsproxy. It should return you a Plone looking page greeting you with the message Hello Plone World entered above. If so you have the script working, so you can move on to actually making it useful.

Fetching ViewCVS content with a Python External Method

You have a working external method (getcvs) that is called by a Plone-looking page-template (vcvsproxy) for its content. You external method may differ from mine. Mine is probably appalling code, but it almost works. The general idea is to:

  1. Parse the request to the vcvsproxy for the parameters to pass to ViewCVS
  2. Construct a new URL which is the actual location of ViewCVS on the system (in my case /local/cvs/*).
  3. Connect and read the headers for the new URL.
  4. If it is an text/html page, return it‘s contents back to the page template that called the method.
  5. I it is any other file, return a page containing a link to the actual location of the file so that users may click it to download.

Happy? Let‘s have a look at the code:

  import urllib2def getcvs(self):# self is an object passed to us. You can query it with dir() if you# like, split the path requested, and grab the bit after ‘/vcvsproxy/‘p = self.REQUEST.PATH_INFO.split(‘vcvsproxy‘)[-1]# build the new actual URL to ViewCVSu = "http://localhost/local/cvs/%s?%s" % (p, self.REQUEST.QUERY_STRING)# urllib2 voodoo for clearing proxies that might be set upopener = urllib2.build_opener(urllib2.ProxyHandler({}))# open the URL without readingf = opener.open(u)o = ‘‘# check the content typeif f.info().has_key(‘Content-Type‘):ct = f.info()[‘Content-Type‘].split(‘/‘)[-1]# if it is htmlif ct.startswith(‘html‘):# read the data and return it with in a templateo = RT % f.read()else:# otherwise return a link to the file in a templateo = FT % ureturn oFT = """<h1>Please download the file here</h1><a href="%s">download</a>"""RT = """%s<a >How to embed ViewCVS in Plone</a>"""

 

Well, you won‘t believe it, but you are done!

Test your setup. Browsing vcvsproxy/ should give you the CVS root. If you would like to see an example of this working, please visit my CVS Repository.

by aafshar last modified February 5, 2006
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
關(guān)于Python的一些介紹和資源
Java視線論壇 :: 閱讀主題 - 我眼中的Python
Python做網(wǎng)站
[Python]Pytho WEB 編程的學(xué)習(xí)方法
Python高級編程
一個老外對Zope的評價,然后,他...
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服