Tuesday, November 2, 2010

本机上创建多个基于域名的虚拟主机

这是一些配置文件,使用这些配置文件后,就可使用eclipse来访问Eclipse建立的项目目录,而使用old则访问用户目录中的Apache2目录。
这是一个使用Apache2的基于域名的多个虚拟主机创建实例。但遗憾的是Apache在运行时,会有一个小小的警告
* Reloading web server config apache2
apache2: Could not reliably determine the server's fully
qualified domain name, using 127.0.1.1 for ServerName
不过,这些都素浮云,因为伊可以正常运行了。
127.0.0.1 localhost
127.0.1.1 westnorth-tablet
127.0.1.2 eclipse
127.0.1.3 old
192.168.1.100 pc1
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
/////////////etc/hosts


#NameVirtualHost 127.0.1.3
<VirtualHost *:80>
ServerAdmin webmaster@localhost
# ServerName old
DocumentRoot /home/westnorth/apache2
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/westnorth/apache2/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>
#########################/etc/apache2/default

NameVirtualHost 127.0.1.2
<VirtualHost 127.0.1.2>
ServerAdmin webmaster@localhost
ServerName eclipse
DocumentRoot /home/westnorth/workspace/php
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/westnorth/workspace/php/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>
#############################/etc/apache2/site-availvabale/eclipse

Monday, November 1, 2010

再续

记忆力越来越差了,证明了记笔记的重要性。没自己写,找了个现成的,注意红色部分。

引用:
随便找个项目里的py文件以"Python Run"方式运行一下。然后右键点项目,选择"Debug as",在第2个输入框右侧点"Browser",选择Google App Engine文件夹里的dev_appserver.py文件(最终路径类似于${workspace_loc:keakon/appengine/dev_appserver.py})。切换到"Arguments"标签,填入"."(不含引号)。

前篇之续

前面有点内容没有提,补一下。

安装Pydev后,还需要在Eclipse中设置一下Python的运行环境。
打开菜单windows->preference,在Interpreter-Python中,单击New按钮,选择Python的安装位置,Ubuntu的在/usr/bin/python,下面的system
PYTHONPATH中会出现Python的的系统库的一些目录,要注意的是里面的版本号应该是2.5.这样,就完成了Pydev的设置。

使用pydev插件在Eclipse调用Google App Engine开发Python

突然对Google App Engine(GAE)感兴趣,于是准备在Eclipse中进行试验,但其实噩梦刚刚开始。
遇到的问题有:
1.GAE在Eclipse中插件无法正常安装。
2.Pydev建立的GAE项目无法正常运行。
安装GAE插件,可以使用地址:http://dl.google.com/eclipse/plugin/3.6
,这是对应于Eclipse的3.6,如果是3.5中需要简单修改数字即可。
安装的方法是单击Eclipse的Help,选择"Install new
software",然后,单击Add按钮,在Location中输入地址,在Name中输入描述信息,单击OK会显示可以安装的软件列表,选择要安装的软件,如果不确定,可以全部选择。然后进行安装。不知怎么搞的,我的Eclipse安装GAE插件始终会报错。不过,实践证明,在以后的使用过程中,发现可以使用Python进行开发。

现在我使用的是Ubuntu10.04,这个版本安装的Python是2.6版本,但GAE需要2.5,所以需要再建立一个2.5的Python。其他下载方法比较混乱,最简单的方法是加入一个有2.5的源即可。在/etc/apt/source.list中加入deb
http://security.ubuntu.com/ubuntu hardy-security
main,然后,update一下,就可以使用apt-get进行安装了。截至目前(2010年11月1日)为至,最新的SDK还不太支持Python2.6,所以安装2.5还是必须的。

现在安装Pydev,在Eclipse中的安装地址是http://pydev.sf.net/updates/。这个比较简单。

现在开始新建一个项目,可以选择Pydev中的GAE项目,创建的过程也比较简单。复杂的是如何让它运行起来。
一般来说,应遵循如下步骤:
1.首先,选择一个Python文件,单击Run按钮,使其运行一次。
2.右键单击项目,选择新建文件夹,在Folder Name中随便输入一个名字,如GAE。
3.单击Advanced按钮,选择Link to the Alternate Location。单击其后的Browser,选择GAE的目录。
前面是为了将GAE链接到工程中来。
4.右键单击项目,选择Debug as-》debug configuration,在Main
Module中,选择GAE目录(刚才新建的包含了GAE SDK的目录)中的dev_appserver.py文件。
5.单击Debug按钮则服务开始运行。
6.在运行前,可能在Console中会出现一些提示,问要不要在运行前更新之类,输入yes或no(按自己的需要)
7.在运行提示中,会发现服务运行于哪个端口,一般是8080。在浏览器中输入 localhost:8080,就可以看到一个简单的示例输出。

Friday, August 20, 2010

使用git同步代码

git是一个代码同步工具。
  1. 1.安装git
Ubuntu中的git-core有许多工具是没有的,所以应该下载一个git的deb包进行安装。
  1. 2.安装ssh
同步有许多方法,有http,也可以使用ssh。我使用的是ssh。
首先,安装一个ssh服务,名字叫openssh-server。安装后自动启动。
然后在客户机上使用ssh-keygen -t rsa生成一个密钥,在生成时,密码掩码要留空,这样就可自动登录。
生成一个名为id_rsa.pub(?),的文件,该 文件位于.ssh目录中,将这个文件发送到服务器的.ssh目录中,更名为authorized_keys,然后重新使用ssh登录,会发现已经不要密码了。现在准备工作作完,开始部署服务器。
  1. 3.部署git服务
首先,要在服务器端创建名为/var/cache/git/workspace.git的目录,这个是必须的。
然后要给该目录一个权限。
cd  /var/cache/git/workspace.git
chown -R root:www-data ./
而且要将当前用户加入到www-data组之中。
在该目录中生成一个git反响:
git --bare init
chmod g+rwx -R ./
  1. 4.客户端向服务器添加代码
客户端操作:
进入一个不是workspace的目录。创设是code。
执行:
会将服务器同步下来。由于服务器中并无代码,所以我们还需要加入一些代码。
(1)将代码复制到code目录。
(2)git add ./,这样就会将当前目录中的所有代码添加到git中。
(3)git commit -m 'init' ,第2步并未真正提交代码,这是提交的命令
 (4)git push origin master ,将本地作为master分支提交到服务器的origin中。这两个关键词都不能更改。这是第一次,执行完后,以后就可直接git push了。
现在,就将本地的代码同步到服务器上了。
  1. 5.从任意客户端获取代码
现在,任意客户端(安装了git的机器),进入到一个要获取代码的目录。
然后,
就会将我们上传到服务器的代码同步到本机。
然后我们也可以参照上一节的操作上传代码了。

注意:Eclipse的代码有点特别。如果要从服务器同步代码的话。那么,不能将同步来的项目代码放置在这Eclipse的项目默认目录(一般是~/workspace),否则在打开项目文件时会报错。放置在另外的其他目录就没任何问题了。
 







使用按钮打开一个activity

For example, inside the onCreateOptionsMenu() method, you can define a new menu item with an Intent like this:

  MenuItem menuItem = menu.add(0, PHOTO_PICKER_ID, 0, "Select Photo");
menuItem
.setIntent(new Intent(this, PhotoPicker.class));
  这是SDK中的一段话,意思是可以在创建菜单时使用SetIntent来使该项可打开一个Activity.
  

关于组菜单的操作

在菜单创建代码后面加上如下一句,则会使一组菜单成为单选状态。
 menu_send.setGroupCheckable(0, true, true);

代码:
      menu.setHeaderTitle(R.string.backup_conmenu);
            SubMenu menu_send=menu.addSubMenu("send");
            menu_send.add(0,menu_email,0,"email");
            menu_send.add(0,menu_wifi,0,"wifi");
            menu_send.setGroupCheckable(0, true, true);
            menu_send.setGroupEnabled(0, false);


SDK中的一句话应该如何理解:

This will display a checkbox with the menu item (unless it's in the Icon Menu). When the item is selected, the onOptionsItemSelected() callback is called as usual. It is here that you must set the state of the checkbox. You can query the current state of the item with isChecked() and set the checked state with setChecked(). Here's what this looks like inside theonOptionsItemSelected() callback:

  switch (item.getItemId()) {
case VIBRATE_SETTING_ID:
 
if (item.isChecked()) item.setChecked(false);
 
else item.setChecked(true);
 
return true;
...这里为什么要不断设置单选框的状态?
}
我在实际代码中这样:

    @Override
    public boolean onContextItemSelected(MenuItem item) {
//      AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    TextView tview3=(TextView)findViewById(R.id.hello);
     switch (item.getItemId()) {
      case menu_email:
      tview3.setText("your data will send by email");
        return true;
      case menu_wifi:
      tview3.setText("your data will send by wifi");
        return true;
      case menu_apple:
      if (item.isChecked()) item.setChecked(false);
      else item.setChecked(true);
      tview3.setText("your favorite is apple");
      return true;
      case menu_pear:
      if (item.isChecked()) item.setChecked(false);
      else item.setChecked(true);
      tview3.setText("your favorite is pear");
      return true;
      case menu_ear:
      if (item.isChecked()) item.setChecked(false);
      else item.setChecked(true);
      tview3.setText("your favorite is ear");
      
      return true;
      case menu_egg:
//      if (item.isChecked()) item.setChecked(false);
//      else item.setChecked(true);
      tview3.setText("your favorite is egg");
      return true;
      default:
        return super.onContextItemSelected(item);
      }
     }

似乎也没有什么问题。