2013年8月17日星期六

Python根据下载的图片日期创建文件夹并自动整理

__author__ = 'jimshen'
#coding=utf-8

import os, os.path, sys, time, string, shutil, random

mydir = unicode('e:\\download', 'utf8')
picstore = unicode('e:\\图片', 'utf8')
files = os.listdir(mydir)
for f in files:
    filename = mydir + os.sep + f
    if os.path.isdir(filename):
        continue
    ext = os.path.splitext(filename)[1].lower()
    if(ext=='.gif' or ext=='.jpg' or ext=='.jpeg' or ext=='.png'):
        mtime = time.strftime("%Y-%m-%d",
                              time.localtime(os.path.getmtime(filename)))
        newfilename = time.strftime("%Y%m%d%H%M%S",
                                    time.localtime(os.path.getmtime(filename))) \
                      + str(random.randint(100000, 999999)) + os.path.splitext(filename)[1]
        foldername = picstore + os.sep + mtime
        dstfilename = foldername + os.sep + newfilename
        if not os.path.exists(foldername):
            os.mkdir(foldername)
        shutil.move(filename, dstfilename)
        print f + " moved to " + dstfilename

Ubuntu Server 12.04 上 ownCloud安装过程


ownCloud安装基本没啥难度,按照官方文档的安装说明做就可以了,不过我这里用到了另一个机器上的iSCSI target,所以过程稍微有些复杂。
Prerequisites
To run ownCloud, your webserver must have the following installed:
·             php5 (>= 5.3)
·             php5-gd
·             php-xml-parser
·             php5-intl
And as optional dependencies:
·             php5-sqlite (>= 3)
·             php5-mysql
·             smbclient
·             curl
·             libcurl3
·             php5-curl
You have to install at least one of php5-sqlite or php5-mysql, depending on which of the two database systems you want to use.
smbclient is only used if you want to mount SMB shares to your ownCloud. The curl packages are needed for some apps (e.g. http user authentication)
Commands for Ubuntu and Debian (run as root):
apt-get install apache2 php5 php5-gd php-xml-parser php5-intl
apt-get install php5-sqlite php5-mysql smbclient curl libcurl3 php5-curl
Extract ownCloud and Move to Your Webserver
tar -xjf path/to/downloaded/owncloud-x.x.x.tar.bz2
(如果下载的是zip版本 则是sudo unzip owncloud-x.x.x.zip
sudo mv owncloud /path/to/your/webserver
Set the Directory Permissions
The owner of your webserver must own the apps/, data/ and config/ directories in your ownCloud install. You can do this by running the following command for the apps, data and config directories:
chown -R www-data:www-data /path/to/your/owncloud/install/data
Replace www-data:www-data with the user and group of the owner of your webserver.
【这里我们使用了iSCSI作为ownCloud的存储】
1、首先在freenas上设置好networkiscsi volumechap secret等,并记住iscsitarget名称
2sudo apt-get install open-iscsi
3如果iSCSI Target有启用CHAP(非相互CHAP),要编辑/etc/iscsi/iscsid.conf中的CHAP Settings区段,将以下2行启用(删掉前面的#
node.session.auth.username = username
node.session.auth.password = password
并将正确的帐号密码填入,存档后重新启动open-iscsi
sudo /etc/init.d/open-iscsi restart
4、寻找iSCSI Target
sudo iscsiadm -m discovery -t st -p 10.18.32.28
找到后会列出可用的iSCSI Target名称,而且在/etc/iscsi/nodes下会产生对应的目录
5 iscsiadm -m node --targetname "iqn.2010-10.synology-iscsi:newvirtualdisk.1" --portal "10.18.32.28:3260" –login
6fdisk –l
fdisk /dev/sdb
n命令创建primary分区
7、创建文件系统
mkfs.ext3 /dev/sdb1
8、挂载文件系统
mount /dev/sdb1 /mnt
sudo chown www-data:www-data –R /mnt
9、在moodle安装时使用/mnt作为存储目录

l  登出已连接的iSCSI Target
sudo iscsiadm -m node -T 已登入的Target名称 -p NASIP -u
l  设定开机自动登入iSCSI Target
方法1、针对已存在的Target单独设定
sudo iscsiadm -m node -T Target名称 -p NASIP -o update -n node.conn[0].startup -v automatic
sudo /etc/init.d/open-iscsi restart
方法2、针对设定之后,新加入的Target,已存在的Target不受影响
编辑/etc/iscsi/iscsid.conf
node.startup 设为 automatic
sudo /etc/init.d/open-iscsi restart

Enable .htaccess and mod_rewrite if Running Apache
If you are running the apache webserver, it is recommended that you enable .htaccess files as ownCloud uses them to enhance security and allows you to use webfinger. To enable .htaccess files you need to ensure that AllowOverride is set to All in the Directory /var/www/ section of your virtual host file. This is usually in /etc/apache2/sites-enabled/000-default. You should also run 
a2enmod rewrite 
and 
a2enmod headers.
Then restart apache:
service apache2 restart
In order for the maximum upload size to be configurable, the .htaccess file in the ownCloud folder needs to be made writable by the server.
【修改配置文件设定最大文件上传大小】
upload_max_filesize = 8M 
post_max_size = 10M 
memory_limit = 20M 
Follow the Install Wizard
Open your web browser and navigate to your ownCloud instance. If you are installing ownCloud on the same machine as you will access the install wizard from, the url will be: http://localhost/ (or http://localhost/owncloud). For basic installs we recommend SQLite as it is easy to setup (ownCloud will do it for you). For larger installs you should use MySQL or PostgreSQL. Click on the Advanced options to show the configuration options. You may enter admin credentials and let ownCloud create its own database user, or enter a preconfigured user. If you are not using apache as the webserver, please set the data directory to a location outside of the document root. See the advanced install settings.


Ubuntu 12.04 Server上安装gitlab 5.3过程

这个安装过程有点变态,基本是按照官方安装文档来进行的,网址是:https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md。安装过程中遇到不少问题,所幸的是最后都解决了。我用Diigo在安装文档上做了很多的注释,最后汇总一下。
Overview
The GitLab installation consists of setting up the following components:
1.  Packages / Dependencies
2.  Ruby
3.  System Users
4.  GitLab shell
5.  Database
6.  GitLab
7.  Nginx
1. Packages / Dependencies
sudo is not installed on Debian by default. Make sure your system is up-to-date and install it.
# run as root!
apt-get update -y
apt-get upgrade -y
apt-get install sudo -y
Note: During this installation some files will need to be edited manually. If you are familiar with vim set it as default editor with the commands below. If you are not familiar with vim please skip this and keep using the default editor.
# Install vim and set as default editor
sudo apt-get install -y vim
sudo update-alternatives --set editor /usr/bin/vim.basic
Install the required packages:
sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl git-core openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev
Make sure you have the right version of Python installed.
# Install Python
sudo apt-get install -y python
# Make sure that Python is 2.5+ (3.x is not supported at the moment)
python --version
# If it's Python 3 you might need to install Python 2 separately
sudo apt-get install python2.7
# Make sure you can access Python via python2
python2 --version
# If you get a "command not found" error create a link to the python binary
sudo ln -s /usr/bin/python /usr/bin/python2
# For reStructuredText markup language support install required package:
sudo apt-get install python-docutils
Note: In order to receive mail notifications, make sure to install a mail server. By default, Debian is shipped with exim4 whereas Ubuntu does not ship with one. The recommended mail server is postfix and you can install it with:
sudo apt-get install -y postfix
Then select 'Internet Site' and press enter to confirm the hostname.
2. Ruby
Remove the old Ruby 1.8 if present
sudo apt-get remove -y ruby1.8
Download Ruby and compile it:
mkdir /tmp/ruby && cd /tmp/ruby
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz | tar xz
cd ruby-2.0.0-p247
./configure
make
sudo make install
Install the Bundler Gem:
sudo gem install bundler --no-ri --no-rdoc
3. System Users
Create a git user for Gitlab:
sudo adduser --disabled-login --gecos 'GitLab' git
4. GitLab shell
GitLab Shell is a ssh access and repository management software developed specially for GitLab.
# Go to home directory
cd /home/git
# Clone gitlab shell
sudo -u git -H git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell
# switch to right version
sudo -u git -H git checkout v1.7.0
sudo -u git -H cp config.yml.example config.yml
# Edit config and replace gitlab_url with something like 'http://domain.com/'
sudo -u git -H editor config.yml
# Do setup
sudo -u git -H ./bin/install
5. Database
这里就是创建一个数据库和创建一个用户,可以用phpmyadmin来完成。
# Create the GitLab production database
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;

# Grant the GitLab user necessary permissions on the table.
mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
6. GitLab
# We'll install GitLab into home directory of the user "git"
cd /home/git
Clone the Source
# Clone GitLab repository
sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab
# Go to gitlab dir
cd /home/git/gitlab
# Checkout to stable release
sudo -u git -H git checkout 5-4-stable
Note: You can change 5-4-stable to master if you want the bleeding edge version, but never install master on a production server!
Configure it
cd /home/git/gitlab
# Copy the example GitLab config
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
# Make sure to change "localhost" to the fully-qualified domain name of your
# host serving GitLab where necessary
sudo -u git -H editor config/gitlab.yml
# Make sure GitLab can write to the log/ and tmp/ directories
sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX  log/
sudo chmod -R u+rwX  tmp/
# Create directory for satellites
sudo -u git -H mkdir /home/git/gitlab-satellites
# Create directories for sockets/pids and make sure GitLab can write to them
sudo -u git -H mkdir tmp/pids/
sudo -u git -H mkdir tmp/sockets/
sudo chmod -R u+rwX  tmp/pids/
sudo chmod -R u+rwX  tmp/sockets/
# Create public/uploads directory otherwise backup will fail
sudo -u git -H mkdir public/uploads
sudo chmod -R u+rwX  public/uploads
# Copy the example Unicorn config这里发生了一个问题,我找不到这个unicorn.rb.example,所以从github上的gitlab源码里边下载了一个放进去了
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
# Enable cluster mode if you expect to have a high load instance
# Ex. change amount of workers to 3 for 2GB RAM server
sudo -u git -H editor config/unicorn.rb
# Configure Git global settings for git user, useful when editing via web
# Edit user.email according to what is set in gitlab.yml
sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "gitlab@localhost"
sudo -u git -H git config --global core.autocrlf input
Important Note: Make sure to edit both gitlab.yml and unicorn.rb to match your setup.
Configure GitLab DB settings
# Mysql
sudo -u git cp config/database.yml.mysql config/database.yml
or
# PostgreSQL
sudo -u git cp config/database.yml.postgresql config/database.yml
# Make sure to update username/password in config/database.yml.
# You only need to adapt the production settings (first part).
# If you followed the database guide then please do as follows:
# Change 'root' to 'gitlab'
# Change 'secure password' with the value you have given to $password
# You can keep the double quotes around the password
sudo -u git -H editor config/database.yml
# Make config/database.yml readable to git only
sudo -u git -H chmod o-rwx config/database.yml
Install Gems
cd /home/git/gitlab
sudo gem install charlock_holmes --version '0.6.9.4'
# For MySQL (note, the option says "without ... postgres")这里会花很长很长时间,要耐心等待
sudo -u git -H bundle install --deployment --without development test postgres unicorn aws
# Or for PostgreSQL (note, the option says "without ... mysql")
sudo -u git -H bundle install --deployment --without development test mysql unicorn aws
Initialize Database and Activate Advanced Features
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
# Type 'yes' to create the database.
# When done you see 'Administrator account created:'
Install Init Script
Download the init script (will be /etc/init.d/gitlab):
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
sudo chmod +x /etc/init.d/gitlab
Make GitLab start on boot:
sudo update-rc.d gitlab defaults 21
Check Application Status
Check if GitLab and its environment are configured correctly:
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
【这里又有问题,报git的版本太低,解决方法如下】
if it report "git version is too low", you can install higher version of git manually.reference https://www.digitalocean.com/community/articles/how-to-install-git-on-ubuntu-12-04
Be sure also that when you edit the config/gitlab.yml file that you update the location of git (mine was at /usr/local/bin/git )  . reference https://groups.google.com/forum/#!topic/gitlabhq/exlj_EHatQQ
Start Your GitLab Instance
sudo service gitlab start
# or
sudo /etc/init.d/gitlab restart
Double-check Application Status
To make sure you didn't miss anything run a more thorough check with:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
If all items are green, then congratulations on successfully installing GitLab! However there are still a few steps left.
7. Nginx
Note: Nginx is the officially supported web server for GitLab. If you cannot or do not want to use Nginx as your web server, have a look at the GitLab recipes.
Installation
sudo apt-get install -y nginx
Site Configuration
Download an example site config:
sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
Make sure to edit the config file to match your setup:
# Change YOUR_SERVER_FQDN to the fully-qualified
# domain name of your host serving GitLab.
sudo editor /etc/nginx/sites-available/gitlab
Restart
sudo service nginx restart
Done!
如果到这里还不能通过浏览器访问,一定记得重启一次物理服务器,重启就好了
Visit YOUR_SERVER for your first GitLab login. The setup has created an admin account for you. You can use it to log in:
admin@local.host
5iveL!fe
Important Note: Please go over to your profile page and immediately change the password, so nobody can access your GitLab by using this login information later on.

Enjoy!

【原创】bulk adding users in owncloud automatically

http://forum.owncloud.org/viewtopic.php?f=3&t=2477 presented a way to add a lot of users into owncloud automatically. But I have a another way to do it. My solution is use chrome extension. You can download source code of this extension from https://www.dropbox.com/s/gj0cwzrklel6vkj/ownCloudUsers.zip.
Extract to folder "d:\", it will create a folder named "ownCloudUsers",open the folder and open file named popup.js.

CODE: SELECT ALL
$(document).ready(function(){
    $("#showAnnotation").click(function(){
          chrome.tabs.getSelected(null,function(tab) {
               var usernames=["jsjx","wlgcx","rjgcx","szjsx","jcjxb","zxsys","xsgzbgs","jwbgs","xyxz","jsjxy"];
               for(i=0;i                    var execode='addUser("' + usernames[i] + '")';
                    chrome.tabs.executeScript(null,{code:execode});
                    setTimeout("donothing()",3000);
            }
        });
    });
});

function donothing(){
}


We see an array named usernames stored all user name that we want to add. change content of this array. The password of all new users is setted to "123456" which can be modified in file contentscript.js.

CODE: SELECT ALL
function addUser(userid){
   $('#newusername').val(userid);
   $('#newuserpassword').val('123456');
   $('#newuser input:submit').click();
}


You can modify the usernames array to a two-dimension array so that it can store username and password at same time. and pass username and password to function addUser so that you can specify different password for every user.
Open file named manifest.json and change YourDomain to actually value or IP address, then save it.

CODE: SELECT ALL
{  
  "name": "ownCloud bulk users",
  "version": "0.0.1",  
  "manifest_version": 2,
  "description": "ownCloud  bulk users",
  "browser_action": {
        "default_title": "ownCloud  bulk users",
        "default_icon": "add.png",
        "default_popup": "popup.html"
  },
  "permissions": [
    "tabs","http://YourDomain/owncloud/index.php/settings/users"
  ],
  "content_scripts": [
    {
      "matches": ["http://YourDomain/owncloud/index.php/settings/users"],
      "js": ["jquery-1.8.3.js","contentscript.js"]
    }
  ],
  "web_accessible_resources":["add.png","images/*.png"]
}


Open chrome broswer, open menu item Tools|extensions, Then click button "load unpacked extension" and select folder "d:\ownCloudUsers". A new icon will appear at right-top position of chrome. Log into owncloud web app and go to user manage interface. click the icon of extension just installed, there will be a small popup window with an button inside. click the button, users will be added automatically.

Notice: the extension can't specify group for user.

最近一次刷T959 ROM历程

1、准备刷机,为了追求系统的干净,双wipe,然后format sd card,在格式化时把所有能格式化的全部格式化了
2、重新开机,手机没系统,不断重新启动
3、按3键进入挖煤模式,用odin刷很久之前下载的liroid rom,刷完重启手机提示
Can't mount /dev/block/mmcblk0p1
can't mount DATA
apk无法完成安装,重启手机,不停在开机界面重启
4、重复若干次进入挖煤模式,刷机均无果
5、在一次挖煤模式时,重启了手机。自此手机屏幕出现一个手机、一个电脑和一个惊叹号图案。无法进入挖煤状态
6、查资料,在扣掉电池之后,连接数据线,按住音量加减按钮,接上电池,重新进入挖煤模式
7、下载了i9000的原厂ROM,odin刷机成功,但是安卓版本低,且为英文版
8、尝试再次挖煤无果,原厂ROM锁了三键
9、自制挖煤神器,进入挖煤模式,再刷T959 ROM成功
10、拷贝CM10 zip到SDCARD,进入recovery模式,双wipe,install from zip刷CM10成功
------期间刷过国内力卓做的安卓4.1 ROM,里边捆绑了一堆软件,卸载之后一直出错,无奈又用adb命令进入恢复模式重新刷ROM

2012年12月20日星期四

Hibernate中findById时出现org.hibernate.MappingException: Unknown entity:的解决办法

 

原因:在使用myeclispe生成pojo和DAO代码后,对相关类进行了重构,改变了包。造成反射时找不到类。

出现错误的findById代码

public Trace findById(Long id) {
        log.debug("getting Trace instance with id: " + id);
        try {
            Trace instance = (Trace) getHibernateTemplate().get("Trace", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }

 

修改后的方法

public Trace findById(Long id) {
        log.debug("getting Trace instance with id: " + id);
        try {
            Trace instance = (Trace) getHibernateTemplate().get("cn.cslg.Trace", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }

2012年12月16日星期日

VMware无法识别USB设备的解决方法

我的虚拟机上认不到USB设备,发现是VMware USB Arbitration Service服务没有启动,手动启动VMware USB Arbitration Service服务,再重启VMware,虚拟机就能识别出USB设备了。

具体步骤:
1.点击开始->运行,在对话框中输入"services.msc",确定,打开windows服务管理器。

2.在服务列表中选中"VMware USB Arbitration Service",双击打开属性对话框,再选择"启动",就能启动VMware USB Arbitration Service服务了。

3.关闭VMware软件,并重新打开,启动一个虚拟机,进入系统之后VMware就会提示发现USB设备。如果要在虚拟机中使用这些USB设备(以USB摄像头为例),在VMware的菜单栏中选择VM->Removable Devices->Pixart Imaging CIF Single Chip->Connect (Disconnect form host) ,就可以了。当然,这样USB设备在连接到虚拟机的同时会断开同主机(一般为Windows系统)的连接。如果想重新在主机上使用USB设备,则在VMware菜单栏中选择VM->Removable Devices->Pixart Imaging CIF Single Chip->Disconnect (Connect to host) 。

另外补充一点:如果是AMD平台的机器,有可能会出现无法启动VMware USB Arbitration Service服务,这是AMD主板驱动中的"USB过滤器"所导致的。

解决办法是:在AMD主板驱动中,选择"ATI catalyst管理器",里面有选择"usb 过滤管理器",将其卸载之后即可启动VMware USB Arbitration Service服务。