블로그 이미지
언제나 늘 푸른 소나무처럼. 자신의 의지로 오롯이 서기
예섬수진

공지사항

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

Rails]Rails를 이용한 DB Table 생성(sqlite3)

2009. 12. 14. 23:25 | Posted by 예섬수진
rails web으로 기본 골격 생성

cd web
rake db:create로 DB 생성

ruby script/generate model build_info build_type:string model_name:string build_time:string rom_file:string 로 model 생성
  ※ model을 이용하면 DB의 CRUD를 할 수 있음
  ※ 나는 model 이름을 build_info라고 하였으나, 실제 모델 이름은 BuildInfo 임
       - web\app\models\build_info.rb
class BuildInfo < ActiveRecord::Base
            end

rake db:migrate DB에서 적용안된 내용을 적용하기 위함

생성된 table 이름 확인
  - web\db\schema.db에 가면, build_infos로 테이블이 생성된 것을 확인할 수 있음
       create_table "build_infos", :force => true do |t|
         t.string   "build_type"
         t.string   "model_name"
         t.string   "build_time"
         t.string   "rom_file"
         t.datetime "created_at"
         t.datetime "updated_at"
       end

Mapping
   - web\config\routes.rb에서 다음 라인을 2째 줄에 추가함
       map.resources :build_infos

ruby script/generate controller build_info add get를 이용하여 Controller 생성
   1. web\app\controllers\build_info_controller.rb 수정
       class BuildInfoController < ApplicationController
          def add
             @build_type = params['build_type']
             @model_name = params['name']
             @build_time = params['started_at']
             @rom_file = params['rom_file']
             BuildInfo.create(:build_type => @build_type, :model_name => @model_name, :build_time => @build_time, :rom_file => @rom_file)
 
             @build_infos = BuildInfo.all
             respond_to do |format|
                 format.html # add.html.erb
                 format.xml  { render :xml => @build_infos }
             end
          end

          def get
              @build_infos = BuildInfo.all
              respond_to do |format|
                   format.html # get.html.erb
                   format.xml  { render :xml => @build_infos }
              end
           end
        end

    2. web\app\views\build_info의 add.html.erb/get.html.erb를 아래와 같이 수정함
        <h1>Listing build_info</h1>
        <table>
              <% @build_infos.each do |build_info| %>
                <tr>
                     <td><%=h build_info.build_type %></td>
                     <td><%=h build_info.model_name %></td>
                     <td><%=h build_info.build_time %></td>
                     <td><%=h build_info.rom_file %></td>
                </tr>
              <% end %>
         </table>

웹서버 실행을 ruby script/server를 실행함

DB Table에 해당 Record가 삽입되었는지 확인하려면, 주소창에 다음을 입력함
http://localhost:3000/build_info/add?build_type=target&name=BlueMT&started_at=091214_12000&rom_file=kernrom 


Ant]pass parameter

2009. 12. 12. 14:18 | Posted by 예섬수진
in cmd prompt
     ant -buildfile build_xxx.xml -Dparam_name1=param_value1 -Dparam_name2=param_value2

in build_xxx.xml
     ${param_value1} ${param_value2}

rails를 이용한 Web Application 만들기

2009. 12. 6. 16:40 | Posted by 예섬수진

1. rails를 이용한 기본 프로젝트 생성
rails blog

2. SQLite3 설치 (on Win32)
  1) cd blog (in cmd prompt)

  2) http://www.sqlite.org/download.html 에서 Precompiled Binaries For Windows에서 sqlitedll.zip Download. 
 
  3) 압축 해제 후, 2개의 파일(def, dll)을 ruby 설치 폴더\bin이나 c:\Windows\System32에 복사함
     ※ http://www.skorks.com/2009/08/installing-and-using-sqlite-with-ruby-on-windows/

  4) gem install sqlite3-ruby --include-dependencies

3. blog 프로젝트를 위한 DB 생성
   - cd blog
   - rake db:create

4. "Hello, Worlds" 출력
    1) ruby script/generate controller home index

    2) blog 폴더 내 app\views\home\index.html.erb 파일에서 내용을 지우고 다음과 같이 적임
      <h1>hello, world</h1>

    3) Web Server의 실행을 위해, 다음을 입력함
        ruby script/server

    4) In Web browser, 주소창에 http://localhost:3000/home/index를 입력하면 "hello, world"가 보임

5. Default Page 대신 "hello, world" Page 보여 주기
    1) rm public/index.html

    2) Open config\routes.rb using a edit program, write following 1st line
      map.root :controller => "home"
      map.connect ':controller/:action/:id'
      map.connect ':controller/:action/:id.:format'

      * routes.rb : tells Rails how to connect incoming request to controllers and actions.

    3) In web-browser, 주소창에 http://localhost:3000를 입력하면 "hello, world"가 보임



 

Mongrel 설치 & 실행 on Win32

2009. 12. 5. 16:37 | Posted by 예섬수진
1. Ruby 설치 (V1.8.6)
  ※ Ruby 설치 버젼 확인 : ruby -v

2. RubyGem Update 
   1) RubyForge에서 최신 RubyGem 압축 파일(.zip)을 받음
   2) 로컬에서 압축을 푼 후, cmd prompt에서 그 압축 폴더로 이동함
   3) ruby setup.rb를 입력함

  ※ 또는 cmd propt에서 gem update --system을 입력함

3. Rails 설치
    gem install rails --include-dependencies

4. Mongrel 설치
    gem install mongrel --include-dependencies
    gem install mongrel_service --include-dependencies
    gem install win32-service --include-dependencies

5. Mongrel 설치 확인
    mongrel_rails start -h

6. Rails를 이용한 Web Application 작성
   http://www.advanceecomsolutions.com/resources/developing_web_applications_using_Ruby_on_Rails_framework.asp
   rails web_application_name

7. Mongrel을 이용한 Web Server 실행
   web_application_foloder]mongrel_rails start -p port_num -a host_ip
    ※ Web Server 실행 확인 : http://host_ip:port_num
 

pthread_creat( )를 한 이후, main thread는 child thread( )가 종료될 때까지 기다린다.
-> pthread_join( )의 역할

하지만, 이 경우 thread가 종료되어도 child thread의 자원은 반환되지 않는다!!

그러므로 child thread가 종료되기 전에 pthread_exit( ) 함수를 호출해야 한다.

pthread_join ( )가 호출될 때, child thread( )의 resource를 반환한다.

'컴퓨터 > C/C++' 카테고리의 다른 글

C++]pure virtual function 컴파일 에러  (0) 2011.04.28

Python] Linux에서 Python 설치

2009. 10. 21. 21:18 | Posted by 예섬수진
Linux에는 기본적으로 Python이 설치되어 있다. 설치된 Python 버젼이 낮을 때는 아래와 같이 Upgrade해 보자.

(1) Python 실행 파일 위치 및 버젼 알기
which python         --> /usr/bin/python
python -V              --> 2.4

(2) 설치하고 싶은 버젼의 tar 파일을 Linux 컴퓨터에 저장
Ex> /opt/Python-2.5.4.tar
(3) tar 파일 압축 풀기
tar -zxvf Python-2.5.4.tar

(4) Python 설치
압축 해제된 폴더 내에서, 다음 명령어를 수행함
1) ./configure
2) make
3) make install
이렇게 하면 압축 해제된 폴더 내에 실행가능한 python 파일이 생김

실행해 보면 설치하려고 했던 버젼의 python이 실행됨

(5) Symbolic Link 걸기
1) /usr/bin/python에 Symbolic link가 걸려 있는지 확인함
2) 안걸려 있다면 파일 이름을 변경함
Ex> mv python python-2.4
3) Symbolic Link 걸기
ln -s /opt/Python-2.5.4/python /usr/bin/python

'컴퓨터 > Python' 카테고리의 다른 글

Python]한글 입력  (0) 2010.01.20
Python] 다른 프로그램 실행  (0) 2010.01.19
Python]Get child directory  (0) 2009.10.09
Python] 오늘의 날짜 시간 구하기  (0) 2009.10.07
Python]파일의 수정 날짜 출력하기  (0) 2009.10.06

Python]Get child directory

2009. 10. 9. 16:15 | Posted by 예섬수진
특정 폴더의 바로 밑에 해당하는 폴더명 구하기

 for sub_path in os.listdir(rc_result_folder):
  sub_dir = os.path.join(rc_result_folder, sub_path)
  if os.path.isdir(sub_dir):
   print 'rc model = ' + sub_dir
   # end of if
 # end of for

Python] 오늘의 날짜 시간 구하기

2009. 10. 7. 16:16 | Posted by 예섬수진
>>> import datetime
>>> now = datetime.datetime.now()
>>> now
datetime.datetime(2009, 10, 7, 16, 1, 34, 137000)
>>> now.strftime("%y.%m.%d")
'09.10.07'
>>> now.strftime("%H:%M")
'16:01'

Python]파일의 수정 날짜 출력하기

2009. 10. 6. 15:05 | Posted by 예섬수진
import os
import time

filestat = os.stat('\\\\101.881.166.231\\Cruisecontrol\\Prevent\\Source\\cambr
ia.zip')

print time.strftime('%y.%m.%d', time.localtime(filestat.st_mtime))
# 접근한 날짜 : st_atime
# 수정한 날짜 : st_mtime
# 만든 날짜 : st_ctime

출력 결과 : 09.10.02

Python] SSH connection using Paramiko on Windows OS

2009. 9. 13. 15:46 | Posted by 예섬수진
Python 자체에서 SSH를 지원해 주지 않았다.

그래서 나는 paramiko를 이용하였다.

1. 설치 방법
  (1) pycrypto 설치
     - http://www.voidspace.org.uk/python/modules.shtml#pycrypto
       . Python version에 맞게 설치함
         
  (2) Paramiko 설치
     - 공식 URL : http://www.lag.net/paramiko/

     - 공식 URL이 아닌 Windows용으로 Binary 파일이 생성된 것을 이용하겠음
        . URL : http://bazaar-vcs.org/WindowsInstall
         
2. 설치 확인
  - 아래와 같이 import paramiko를 적었을 때 error가 안 나면 됨

3. 사용 방법
import paramiko

# SSHClient 인스턴스 생성
client = paramiko.SSHClient()

# 저장된 Host 키값이 없으면 Policy에 따라 자동적으로 Host 키값 추가
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

# SSH 접속 정보 입력
client.connect(hostname='ipaddress', username='ID', password='PW')

# 실행할 커맨드 입력
stdin, stdout, stderr = client.exec_command("ls -al")

# SSH에서 결과로 뿌려주는 output 출력 (stdout)
for line in stdout:
     print line.strip('\n')

# 접속 종료
client.close()

'컴퓨터 > Python' 카테고리의 다른 글

Python] 다른 프로그램 실행  (0) 2010.01.19
Python] Linux에서 Python 설치  (0) 2009.10.21
Python]Get child directory  (0) 2009.10.09
Python] 오늘의 날짜 시간 구하기  (0) 2009.10.07
Python]파일의 수정 날짜 출력하기  (0) 2009.10.06
이전 1 ··· 3 4 5 6 7 다음