2019年7月24日 星期三

pyenv-win 安裝與移除

https://github.com/pyenv-win/pyenv-win

1. Install
pip install pyenv-win --target %USERPROFILE%/.pyenv

2. Add following to PATH enviroment variable
%USERPROFILE%\.pyenv\pyenv-win\bin;%USERPROFILE%\.pyenv\pyenv-win\shims;

3. Add installed path in file easy_install.pth to site-packages folder(ex: C:\Users\Jack_Lin\AppData\Local\Programs\Python\Python37-32\Lib\site-packages).
Need to add absolute path, ex:
C:\Users\Jack_Lin\.pyenv in file easy_install.pth

4. pip list to check pyenv-win is installed and recognize by pip

5. upgrade
pip install --upgrade pyenv-win

6. uninstall
pip uninstall pyenv-win

2019年6月14日 星期五

如何push本地branch並覆蓋remote branch


git push -f --set-upstream origin master
git push -f  要小心使用

2019年5月20日 星期一

Scrapy學習筆記

若要整合Django和Scrapy,可利用DjangoItem,可節省定義Item的部分,讓Scrapy的Item定義自動去參照Django model,也可在Item增加欄位。

ItemLoader的部分,預設add_value後,postprocessor都會以list為最後輸出結果,可更感post processor為TakeFirst。

在Pipeline裡,若應用到DjangoItem,要先save後,在以Django model來操作 Foreign Key或是ManyToManyField部分。DjangoItem無法直接取得Django model內容。DjangoItem只是取去參考Django model,省去寫 field_xxx = scrapy.Field()而已。

2019年4月24日 星期三

pandas Dataframe操作

import pandas as pd
df = pd.read_excel('b.xlsx', 'Acceptance')
df[df['Config 3'].notna()]

裡面的df['Config 3'].notna()是filter的方式,結果是列出所有Config13欄位不是na的 rows

Pandas的Series是縱向的,例如某個Column的值的列表

pandas兩個主要的data structure
DataFrame和Series
DataFrame就是Series的容器
Series就是純量的容器

Indexing / Selection

The basics of indexing are as follows:
OperationSyntaxResult
Select columndf[col]Series
Select row by labeldf.loc[label]Series
Select row by integer locationdf.iloc[loc]Series
Slice rowsdf[5:10]DataFrame
Select rows by boolean vectordf[bool_vec]DataFrame

如果要一個row一個row去做動作
df.iterrows()

2019年3月7日 星期四

Delopy Django project on Ubuntu 1804 with mod_wsgi

1. Install apache2 & postgresql
2. Install mod_wsgi
# sudo apt install libapache2-mod-wsgi-py3
3. Create a Python3 virtualenv
# mkvirtualenv -p $(which python3) django & psycopg2-binary
(django)# pip install django
(django)# pip install psycopg2-binary
4. Enter into project folder. /home/jack/Documents/Projects/myproject
5. Install Requirement python package
(django) # pip install -r requirements.txt
6. Note that the wsgi.py is put on /home/jack/Documents/Projects/myproject/myproject
7. Edit settings.py in ./myproject
Add ALLOWED_HOSTS = ['*',]
(This is risky)
Add STATIC_ROOT = '/home/jack/Documents/Projects/myproject/static'
8. Setup Postgresql database correctly & create a database in it.
9. Edit settings.py to meet the database you want to use.
10. Database Migrate & collectstatic
(django) # python manage.py migrate
(django) # python manage.py collectstatic
11. create a new conf in /etc/apache2/site-available myproject.conf with sudo

    ServerName myproject
    Alias /robots.txt /home/jack/Documents/Projects/myproject/static/static/robots.txt
    Alias /favicon.ico /home/jack/Documents/Projects/myproject/static/favicon.ico
    Alias /static/ /home/jack/Documents/Projects/myproject/static/
   
        Require all granted
   
    WSGIDaemonProcess django python-home=/home/jack/.virtualenvs/django/ python-path=/home/jack/Documents/Projects/myproject/
    WSGIScriptAlias / /home/jack/Documents/Projects/myproject/myproject/wsgi.py
    WSGIProcessGroup django
   
       
        Require all granted
       
   

12. Edit /etc/apache2/ports.conf, Add a line
Listen 4002
13. Enable the site & reload
# sudo a2ensite myproject
# sudo systemctl reload apache2
14. Allow port 4002 in Firewall
# sudo ufw allow 4002


Reference:
https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/
https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/

2018年10月22日 星期一

TestLink setup on CentOS 7

#Install PostgreSQL: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-centos-7
# sudo yum install postgresql-server postgresql-contrib
# sudo postgresql-setup initdb
# sudo systemctl start postgresql
# sudo systemctl enable postgresql

https://dotblogs.com.tw/jovepaterlab/2017/04/17/222958
[root@localhost peter]# su - postgres
-bash-4.2$ psql -U postgres
psql (9.6.2)
Type "help" for help.

postgres=# ALTER USER postgres WITH PASSWORD 'password'
postgres-# \q
-bash-4.2$ exit
logout

Edit /var/lib/pgsql/data/pg_hba.conf
local    all             all                                    md5
host    all             all             127.0.0.1/32            md5
host    all             all             ::1/128                 md5

https://www.tecmint.com/install-php-7-in-centos-7/
# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
# yum-config-manager --enable remi-php72
# yum install php php-mcrypt php-cli php-gd php-curl php-pgsql php-ldap php-zip php-fileinfo
# php -v

Enable Apache2
# systemctl start httpd
# systemctl enable httpd

Edit /etc/php.ini
session.gc_maxlifetime = 2400
max_input_vars = 3000
memory_limit = 256M
upload_max_filesize = 20M
max_execution_time = 120


Set MySQL password
mysqladmin -u root password password

# Copy Testlink source code
# wget -e use_proxy=yes -e https_proxy=jack_lin3.compal.com:3128 https://github.com/TestLinkOpenSourceTRMS/testlink-code/archive/testlink_1_9.zip
   47  unzip
# unzip testlink_1_9.zip -d /var/www/html/
# cd /var/www/html/
# ls
# mv testlink-code-testlink_1_9/ testlink/
# ls
# chown -R apache:apache testlink
mkdir  /var/testlink
mkdir /var/testlink/logs
mkdir /var/testlink/upload_area
chown apache:apache /var/testlink/logs
chown apache:apache /var/testlink/upload_area


Check firewall setting
https://linuxhint.com/list_open_ports_firewalld/
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-using-firewalld-on-centos-7

Add http service in firewall
# sudo firewall-cmd --zone=public --permanent --add-service=http

link1
link2
# sudo chcon -Rv --type httpd_sys_rw_content_t /var/www/html/testlink/gui/templates_c
##### chcon -Rv --type httpd_sys_rw_content_t /var/www/html/testlink
https://tripal.info/tutorials/v3.x/installation/server-setup/centos7
# setsebool -P httpd_can_network_connect_db on

Remove line 872~879
/install/sql/postgres/testlink_create_tables.sql
https://github.com/TestLinkOpenSourceTRMS/testlink-code/blob/testlink_1_9/install/sql/postgres/testlink_create_tables.sql


Open http:///testlink, Follow steps to install.

YOU NEED TO RUN MANUALLY Following Script on your DB CLIENT Application

/var/www/html/testlink/install/sql/postgres/testlink_create_udf0.sql


YOUR ATTENTION PLEASE:
To have a fully functional installation You need to configure mail server settings, following this steps

    copy from config.inc.php, [SMTP] Section into custom_config.inc.php.
    complete correct data regarding email addresses and mail server.


Installation was successful!
You can now log in to Testlink (using login name:admin / password:admin - Please Click Me!).