--- /dev/null
+DongHee Yang <donghee.yang@samsung.com>
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+HyunGoo Kang <hyungoo1.kang@samsung.com>
--- /dev/null
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
--- /dev/null
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
--- /dev/null
+Tizen SDK Development Guide
+
+
+Contents
+========================================
+
+1 Introduction
+2 Setup Build Environment
+2.1 Linux(Ubuntu)
+2.1.1 Install Tizen SDK
+2.1.2 Install Ruby
+2.1.3 Install Packages needed by DIBS
+2.1.4 Install Pre-Requisite Packages
+2.1.5 More
+2.2 Windows
+2.2.1 Install Tizen SDK
+2.2.2 Install Ruby
+2.2.3 Install Packages needed by DIBS
+2.2.4 Install MSYS GIT
+2.2.5 More
+3 Simple Build and Test
+3.1 Build Package
+3.2 Install Package
+3.3 Launch your own SDK
+4 More DIBS commands
+4.1 List Up Available Packages
+4.2 Update Package List
+4.3 Upgrade Packages
+4.4 Install SDK
+
+
+1 Introduction
+========================================
+
+Tizen SDK is composed of many separated packages which are has their own dependencies. And DIBS(Distributed Intelligent Build System) is the build system designed for building that kind of complexity. It provides various features.
+* Has own packaging system and packaging interface
+* Provides distributed package server/build Server
+* Provides Automatic dependency checker/resolver
+* Provides client/server tools which are easy to use
+This guides will show how to build Tize SDK packages using DIBS
+
+
+2 Setup Build Environment
+========================================
+
+2.1 Linux(Ubuntu)
+
+2.1.1 Install Tizen SDK
+Install the SDK first
+
+2.1.2 Install Ruby
+To use DIBS, you have to install Ruby 1.8.7
+
+ $ sudo apt-get install ruby
+
+Higher version of Ruby is not tested yet!
+
+2.1.3 Install Packages needed by DIBS
+
+ $ sudo apt-get install wget zip unzip
+
+2.1.4 Install Pre-Requisite Packages
+To build or develop SDK , you have to install following packages
+* For emulator development
+ bcc bison flex autoconf gcc libglu1-mesa-dev libsdl1.2-dev libgtk2.0-dev libsdl-image1.2-dev libsdl-gfx1.2-dev debhelper libxml2-dev libasound2-dev libx11-dev zlib1g-dev uuid-dev libv4l-dev
+* GDB 7.2
+ quilt libncurses5-dev libexpat1-dev libreadline-dev mingw32(only for building windows version)
+* GCC 4.5
+ quilt texinfo bison flex mingw32(only for building windows version)
+
+ $ sudo apt-get install {pre-requisite packages}
+
+2.1.5 More
+For your convenience,
+* Add DIBS path to $PATH. Edit shell configuration. ex) .bashrc
+
+ $ export PATH={SDK Install dir}/dev-tools:$PATH
+
+2.2 Windows
+
+2.2.1 Install Tizen SDK
+Install the SDK first
+
+2.2.2 Install Ruby
+* You can download Ruby binary at ..
+ ftp://ftp.ruby-lang.org/pub/ruby/binaries/mswin32/ruby-1.8.7-i386-mswin32.zip
+ http://rubyforge.org/frs/download.php/75679/rubyinstaller-1.8.7-p357.exe
+
+2.2.3 Install Packages needed by DIBS
+* Login MinGW provided by Tizen SDK. Execute following windows BAT file.
+
+ {Tizen-Install Dir}/MinGW/msys/1.0/msys.bat
+
+* Execute the following commands on MinGW environment
+
+ $ mingw-get.exe update
+ $ mingw-get.exe install msys-wget
+ $ mingw-get.exe install msys-zip
+ $ mingw-get.exe install msys-unzip
+
+2.2.4 Install MSYS GIT
+* Download the MSYS binary
+ http://msysgit.googlecode.com/files/Git-1.7.9-preview20120201.exe
+
+* Install it
+
+2.2.5 More
+For your convenience,
+* Add "/usr/bin/ruby" shell script
+
+ #!/bin/sh
+ {ruby install dir}/bin/ruby.exe $@
+
+ ex)
+
+ #!/bin/sh
+ /c/Ruby187/bin/ruby.exe $@
+
+* Add "/usr/bin/git" shell script
+
+ #!/bin/sh
+ {MSYS GIT install dir}/bin/ruby.exe $@
+
+ ex)
+
+ #!/bin/sh
+ /c/Program\ Files/Git/bin/it.exe $@
+
+* Add DIBS path to $PATH. Edit shell configuration. ex) /etc/profile
+
+ $ export PATH={SDK Install dir}/dev-tools:$PATH
+
+
+3 Simple Build and Test
+========================================
+
+If you downloaded a SDK package source and modified it, then you want to build it and apply it to Tizen SDK. Here is the simple process to do it.
+
+3.1 Build Package
+Building a SDK package is very simple. Here is the command for buiding package.
+
+ ## pkg-build [-u <package server url>] [-o <os>] [-c <clean>] [-r <reverse build dependency check>]
+ ## -u : Package server URL which contains binary and development packages.
+ ## If ommited, it will use previous server URL.
+ ## -o : Target OS(linux or windows)
+ ## -c : Clean build""
+ ## If set, start build after downloading all dependent packages
+ ## If not set, it will not download dependent packages if already downloaded
+ ## -r : Check reverse-build-dependency
+ ## This option will check that the packages which depend on me can be built
+
+And Here are simple steps
+ 1. Move to source directory
+ ex)
+
+ $ cd ~/project/common-eplugin
+
+ 2. Type the command
+ ex)
+
+ $ pkg-build -u http://172.21.17.55/dibs/unstable
+
+ 3. Now you can see the package files( *.zip, *.tar.gz ) in your source directory
+
+3.2 Install Package
+Installing a SDK package is also very simple. Here is the command for installing package files
+
+ ## pkg-cli install-file -p <package file path> [-l <location>] [-f]
+ ## -p : Binary package file(*.zip) path which you want to install
+ ## -l : Install root location of target SDK
+ ## If omitted, current working directory path will be set
+ ## -f : Install the package by force
+ ## This option will allow installing the package that has lower or equal version compare to installed
+
+Now let's assume that you have just finished building and have a Tizen SDK installation on '~/tizen_sdk'
+ 1. Just type the command
+ ex)
+
+ $ pkg-cli install-file -p common-eplugin_0.20.6_linux.zip -l ~/tizen_sdk
+
+3.3 Launch your own SDK
+Now you can check your modifications. Lauch your SDK!!
+ 1. type the following command or use the short-cut for launching Tizen SDK.
+ ex)
+
+ $ ~/tizen_sdk/IDE/startup.sh
+
+
+4 More DIBS commands
+========================================
+
+There are more useful commands provided
+
+4.1 List Up Available Packages
+You can list up available packages of server.
+
+ ## pkg-cli list-rpkg [-o <os>] [-u <package server url>]
+ ## -o : Target OS(linux or windows)
+ ## -u : Package server URL which contains binary and development packages.
+ ## If ommited, it will use previous server URL.
+
+ 1. List up packages
+ ex)
+
+ $ pkg-cli update -u http://172.21.17.55/dibs/unstable_release
+
+ ex)
+
+ $ pkg-cli list-rpkg
+
+ 2. List up packages with updating
+ ex)
+
+ $ pkg-cli list-rpkg -u http://172.21.17.55/dibs/unstable_release
+
+You can list up packages of your install directory
+
+ ## pkg-cli list-lpkg [-l <locatio>]
+ ## -l : Install root location of target SDK
+ ## If omitted, current working directory path will be set
+
+ 1. List up packages
+ ex)
+
+ $ pkg-cli list-lpkg -l ~/tizen_sdk
+
+4.2 Update Package List
+You should have package list of server in your host before listing, installing and downloading packages. So, if you want to install the latest package, then you should update your package list before installing.
+
+ ## pkg-cli update [-u <package server url>]
+ ## -u : Package server URL which contains binary and development packages.
+ ## If ommited, it will use previous server URL.
+
+ 1. Update package list from server
+ ex)
+
+ $ pkg-cli update -u http://172.21.17.55/dibs/unstable_release
+
+ 2. Install / download packages from server
+ ex)
+
+ $ pkg-cli install -p nativeapp-eplugin -l ~/tizen_sdk
+
+ ex)
+
+ $ pkg-cli install -p unittest-eplugin -l ~/tizen_sdk
+
+ ex)
+
+ $ pkg-cli download -p base-ide-product -l ~/downloads
+
+ 3. If package is updated on server and you want to use is, you should update your package list. If you do not set the server url, it will be set previous server URL.
+ ex)
+
+ $ pkg-cli update
+
+ ex)
+
+ $ pkg-cli install -p nativeapp-eplugin -l ~/tizen_sdk
+
+4.3 Upgrade Packages
+You can upgrade your installed packages from server.
+
+ ## pkg-cli upgrade -l <location> -u <package server url>
+ ## -u : Package server URL which contains binary and development packages.
+ ## If ommited, it will use previous server URL.
+ ## -l : Install root location of target SDK
+ ## If omitted, current working directory path will be set
+
+ 1. Check package for upgrading
+ ex)
+
+ $ pkg-cli update -u http://172.21.17.55/dibs/unstable_release
+ $ pkg-cli check-upgrade -l ~/tizen_sdk
+
+ 2. Upgrade packages
+ ex)
+
+ $ pkg-cli upgrade -l ~/tizen_sdk
+
+ 3. Upgrade packages with updating
+ ex)
+
+ $ pkg-cli upgrade -l ~/tizen_sdk -u http://172.21.17.55/dibs/unstable_release
+
+ 4. If you want to upgrade specific package, you can upgrade it as installing
+ ex)
+
+ $ pkg-cli install -p common-eplugin -l ~/tizen_sdk -u http://172.21.17.55/dibs/unstable_release
+
+4.4 Install SDK
+You can also install new SDK using the network install command. Originally this command is used for installing packages by network. But you can set "TIZEN-SDK" as package name, all Tizen SDK packages will be installed.
+
+ ## pkg-cli install -p <package name> [-u <package server url>] [-l <location>] [-t] [-f]
+ ## -p : Binary package name which you want to install
+ ## -u : Package server URL which contains binary and development packages.
+ ## If ommited, it will use previous server URL.
+ ## -l : Install root location of target SDK
+ ## If omitted, current working directory path will be set
+ ## -t : Install the package with all dependent packages
+ ## -f : Install the package by force
+ ## This option will allow installing the package that has lower or equal version compare to installed
+
+ 1. Install "TIZEN-SDK" by network to new location("~/tizen_sdk2")
+ ex)
+
+ $ pkg-cli install -p TIZEN-SDK -l ~/tizen_sdk2 -t
+
+ 2. Change Tizen SDK configuration
+ ex)
+
+ $ echo "TIZEN_SDK_INSTALLED_PATH=/home/{username}/tizen_sdk2" > ~/.TizenSDK/tizensdkpath
+
+ 3. Launch your SDK!
+ ex)
+
+ $ ~/tizen_sdk2/IDE/startup.sh
+
--- /dev/null
+#!/usr/bin/ruby
+
+=begin
+
+ build-cli
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require "socket"
+require 'fileutils'
+$LOAD_PATH.unshift File.dirname(__FILE__)+"/src/common"
+$LOAD_PATH.unshift File.dirname(__FILE__)+"/src/build_server"
+require "utils"
+require "BuildClientOptionParser"
+require "BuildComm"
+
+#option parsing
+begin
+ option = option_parse
+rescue => e
+ puts e.message
+ exit 0
+end
+
+# if "--os" is not specified, use host os type
+if option[:os].nil? then
+ option[:os] = Utils::HOST_OS
+else
+ if not option[:os] =~ /^(linux|windows|darwin|all)$/ then
+ puts "We have no plan to Buld OS \"#{option[:os]}\" \n please check your option OS "
+ exit 1
+ end
+end
+
+if option[:domain].nil? then
+ option[:domain] = "127.0.0.1"
+end
+
+if option[:port].nil? then
+ option[:port] = 2222
+end
+
+begin
+ case option[:cmd]
+ when "build"
+ result = Utils.parse_server_addr(option[:domain])
+ if result.nil? then
+ puts "Server address is incorrect. (#{option[:domain]})"
+ puts "Tune as following format."
+ puts " <ip>:<port>"
+ exit 1
+ end
+ client = BuildCommClient.create( result[0], result[1], 0 )
+ if not client.nil? then
+ client.send "BUILD,GIT,#{option[:project]},#{option[:passwd]},#{option[:os]},#{option[:async]}"
+ client.print_stream
+ client.terminate
+ else
+ puts "Connection to server failed!"
+ exit 1
+ end
+ when "resolve"
+ result = Utils.parse_server_addr(option[:domain])
+ if result.nil? then
+ puts "Server address is incorrect. (#{option[:domain]})"
+ puts "Tune as following format."
+ puts " <ip>:<port>"
+ exit 1
+ end
+ client = BuildCommClient.create( result[0], result[1], 0 )
+ if not client.nil? then
+ client.send "RESOLVE,GIT,#{option[:project]},#{option[:passwd]},#{option[:os]},#{option[:async]}"
+ client.print_stream
+ client.terminate
+ end
+ when "query"
+ result = Utils.parse_server_addr(option[:domain])
+ if result.nil? then
+ puts "Server address is incorrect. (#{option[:domain]})"
+ puts "Tune as following format."
+ puts " <ip>:<port>"
+ exit 1
+ end
+ # SYSTEM INFO
+ client = BuildCommClient.create( result[0], result[1], 0 )
+ if not client.nil? then
+ client.send "QUERY,SYSTEM"
+ result0 = client.receive_data()
+ if result0.nil? then
+ client.terminate
+ exit(-1)
+ end
+ result0 = result0[0].split(",").map { |x| x.strip }
+ puts "HOST-OS: #{result0[0]}"
+ puts "MAX_WORKING_JOBS: #{result0[1]}"
+ client.terminate
+ else
+ puts "Connection to server failed!"
+ exit 1
+ end
+
+ # FTP INFO
+ puts ""
+ client = BuildCommClient.create( result[0], result[1], 0 )
+ if not client.nil? then
+ client.send "QUERY,FTP"
+ result0 = client.receive_data()
+ if result0.nil? then
+ client.terminate
+ exit(-1)
+ end
+ puts "* FTP *"
+ result0 = result0[0].split(",").map { |x| x.strip }
+ puts "FTP_ADDR: #{result0[0]}"
+ puts "FTP_USERNAME: #{result0[1]}"
+ client.terminate
+ else
+ puts "Connection to server failed!"
+ exit 1
+ end
+
+ # PROJECT INFO
+ puts ""
+ client = BuildCommClient.create( result[0], result[1], 0 )
+ if not client.nil? then
+ client.send "QUERY,PROJECT"
+ result1 = client.receive_data()
+ if result1.nil? then
+ client.terminate
+ exit(-1)
+ end
+ puts "* PROJECT(S) *"
+ for item in result1
+ tok = item.split(",").map { |x| x.strip }
+ type = (tok[0]=="G" ? "NORMAL":"REMOTE")
+ printf("%-25s %s\n",tok[1],type)
+ end
+ else
+ puts "Connection to server failed!"
+ exit 1
+ end
+
+ # JOB INFO
+ puts ""
+ client = BuildCommClient.create( result[0], result[1], 0 )
+ if not client.nil? then
+ client.send "QUERY,JOB"
+ result1 = client.receive_data()
+ if result1.nil? then
+ client.terminate
+ exit(-1)
+ end
+ puts "* JOB(S) *"
+ for item in result1
+ tok = item.split(",").map { |x| x.strip }
+ puts "#{tok[1]} #{tok[0]} #{tok[2]}"
+ end
+ else
+ puts "Connection to server failed!"
+ exit 1
+ end
+
+ when "cancel"
+ result = Utils.parse_server_addr(option[:domain])
+ if result.nil? then
+ puts "Server address is incorrect. (#{option[:domain]})"
+ puts "Tune as following format."
+ puts " <ip>:<port>"
+ exit 1
+ end
+ if not option[:job].nil? then
+ client = BuildCommClient.create( result[0], result[1], 0 )
+ if not client.nil? then
+ client.send "CANCEL,#{option[:job]},#{option[:passwd]}"
+ result1 = client.receive_data()
+ if result1.nil? then
+ client.terminate
+ exit(-1)
+ end
+ puts result1
+ else
+ puts "Connection to server failed!"
+ exit 1
+ end
+ else
+ puts "you must input \"cancel job number\"!!"
+ exit 1
+ end
+
+ when "register"
+ # check file exist
+ if not File.exist? option[:package] then
+ puts "The file does not exist!.. #{option[:package]}"
+ exit(-1)
+ end
+
+ result = Utils.parse_server_addr(option[:domain])
+ if result.nil? then
+ puts "Server address is incorrect. (#{option[:domain]})"
+ puts "Tune as following format."
+ puts " <ip>:<port>"
+ exit 1
+ end
+ bs_ip = result[0]
+ bs_port = result[1]
+
+ ftp_result = Utils.parse_ftpserver_url(option[:fdomain])
+ if ftp_result.nil? or ftp_result.length != 4 then
+ puts "FTP server url is incorrect. (#{option[:fdomain]})"
+ puts "Tune as following format."
+ puts " ftp://<usrename>:<passwd>@<address>"
+ exit 1
+ end
+ ip = ftp_result[0]
+ port = ftp_result[1]
+ username = ftp_result[2]
+ passwd = ftp_result[3]
+
+ # upload
+ client = BuildCommClient.create( bs_ip, bs_port, 0 )
+ if client.nil? then
+ puts "Can't access server #{bs_ip}:#{bs_port}"
+ exit(-1)
+ end
+ client.send("UPLOAD")
+ result = client.send_file(ip, port, username, passwd, option[:package])
+ client.terminate
+ if not result then
+ puts "Uploading file failed!.. #{option[:package]}"
+ exit(-1)
+ end
+
+ # register
+ client = BuildCommClient.create( bs_ip, bs_port, 0 )
+ if client.nil? then
+ puts "Can't access server #{bs_ip}:#{bs_port}"
+ exit(-1)
+ end
+ client.send("REGISTER,BINARY,#{File.basename(option[:package])},#{option[:passwd]}")
+ client.print_stream
+ client.terminate
+
+ # for test
+ when "upload"
+ # check file exist
+ if not File.exist? option[:file] then
+ puts "The file does not exist!.. #{option[:file]}"
+ exit(-1)
+ end
+
+ result = Utils.parse_server_addr(option[:domain])
+ if result.nil? then
+ puts "Server address is incorrect. (#{option[:domain]})"
+ puts "Tune as following format."
+ puts " <ip>:<port>"
+ exit 1
+ end
+
+ # FTP INFO
+ client = BuildCommClient.create( result[0], result[1], 0 )
+ if client.nil? then
+ puts "Can't access server #{result[0]}:#{result[1]}"
+ exit(-1)
+ end
+ client.send "QUERY,FTP"
+ result0 = client.receive_data()
+ if result0.nil? then
+ client.terminate
+ exit(-1)
+ end
+ result0 = result0[0].split(",").map { |x| x.strip }
+ ip = result0[0]
+ username = result0[1]
+ passwd = result0[2]
+ client.terminate
+
+ client = BuildCommClient.create( result[0], result[1], 0 )
+ if client.nil? then
+ puts "Can't access server #{result[0]}:#{result[1]}"
+ exit(-1)
+ end
+ client.send("UPLOAD")
+ result = client.send_file(ip, username, passwd, option[:file])
+ client.terminate
+ if not result then
+ puts "Uploading file failed!.. #{option[:file]}"
+ exit(-1)
+ else
+ puts "Uploading file succeeded!"
+ end
+
+ when "download"
+ result = Utils.parse_server_addr(option[:domain])
+ if result.nil? then
+ puts "Server address is incorrect. (#{option[:domain]})"
+ puts "Tune as following format."
+ puts " <ip>:<port>"
+ exit 1
+ end
+
+ # FTP INFO
+ client = BuildCommClient.create( result[0], result[1], 0 )
+ if client.nil? then
+ puts "Can't access server #{result[0]}:#{result[1]}"
+ exit(-1)
+ end
+ client.send "QUERY,FTP"
+ result0 = client.receive_data()
+ if result0.nil? then
+ client.terminate
+ exit(-1)
+ end
+ result0 = result0[0].split(",").map { |x| x.strip }
+ ip = result0[0]
+ username = result0[1]
+ passwd = result0[2]
+ client.terminate
+
+ # download
+ client = BuildCommClient.create( result[0], result[1], 0 )
+ if client.nil? then
+ puts "Can't access server #{result[0]}:#{result[1]}"
+ exit(-1)
+ end
+ file_name = option[:file]
+ client.send("DOWNLOAD,#{file_name}")
+ result = client.receive_file(ip, username, passwd, "./#{file_name}")
+ client.terminate
+ if not result then
+ puts "Downloading file failed!.. #{option[:file]}"
+ exit(-1)
+ else
+ puts "Downloading file succeeded!"
+ end
+ else
+ raise RuntimeError, "input option incorrect : #{option[:cmd]}"
+ end
+
+rescue => e
+ puts e.message
+ exit(-1)
+end
+
+exit 0
--- /dev/null
+#!/usr/bin/ruby -d
+
+=begin
+
+ build-svr
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require 'fileutils'
+$LOAD_PATH.unshift File.dirname(__FILE__)+"/src/common"
+$LOAD_PATH.unshift File.dirname(__FILE__)+"/src/build_server"
+require "utils"
+require "BuildServerOptionParser"
+require "BuildServerController"
+
+#option parsing
+begin
+ option = option_parse
+rescue => e
+ puts e.message
+ exit 0
+end
+
+
+# if "--os" is not specified, use host os type
+if option[:os].nil? then
+ option[:os] = "linux,windows"
+end
+
+begin
+ case option[:cmd]
+ when "create"
+ svr_result = Utils.parse_server_addr(option[:domain])
+ if svr_result.nil? or svr_result.length != 2 then
+ puts "Server address is incorrect. (#{option[:domain]})"
+ puts "Tune as following format."
+ puts " <ip>:<port>"
+ exit 1
+ end
+ ftp_result = Utils.parse_ftpserver_url(option[:fdomain])
+ if ftp_result.nil? or ftp_result.length != 4 then
+ puts "FTP server url is incorrect. (#{option[:fdomain]})"
+ puts "Tune as following format."
+ puts " ftp://<usrename>:<passwd>@<address>:<port>"
+ exit 1
+ end
+ pkgsvr_addr = svr_result[0]
+ pkgsvr_port = svr_result[1]
+ ftpsvr_addr = ftp_result[0]
+ ftpsvr_port = ftp_result[1]
+ ftpsvr_username = ftp_result[2]
+ ftpsvr_passwd = ftp_result[3]
+ BuildServerController.create_server( option[:name], Utils::WORKING_DIR, option[:url], pkgsvr_addr, pkgsvr_port, option[:pid], ftpsvr_addr, ftpsvr_port, ftpsvr_username, ftpsvr_passwd )
+ when "remove"
+ BuildServerController.remove_server( option[:name] )
+ when "start"
+ BuildServerController.start_server( option[:name], option[:port] )
+ when "stop"
+ BuildServerController.stop_server( option[:name] )
+ when "add-svr"
+ svr_result = Utils.parse_server_addr(option[:domain])
+ if svr_result.nil? or svr_result.length != 2 then
+ puts "Server address is incorrect. Tune as following format."
+ puts " <ip>:<port>"
+ exit 1
+ end
+ pkgsvr_addr = svr_result[0]
+ pkgsvr_port = svr_result[1]
+ BuildServerController.add_friend_server( option[:name], pkgsvr_addr, pkgsvr_port )
+ when "add-prj"
+ if not option[:git].nil? then
+ BuildServerController.add_project( option[:name], option[:pid],
+ option[:git], option[:branch], option[:remote], option[:passwd], option[:os] )
+ else
+ BuildServerController.add_binary_project( option[:name], option[:pid],
+ option[:package], option[:passwd], option[:os] )
+ end
+ when "fullbuild"
+ BuildServerController.build_all_projects( option[:name] )
+ when "register"
+ BuildServerController.register_package( option[:name], option[:package] )
+ else
+ raise RuntimeError, "input option incorrect : #{option[:cmd]}"
+ end
+
+ exit 0
+rescue => e
+ puts e.message
+end
+
+
--- /dev/null
+# Logfile created on Mon Feb 06 23:18:31 +0900 2012 by logger.rb/22285
+I, [2012-02-06T23:18:31.266112 #30127] INFO -- : option parsing start
+I, [2012-02-06T23:18:31.266200 #30127] INFO -- : option is : -u,http://172.21.111.132/testserver/unstable
+I, [2012-02-06T23:18:31.266322 #30127] INFO -- : option parsing end
--- /dev/null
+#!/bin/sh -xe
+# clean
+clean()
+{
+ rm -rf $SRCDIR/*.zip
+ rm -rf $SRCDIR/*.tar.gz
+}
+
+# build
+build()
+{
+ echo "build"
+}
+
+# install
+install()
+{
+ BIN_DIR=$SRCDIR/package/dibs.package.${BUILD_TARGET_OS}/data/dev_tools/dibs/
+ DOC_DIR=$SRCDIR/package/dibs.package.${BUILD_TARGET_OS}/data/dev_tools/dibs/doc
+ mkdir -p $BIN_DIR
+ mkdir -p $DOC_DIR
+ cp -f $SRCDIR/pkg-* $BIN_DIR/
+ cp -f $SRCDIR/build-* $BIN_DIR/
+ cp -rf $SRCDIR/src $BIN_DIR/
+ cp -rf $SRCDIR/src $BIN_DIR/
+ cp -f $SRCDIR/AUTHORS $DOC_DIR/
+ cp -f $SRCDIR/LICENSE $DOC_DIR/
+ cp -f $SRCDIR/NOTICE $DOC_DIR/
+ cp -f $SRCDIR/doc/* $DOC_DIR/
+}
+
+
+$1
+echo "$1 success"
+
--- /dev/null
+Package : dibs
+Version : 0.99.11
+OS : linux
+Build-host-os : linux
+Source : dibs
+Maintainer : taejun ha<taejun.ha@samsung.com>, jiil hyoun <jiil.hyoun@samsung.com>, <donghyouk.yang@samsung.com>, donghee yang< donghee.yang@samsung.com >
+Description : Distribute Inteligent Build System
+
+Package : dibs
+Version : 0.99.11
+OS : windows
+Build-host-os : linux
+Source : dibs
+Maintainer : taejun ha<taejun.ha@samsung.com>, jiil hyoun <jiil.hyoun@samsung.com>, <donghyouk.yang@samsung.com>, donghee yang< donghee.yang@samsung.com >
+Description : Distribute Inteligent Build System
--- /dev/null
+#!/usr/bin/ruby
+
+=begin
+
+ pkg-build
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+$LOAD_PATH.unshift File.dirname(__FILE__)+"/src/common"
+$LOAD_PATH.unshift File.dirname(__FILE__)+"/src/pkg_server"
+$LOAD_PATH.unshift File.dirname(__FILE__)+"/src/builder"
+require "utils"
+require "packageServer"
+require "Builder"
+require "optionparser"
+
+begin
+ option = parse
+rescue => e
+ puts e.message
+ exit 0
+end
+
+#generate server when local package server is not set
+
+# if "--os" is not specified, use host os type
+if option[:os].nil? then
+ option[:os] = Utils::HOST_OS
+else
+ if not option[:os] =~ /^(linux|windows|darwin)$/ then
+ puts "We have no plan to Buld OS \"#{option[:os]}\" \n please check your option OS "
+ exit 1
+ end
+end
+
+path = Dir.pwd
+if not File.exist? "package" then
+ puts "current dirctory \"#{path}\" is not package root directory"
+ exit 1
+end
+
+# if url specified
+if not option[:url].nil? then
+ begin
+ builder = Builder.get("default")
+ if builder.pkgserver_url != option[:url] then
+ puts "Package server URL has been changed! Creating new builder..."
+ builder = Builder.create("default", option[:url], nil, nil, nil)
+ end
+ rescue
+ puts "Default builder does not exist! Creating new builder..."
+ builder = Builder.create("default", option[:url], nil, nil, nil)
+ end
+else # if url is not specified
+ begin
+ builder = Builder.get("default")
+ rescue
+ puts "Default builder does not exist! Creating new builder..."
+ builder = Builder.create("default", "http://172.21.111.132/pkgserver/unstable",nil, nil, nil)
+ end
+end
+
+#build project
+if not builder.build( Utils::WORKING_DIR, option[:os], option[:clean], [], false) then
+ puts "Build Failed!"
+else
+ puts "Build Succeeded!"
+end
+
--- /dev/null
+#!/usr/bin/ruby
+
+=begin
+
+ pkg-clean
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+$LOAD_PATH.unshift File.dirname(__FILE__)+"/src/common"
+$LOAD_PATH.unshift File.dirname(__FILE__)+"/src/pkg_server"
+$LOAD_PATH.unshift File.dirname(__FILE__)+"/src/builder"
+require "utils"
+require "packageServer"
+require "Builder"
+require "CleanOptionParser"
+
+path = Dir.pwd
+if not File.exist? "package" then
+ puts "current dirctory \"#{path}\" is not package root directory"
+ exit 1
+end
+
+option = parse
+
+#generate server when local package server is not set
+
+begin
+ builder = Builder.get("default")
+rescue
+ puts "Default builder does not exist! Creating new builder..."
+ builder = Builder.create("default", "http://172.21.111.132/pkgserver/unstable",nil)
+end
+
+#build project
+if not builder.clean( Utils::WORKING_DIR ) then
+ puts "Clean failed!"
+else
+ puts "Clean succeeded!"
+end
+
--- /dev/null
+#!/usr/bin/ruby
+
+=begin
+
+ pkg-cli
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require 'fileutils'
+require 'logger'
+$LOAD_PATH.unshift File.dirname(__FILE__)+"/src/common"
+$LOAD_PATH.unshift File.dirname(__FILE__)+"/src/pkg_server"
+
+#library
+require "utils"
+require "clientOptParser"
+require "client"
+require "packageServer"
+
+#set global variable
+@WORKING_DIR = nil
+
+#option parsing
+begin
+ option = option_parse
+rescue => e
+ # if option parse error print help message
+ puts e.message
+ exit 0
+end
+
+#if "--os" is not specfied, use host os type
+if option[:os].nil? then
+ system_type = `uname -s`
+ case system_type.strip
+ when "Linux" then
+ option[:os] = "linux"
+ when /MINGW32.*/ then
+ option[:os] = "windows"
+ when "Darwin" then
+ option[:os] = "darwin"
+ else
+ raise RuntimeError, "Unknown OS type : #{system_type}"
+ end
+end
+
+case option[:cmd]
+when "update" then
+ client = Client.new( option[:url], nil, nil )
+ client.update()
+when "clean" then
+ client = Client.new( nil, option[:loc], nil )
+ client.clean(option[:f])
+when "download" then
+ client = Client.new( option[:url], option[:loc], nil )
+ if not option[:url].nil? then
+ client.update()
+ end
+ file_loc = client.download( option[:pkg], option[:os], option[:t] )
+when "install" then
+ client = Client.new( option[:url], option[:loc], nil )
+ if not option[:url].nil? then
+ client.update()
+ end
+ client.install( option[:pkg], option[:os], option[:t], option[:f] )
+when "install-file" then
+ client = Client.new( nil, option[:loc], nil )
+ client.install_local_pkg( option[:pkg], option[:f] )
+when "uninstall" then
+ client = Client.new( nil, option[:loc], nil )
+ client.uninstall( option[:pkg], option[:t] )
+when "upgrade" then
+ client = Client.new( option[:url], option[:loc], nil )
+ if not option[:url].nil? then
+ client.update()
+ end
+ client.upgrade( option[:os], option[:t] )
+when "check-upgrade" then
+ client = Client.new( option[:url], option[:loc], nil )
+ if not option[:url].nil? then
+ client.update()
+ end
+ client.check_upgrade( option[:os] )
+when "show-rpkg" then
+ client = Client.new( option[:url], nil, nil )
+ if not option[:url].nil? then
+ client.update()
+ end
+ puts client.show_pkg_info( option[:pkg], option[:os] )
+when "list-rpkg" then
+ client = Client.new( option[:url], nil, nil )
+ if not option[:url].nil? then
+ client.update()
+ end
+ result = client.show_pkg_list( option[:os] )
+ if not result.nil? and not result.empty? then
+ result.each do |i|
+ name = i[0].strip
+ version = i[1].strip
+ desc = i[2].strip
+ puts name + " (" + version + ")"
+ end
+ end
+when "show-lpkg" then
+ client = Client.new( nil, option[:loc], nil )
+ puts client.show_installed_pkg_info( option[:pkg] )
+when "list-lpkg" then
+ client = Client.new( nil, option[:loc], nil )
+ result = client.show_installed_pkg_list()
+ if not result.nil? and not result.empty? then
+ result.each do |i|
+ name = i[0].strip
+ version = i[1].strip
+ desc = i[2].strip
+ puts name + " (" + version + ")"
+ end
+ else
+ puts "Info: There is no any package."
+ end
+when "build-dep" then
+ client = Client.new( nil, nil, nil )
+ result = client.get_build_dependent_packages( option[:pkg], option[:os], true )
+ ret = ""
+ result.each do |i|
+ ret = ret + i + " --> "
+ end
+ ret = ret.strip
+ ret[-3..-1] = ""
+ puts ret
+when "install-dep" then
+ client = Client.new( nil, nil, nil )
+ result = client.get_install_dependent_packages( option[:pkg], option[:os], true, false )
+ ret = ""
+ result.each do |i|
+ ret = ret + i + " --> "
+ end
+ ret = ret.strip
+ ret[-3..-1] = ""
+ puts ret
+else
+ raise RuntimeError, "Input is incorrect : #{option[:cmd]}"
+end
+
--- /dev/null
+#!/usr/bin/ruby
+
+=begin
+
+ pkg-svr
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require 'fileutils'
+$LOAD_PATH.unshift File.dirname(__FILE__)+"/src/common"
+$LOAD_PATH.unshift File.dirname(__FILE__)+"/src/pkg_server"
+require "utils"
+require "packageServer"
+require "serverOptParser"
+
+#option parsing
+begin
+ option = option_parse
+rescue => e
+ puts e.message
+ exit 0
+end
+
+begin
+ if option[:cmd].eql? "list" then
+ if option[:id].empty? then
+ PackageServer.list_id
+ else
+ PackageServer.list_dist option[:id]
+ end
+ exit
+ end
+
+ server = PackageServer.new( option[:id] )
+
+ if server.nil?
+ raise RuntimeError, "server class creation fail"
+ end
+
+ case option[:cmd]
+ when "create"
+ server.create( option[:id], option[:dist], option[:url], option[:loc] )
+ when "register"
+ server.register( option[:pkgs], option[:dist], option[:gensnap], option[:test] )
+ when "gen-snapshot"
+ server.generate_snapshot( option[:snaps][0], option[:dist], option[:bsnap] )
+ when "sync"
+ server.sync( option[:dist], option[:force] )
+ when "add-dist"
+ server.add_distribution( option[:dist], option[:url], option[:clone] )
+ when "remove"
+ if not option[:force] then
+ puts "Do you want to really? then input \"YES\""
+ input = $stdin.gets.strip
+ if input.eql? "YES" then
+ puts "Remove server!"
+ else
+ puts "Remove is canceled by user input"
+ exit(0)
+ end
+ end
+
+ server.remove_server()
+ when "remove-dist"
+ if not option[:force] then
+ puts "Do you want to really? then input \"YES\""
+ input = $stdin.gets.strip
+ if input.eql? "YES" then
+ puts "Remove server!"
+ else
+ puts "Remove is canceled by user input"
+ exit(0)
+ end
+ end
+
+ server.remove_dist( option[:dist] )
+ when "remove-pkg"
+ server.remove_pkg( option[:dist], option[:pkgs], option[:os], option[:recursive] )
+ when "remove-snapshot"
+ server.remove_snapshot( option[:dist], option[:snaps] )
+ when "clean"
+ server.clean( option[:dist], option[:snaps] )
+ when "start"
+ server.start( option[:port] )
+ when "stop"
+ server.stop( option[:port] )
+ else
+ raise RuntimeError, "input option incorrect : #{option[:cmd]}"
+ end
+rescue => e
+ puts e.message
+end
+
+
--- /dev/null
+=begin
+
+ BinaryUploadProject.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require 'fileutils'
+$LOAD_PATH.unshift File.dirname(__FILE__)
+require "CommonProject.rb"
+require "RegisterPackageJob.rb"
+require "Version.rb"
+require "PackageManifest.rb"
+
+
+class BinaryUploadProject < CommonProject
+ attr_accessor :pkg_name
+
+ # initialize
+ def initialize( name, pkg_name, server, os_list )
+ super(name, "BINARY", server, os_list)
+ @pkg_name = pkg_name
+ end
+
+
+ # create new job
+ def create_new_job( filename )
+ new_name = filename.sub(/(.*)_(.*)_(.*)\.zip/,'\1,\2,\3')
+ pkg_name = new_name.split(",")[0]
+ os = new_name.split(",")[2]
+
+ # check file name
+ if @pkg_name != pkg_name then return nil end
+
+ # check package info
+ file_path = "#{@server.incoming_path}/#{filename}"
+ if not File.exist? file_path then return nil end
+
+ pkginfo_dir = "#{@server.path}/projects/#{@name}/pkginfos"
+ if not File.exist? pkginfo_dir then FileUtils.mkdir_p pkginfo_dir end
+ if not Utils.extract_a_file(file_path, "pkginfo.manifest", pkginfo_dir) then
+ return nil
+ end
+ pkginfo =PackageManifest.new("#{pkginfo_dir}/pkginfo.manifest")
+ pkgs = pkginfo.get_target_packages(os)
+ if pkgs.count != 1 then return nil end
+ if pkgs[0].package_name != @pkg_name then return nil end
+
+ return RegisterPackageJob.new( "#{@server.incoming_path}/#{filename}", @server )
+ end
+
+
+ def include_package?(name, version=nil, os=nil)
+ if name == @pkg_name then
+ return true
+ else
+ return false
+ end
+ end
+end
--- /dev/null
+=begin
+
+ BuildClientOptionParser.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require 'optparse'
+
+def option_error_check( options )
+ case options[:cmd]
+
+ when "build" then
+ if options[:project].nil? or options[:project].empty? or
+ options[:domain].nil? or options[:domain].empty? then
+ raise ArgumentError, "Usage: build-cli build -N <project name> -d <server address> [-o <os>] [-w <password>] [--async]"
+ end
+
+ when "resolve" then
+ if options[:project].nil? or options[:project].empty? or
+ options[:domain].nil? or options[:domain].empty? then
+ raise ArgumentError, "Usage: build-cli resolve -N <project name> -d <server address> [-o <os>] [-w <password>] [--async]"
+ end
+
+ when "query" then
+ if options[:domain].nil? or options[:domain].empty? then
+ raise ArgumentError, "Usage: build-cli query -d <server address>"
+ end
+
+ when "cancel" then
+ if options[:job].nil? or options[:job].empty? or
+ options[:domain].nil? or options[:domain].empty? then
+ raise ArgumentError, "Usage: build-cli cancel -j <job number> -d <server address> [-w <password>]"
+ end
+ when "register" then
+ if options[:package].nil? or options[:package].empty? or
+ options[:domain].nil? or options[:domain].empty? or
+ options[:fdomain].nil? or options[:fdomain].empty? then
+ raise ArgumentError, "Usage: build-cli register -P <package file> -d <server address> -t <ftp server url> [-w <password>]"
+ end
+
+ else
+ raise ArgumentError, "Input is incorrect : #{options[:cmd]}"
+ end
+
+end
+
+def option_parse
+ options = {}
+ banner = "Requiest service to build-server command-line tool." + "\n" \
+ + "\n" + "Usage: build-cli <SUBCOMMAND> [OPTS] or build-cli -h" + "\n" \
+ + "\n" + "Subcommands:" + "\n" \
+ + "\t" + "resolve Request change to resolve-status for build-conflict." + "\n" \
+ + "\t" + "query Query information about build-server." + "\n" \
+ + "\t" + "cancel Cancel a building project." + "\n" \
+ + "\t" + "register Register the package to the build-server." + "\n" \
+ + "\n" + "Subcommand usage:" + "\n" \
+ + "\t" + "build-cli build -N <project name> -d <server address> [-o <os>] [-w <password>] [--async]" + "\n" \
+ + "\t" + "build-cli resolve -N <project name> -d <server address> [-o <os>] [-w <password>] [--async]" + "\n" \
+ + "\t" + "build-cli query -d <server address>" + "\n" \
+ + "\t" + "build-cli cancel -j <job number> -d <server address> [-w <password>] " + "\n" \
+ + "\t" + "build-cli register -P <file name> -d <server address> -t <ftp server url> [-w <password>] " + "\n" \
+ + "\n" + "Options:" + "\n"
+
+ optparse = OptionParser.new(nil, 32, ' '*8) do|opts|
+ # Set a banner, displayed at the top
+ # of the help screen.
+
+ opts.banner = banner
+
+ opts.on( '-N', '--project <project name>', 'project name' ) do|project|
+ options[:project] = project
+ end
+
+ options[:domain] = nil
+ opts.on( '-d', '--address <server address>', 'build server address: 127.0.0.1:2224' ) do|domain|
+ options[:domain] = domain
+ end
+
+ options[:os] = nil
+ opts.on( '-o', '--os <operating system>', 'target operating system: linux/windows/darwin' ) do|os|
+ options[:os] = os
+ end
+
+ options[:async] = "NO"
+ opts.on( '--async', 'asynchronous job' ) do
+ options[:async] = "YES"
+ end
+
+ opts.on( '-j', '--job <job number>', 'job number' ) do|job|
+ options[:job] = job
+ end
+
+ options[:passwd] = ""
+ opts.on( '-w', '--passwd <password>', 'password for managing project' ) do|passwd|
+ options[:passwd] = passwd
+ end
+
+ opts.on( '-P', '--pkg <package file>', 'package file path' ) do|package|
+ options[:package] = package.strip
+ end
+
+ opts.on( '-t', '--ftp <ftp server url>', 'ftp server url: ftp://dibsftp:dibsftp@127.0.0.1' ) do|domain|
+ options[:fdomain] = domain
+ end
+
+ opts.on( '-h', '--help', 'display manual' ) do
+ puts opts
+ exit
+ end
+
+ opts.on( '-v', '--version', 'display version' ) do
+ puts "DIBS(Distributed Intelligent Build System) version 1.2.0"
+ exit
+ end
+
+ end
+
+ cmd = ARGV[0]
+
+ if cmd.eql? "build" or cmd.eql? "resolve" or
+ cmd.eql? "query" or cmd.eql? "cancel" or
+ cmd.eql? "register" or
+ cmd =~ /(-v)|(--version)/ or
+ cmd =~ /(help)|(-h)|(--help)/ then
+
+ if cmd.eql? "help" then
+ ARGV[0] = "-h"
+ end
+
+ options[:cmd] = ARGV[0]
+ else
+ raise ArgumentError, "Usage: build-cli <SUBCOMMAND> [OPTS] or build-cli -h"
+ end
+
+ optparse.parse!
+
+ option_error_check options
+
+ return options
+end
+
--- /dev/null
+require "socket"
+
+=begin
+
+ BuildComm.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+$LOAD_PATH.unshift File.dirname(__FILE__)+"/src/common"
+require "log"
+require 'timeout'
+require "fileTransfer"
+require "net/ftp"
+
+class BuildCommServer
+ VERSION = "1.3.0"
+
+ def initialize(port, log, ftp_url=nil)
+ @port = port
+ # checking port is available
+ if port_open? @port then
+ raise "Port \"#{@port}\" is already in use."
+ end
+
+ @log = log
+ @ftp_url = ftp_url
+ @tcp_server = TCPServer.open( port )
+ end
+
+
+ # wait for connection and handle request
+ def wait_for_connection(quit_loop)
+ while( not quit_loop )
+ req = @tcp_server.accept
+
+ begin
+ yield req
+ rescue
+ @log.error $!
+ @log.error "Caught a connection exception"
+ req.close
+ end
+ end
+ end
+
+
+ # terminate
+ def terminate
+ @tcp_server.close()
+ end
+
+
+ # send_begin
+ def self.send_begin( req )
+ send( req, "=BEGIN,#{VERSION}")
+ end
+
+
+ def self.send_end( req )
+ send( req, "=END")
+ end
+
+
+ def self.send_chk( req )
+ send( req, "=CHK" )
+ end
+
+
+ def self.send( req, line )
+ begin
+ if not req.nil? then
+ req.puts line
+ end
+ rescue
+ raise "Connection is closed"
+ end
+ end
+
+
+ def send_file(req, src_file)
+ # 1. send "READY"
+ # 2. If "FTP,ip,username,passwd" is received,
+ # Upload the src file using server's ftp_url.
+ # if then ftp_url is nil, use the url on "FTP" message instead
+ # After uploading, send "UPLOADED,ftp_filepath"
+ # 3. If "SUCC" is received, remove the file on FTP server
+
+ begin
+ if not File.exist? src_file then
+ puts "[E] \"#{src_file}\" file does not exist"
+ req.puts "ERROR"
+ return false
+ end
+
+ req.puts "READY"
+ while l = req.gets()
+ tok = l.split(",").map { |x| x.strip }
+ cmd = tok[0].strip
+ puts "[I] Received \"#{cmd}\" message.."
+ if cmd == "FTP" then
+ if tok.count < 5 then
+ puts "[E] Received wrong REQ : #{l.strip}"
+ req.puts "ERROR"
+ return false
+ end
+
+ # get ftp connection info
+ if @ftp_url.nil? then
+ ip = tok[1].strip
+ port = tok[2].strip
+ username = tok[3].strip
+ passwd = tok[4].strip
+ puts "[I] FTP info from client : [#{ip}, #{port}, #{username}, #{passwd}]"
+ else
+ url_contents = Utils.parse_ftpserver_url(@ftp_url)
+ ip = url_contents[0]
+ port = url_contents[1]
+ username = url_contents[2]
+ passwd = url_contents[3]
+ end
+
+ # upload to ftp server
+ ftp_filepath = FileTransfer.putfile(ip, port, username, passwd, src_file)
+ req.puts "UPLOADED,#{ftp_filepath}"
+ puts "[I] Uploaded file to FTP server: [#{File.basename(src_file)}]"
+ elsif cmd == "SUCC" then
+ FileTransfer.cleandir(ip, port, username, passwd, ftp_filepath)
+ puts "[I] Clean temporary dir on FTP server: #{ftp_filepath}"
+ break
+ end
+ end
+ rescue => e
+ puts "[E] Connection closed"
+ raise e
+ end
+
+ return true
+ end
+
+
+ def receive_file(req, dst_file)
+ # 1. send "READY"
+ # 2. If "UPLOADED,ip,port,file_path,username,passwd" is received,
+ # Download the file using my ftp_url.
+ # If ftp_url is nil, use the url on "UPLOADED" messge instead
+ # After downloading it, send "SUCC"
+ begin
+ req.puts "READY"
+ while l = req.gets()
+ tok = l.split(",").map { |x| x.strip }
+ cmd = tok[0].strip
+ puts "[I] Received \"#{cmd}\" message.."
+ if cmd == "UPLOADED" then
+ if tok.count < 6 then
+ puts "[E] Received wrong REQ : #{l.strip}"
+ req.puts "ERROR"
+ return false
+ end
+ filepath = tok[3].strip
+ dirname = File.dirname(filepath)
+ filename = File.basename(filepath)
+
+ # get ftp connection info
+ if @ftp_url.nil? then
+ ip = tok[1].strip
+ port = tok[2].strip
+ username = tok[4].strip
+ passwd = tok[5].strip
+ puts "[I] FTP info from client: [#{ip}, #{port}, #{username}, #{passwd}]"
+ else
+ url_contents = Utils.parse_ftpserver_url(@ftp_url)
+ ip = url_contents[0]
+ port = url_contents[1]
+ username = url_contents[2]
+ passwd = url_contents[3]
+ end
+
+ # download from ftp server
+ FileTransfer.getfile(ip, port, username, passwd, filepath, dst_file)
+ puts "[I] Received file from FTP server sucessfully.."
+ req.puts "SUCC"
+ break
+ end
+ end
+ rescue => e
+ puts "[E] Connectio is closed"
+ req.puts "ERROR"
+ raise e
+ end
+
+ return true
+ end
+
+
+ def self.disconnect( req )
+ begin
+ req.close
+ rescue
+ end
+ end
+
+ private
+ def port_open?( port )
+ Timeout::timeout(1) do
+ begin
+ TCPSocket.new("127.0.0.1",port).close
+ true
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
+ false
+ end
+ end
+ rescue Timeout::Error
+ false
+ end
+end
+
+
+class BuildCommClient
+ VERSION = "1.3.0"
+
+ private_class_method :new
+
+ def initialize(socket)
+ @socket = socket
+ end
+
+
+ # create
+ # if sec 0 or nil then not set timeout. it's timeout spec
+ def self.create(ip, port, sec = 5)
+ # open socket
+ socket = nil
+ begin
+ timeout(sec) do
+ socket = TCPSocket.open( ip, port )
+ end
+ rescue Timeout::Error
+ return nil
+ rescue
+ # unknown exception
+ return nil
+ end
+
+ # refused
+ if socket.nil? then
+ return nil
+ end
+
+ return new(socket)
+ end
+
+
+ def send( msg )
+ if @socket.nil? then return false end
+
+ @socket.puts( msg )
+ return true
+ end
+
+
+ def print_stream
+
+ begin
+ l = @socket.gets()
+
+ if l.nil? then
+ puts "Connection refused"
+ return false
+ end
+
+ # check protocol
+ if not protocol_matched? l.strip then
+ puts "Comm. Protocol version is mismatched! #{VERSION}"
+ return false
+ end
+
+
+ # get contents
+ while line = @socket.gets()
+ if line.strip == "=END" then break end
+ if line.strip == "=CHK" then next end
+ # print
+ puts line.strip
+ end
+ rescue
+ puts "Connection closed"
+ return false
+ end
+
+ return true
+ end
+
+
+ # handle
+ def read_lines
+
+ begin
+ # get first line
+ l = nil
+ timeout(5) do
+ l = @socket.gets()
+ end
+
+ if l.nil? then
+ return false
+ end
+
+ # check protocol
+ if not protocol_matched? l.strip then
+ return false
+ end
+
+ # get contents
+ while line = @socket.gets()
+ if line.strip == "=END" then break end
+ if line.strip == "=CHK" then next end
+
+ # print
+ yield line.strip
+ end
+ rescue Timeout::Error
+ puts "WARN: Connection timed out"
+ return false
+ rescue => e
+ puts e.message
+ return false
+ end
+
+ return true
+ end
+
+
+ # return result
+ def receive_data
+ result = []
+
+ begin
+ l = @socket.gets()
+
+ if l.nil? then
+ puts "Connection refused"
+ return nil
+ end
+
+ # check protocol
+ if not protocol_matched? l.strip then
+ puts "Comm. Protocol version is mismatched! #{VERSION}"
+ return nil
+ end
+
+
+ # get contents
+ while line = @socket.gets()
+ if line.strip == "=END" then break end
+ if line.strip == "=CHK" then next end
+ # print
+ result.push line.strip
+ end
+ rescue
+ puts "Connection closed"
+ return nil
+ end
+
+ return result
+ end
+
+
+ def send_file(ip, port, username, passwd, src_file)
+ begin
+ l = @socket.gets()
+ if l.nil? then
+ puts "[E] Connection refused"
+ return false
+ end
+
+ # check protocol
+ if not protocol_matched? l.strip then
+ puts "[E] Comm. Protocol version is mismatched! #{VERSION}"
+ return false
+ end
+
+ # 1. If "READY" is received, upload src file to FTP server
+ # After uploading it, send "UPLOADED,ip,file_path,username,passwd"
+ # 2. If "SUCC" is received, remove the file on FTP server
+ while line = @socket.gets()
+ puts "[I] Recevied \"#{line.strip}\" message.."
+ if line.strip == "READY" then
+ ftp_filepath = FileTransfer.putfile(ip, port, username, passwd, src_file)
+ send "UPLOADED,#{ip},#{port},#{ftp_filepath},#{username},#{passwd}"
+ puts "[I] Uploaded file to FTP server : #{File.basename(src_file)}"
+ elsif line.strip == "SUCC" then
+ FileTransfer.cleandir(ip, port, username, passwd, ftp_filepath)
+ puts "[I] Clean FTP temporary dir : #{ftp_filepath}"
+ elsif line.strip == "ERROR" then
+ puts "[E] FTP failed to put file"
+ return false
+ elsif line.strip == "=END" then
+ break
+ end
+ end
+ rescue => e
+ puts "[E] Connection closed"
+ raise e
+ end
+
+ return true
+ end
+
+
+ # return file
+ def receive_file(ip, port, username, passwd, dst_file)
+ begin
+ l = @socket.gets()
+
+ if l.nil? then
+ puts "[E] Connection refused"
+ return false
+ end
+
+ # check protocol
+ if not protocol_matched? l.strip then
+ puts "[E] Comm. Protocol version is mismatched! #{VERSION}"
+ return false
+ end
+
+ # 1. If "READY" is received, send "FTP,ip,port,username,passwd"
+ # 2. if "UPLOADED,ftp_file_path" is received,
+ # Download the file
+ # Send "SUCC"
+ # 3. If "SUCC" is received, remove the file on FTP server
+ while line = @socket.gets()
+ cmd = line.split(",")[0].strip
+ puts "[I] Received \"#{cmd}\" message"
+ if cmd == "READY" then
+ send "FTP,#{ip},#{port},#{username},#{passwd}"
+ puts "[I] Send FTP info to server : #{ip}, #{port}, #{username}, #{passwd}"
+ elsif cmd == "UPLOADED" then
+ tok = line.split(",")
+ if tok.length < 2 then
+ puts "[ERROR] Received wrong REQ : #{line.strip}"
+ return false
+ end
+ ftp_filepath = tok[1].strip
+ FileTransfer.getfile(ip, port, username, passwd, ftp_filepath, dst_file)
+ send "SUCC"
+ puts "[I] Received file from FTP server sucessfully.."
+ elsif cmd == "ERROR" then
+ puts "[E] Failed to receive file from server"
+ return false
+ elsif cmd == "=END" then
+ break
+ end
+ end
+ rescue
+ puts "[E] Connection closed"
+ return false
+ end
+
+ return true
+ end
+
+
+ def terminate
+ @socket.close
+ end
+
+
+ private
+
+
+ # check protocol
+ def protocol_matched?(l)
+
+ version = ( l.split(",")[1].nil? ? "1.0.0" : l.split(",")[1] )
+ if not l.start_with? "=BEGIN" or
+ version.nil? or version != VERSION then
+ return false
+ else
+ return true
+ end
+ end
+end
--- /dev/null
+=begin
+
+ BuildJob.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require "fileutils"
+$LOAD_PATH.unshift File.dirname(__FILE__)
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/builder"
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/pkg_server"
+require "client.rb"
+require "PackageManifest.rb"
+require "Version.rb"
+require "Builder.rb"
+require "RemoteBuilder.rb"
+require "BuildServer.rb"
+require "JobLog.rb"
+require "mail.rb"
+
+class BuildJob
+
+ attr_accessor :id, :server, :pre_jobs, :os, :type
+ attr_accessor :status, :pkginfo, :log, :source_path
+ attr_accessor :pkgsvr_client, :thread
+ attr_accessor :rev_fail_projects, :rev_success_jobs
+ attr_accessor :pending_ancestor, :build_dep_prjs
+ attr_accessor :is_fullbuild_job
+
+ # initialize
+ def initialize (id, project, os, server)
+ @id = id
+ @project = project
+ @os = os
+ @server = server
+ @type = "BUILD"
+
+ @status = "JUST_CREATED"
+ @resolve = false
+ @host_os = Utils::HOST_OS
+ @pkgserver_url = @server.pkgserver_url
+ @job_root = "#{@server.path}/jobs/#{@id}"
+ @source_path = @job_root+"/temp"
+ @job_working_dir=@job_root+"/works"
+ @buildroot_dir = "#{@job_root}/buildroot"
+ @pre_jobs = [] #pre-requisite jobs
+
+ # this item will be initialized on pre-verify
+ @pkginfo = nil
+ @pkgsvr_client = nil
+ @thread = nil
+ @log = nil
+ @parent = nil # for job hierachy
+
+ #for cancel operation
+ @pending_ancestor = nil # for cancel pending job
+ @remote_id = nil # for cancel remote_working job
+ @build_dep_prjs = [] # for cacnel pending job
+
+ # for resolving build-break
+ @rev_fail_projects = []
+ @rev_success_jobs = []
+
+ # remote build
+ @remote_server = nil
+
+ # job type
+ @is_rev_build_check_job = false
+ @is_remote_job = false
+ @is_internal_job = false
+ @is_fullbuild_job = false
+
+ @external_pkgs = []
+ end
+
+
+ def get_project()
+ return @project
+ end
+
+
+ # set parent
+ def set_parent_job( parent )
+ # if parent exists, share build-root
+ @parent = parent
+ @buildroot_dir = "#{@server.path}/jobs/#{@parent.id}/buildroot"
+ end
+
+
+ # set reverse build check job
+ def set_rev_build_check_job( parent )
+ @is_rev_build_check_job = true
+
+ # if parent exists, share build-root
+ if not parent.nil? then
+ set_parent_job( parent )
+ end
+ end
+
+
+ def set_remote_job(server)
+ @is_remote_job = true
+ @remote_server=server
+ end
+
+
+ def set_internal_job()
+ @is_internal_job = true
+ end
+
+
+ # set option for waiting for resolve
+ def set_resolve_flag()
+ @resolve = true
+ end
+
+
+ # set logger
+ def set_logger( logger )
+ @log = logger
+ end
+
+
+ # add external packages to overwrite before build
+ def add_external_package( file_path )
+ @external_pkgs.push file_path
+ end
+
+
+ # execute
+ def execute(sync=false)
+ @log.info( "Invoking a thread for building Job #{@id}", Log::LV_USER)
+ if @status == "ERROR" then return end
+ @thread = Thread.new {
+ # main
+ thread_main()
+
+ # close
+ terminate()
+ }
+
+ if sync then
+ @thread.join
+ end
+
+ return true
+ end
+
+
+ #terminate
+ def terminate()
+ #do noting
+ end
+
+
+ #cancel
+ def cancel()
+ case @status
+ when "WORKING" then
+ @status = "CANCELED"
+ @thread.terminate
+ if not @log.nil? then
+ @log.info( "JOB is canceled by cancel operation !!", Log::LV_USER)
+ end
+ terminate
+ when "REMOTE_WORKING" then
+ @status = "CANCELED"
+ client = BuildCommClient.create( @server.ip, @server.port )
+ if not client.nil? then
+ client.send "CANCEL,#{@remote_id}"
+ result1 = client.receive_data()
+ if result1.nil? then
+ client.terminate
+ exit(-1)
+ end
+ end
+ when "WAITING" , "INITIALIZING" , "JUST_CREATED" then
+ @status = "CANCELED"
+ if not @log.nil? then
+ @log.info( "JOB is canceled by cancel operation !!", Log::LV_USER)
+ end
+ when "PENDING" then
+ @server.cancel_lock.synchronize{
+ @thread.terminate
+ @status = "CANCELED"
+ }
+ if @pending_ancestor.nil? then
+ #resolve pending job
+ pending_descendants = @server.jobmgr.jobs.select{|j| (not j.pending_ancestor.nil?) and "#{j.pending_ancestor.id}" == "#{@id}"}
+ pending_descendants.each do |pd|
+ pd.cancel
+ end
+ else
+ @pending_ancestor.rev_success_jobs.delete self if @pending_ancestor.rev_success_jobs.include? self
+ @pending_ancestor.rev_fail_projects.push @project if not @pending_ancestor.rev_fail_projects.include? @project
+ pending_descendants = @server.jobmgr.jobs.select{|j| (not j.pending_ancestor.nil?) and "#{j.pending_ancestor.id}" == "#{@pending_ancestor.id}"}
+ pending_descendants.select{|j| j.build_dep_prjs.include? @project}.each do |d|
+ @pending_ancestor.rev_success_jobs.delete d if @pending_ancestor.rev_success_jobs.include? d
+ @pending_ancestor.rev_fail_projects.push d.get_project if not @pending_ancestor.rev_fail_projects.include? d.get_project
+ d.thread.terminate
+ d.status = "WAITING"
+ end
+ end
+ if not @log.nil? then
+ @log.info( "JOB is canceled by cancel operation !!", Log::LV_USER)
+ end
+ terminate
+ else # ERROR | FINISHED | RESOLVED
+ #do noting
+ end
+ end
+
+
+ # check building is possible
+ def can_be_built_on?(host_os)
+ for pkg in @pkginfo.packages
+ if pkg.os == @os and pkg.build_host_os.include? host_os then
+ return true
+ end
+ end
+
+ return false
+ end
+
+
+ def has_build_dependency?(other_job)
+
+ if has_same_packages?(other_job) or
+ does_depend_on?(other_job) or
+ does_depended_by?(other_job) then
+
+ return true
+ else
+ return false
+ end
+ end
+
+
+ def has_same_packages?( wjob )
+ # if job type is different, always true
+ if @type != wjob.type then return true end
+
+ # same package must have same os
+ if not @os.eql? wjob.os then
+ return false
+ end
+
+ # check package name
+ for pkg in @pkginfo.packages
+ for wpkg in wjob.pkginfo.packages
+ if pkg.package_name == wpkg.package_name then
+ #puts "Removed from candiated... A == B"
+ return true
+ end
+ end
+ end
+
+ return false
+ end
+
+
+ def does_depend_on?( wjob )
+ # if job type is different, always true
+ if @type != wjob.type then return true end
+
+ # compare build dependency
+ for dep in @pkginfo.get_build_dependencies(@os)
+ for wpkg in wjob.pkginfo.packages
+ # dep packages of my job must have same name and target os
+ # with packages in working job
+ if dep.package_name == wpkg.package_name and
+ dep.target_os_list.include? wjob.os then
+ #puts "Removed from candiated... A -> B"
+ return true
+ end
+ end
+ end
+
+ # if both are full build jobs, install dependency must be checked
+ if @is_fullbuild_job and wjob.is_fullbuild_job and
+ @os == wjob.os then
+
+ for dep in @pkginfo.get_install_dependencies(@os)
+ for wpkg in wjob.pkginfo.packages
+ if dep.package_name == wpkg.package_name then
+ return true
+ end
+ end
+ end
+ end
+
+ return false
+ end
+
+
+ def does_depended_by?( wjob )
+ # if job type is different, always true
+ if @type != wjob.type then return true end
+
+ for pkg in @pkginfo.packages
+ for dep in wjob.pkginfo.get_build_dependencies(wjob.os)
+ # dep package of working job must have same name and target os
+ # with packages in my job
+ if dep.package_name == pkg.package_name and
+ dep.target_os_list.include? @os then
+ #puts "Checking... A <- B"
+ return true
+ end
+ end
+ end
+ return false
+ end
+
+
+ def is_connected?
+ return @log.is_connected?
+ end
+
+
+ # return the job is asyncronous job
+ def is_asynchronous_job?
+ if not @log.has_second_out? then
+ return true
+ else
+ return false
+ end
+ end
+
+ #
+ # PROTECTED METHODS
+ #
+ protected
+
+
+ # main module
+ def thread_main
+ @log.info( "New Job #{@id} is started", Log::LV_USER)
+
+ # checking build dependency
+ if not @is_rev_build_check_job and not @is_remote_job and
+ not @is_fullbuild_job and
+ not check_build_dependency() then
+ @status = "ERROR"
+ return false
+ end
+
+ # clean build
+ if not build() then
+ @status = "ERROR"
+ return
+ end
+
+ # upload
+ if not @is_rev_build_check_job and not @is_internal_job and
+ not upload() then
+ @status = "ERROR"
+ return
+ end
+
+ # copy result files to outgoing path
+ if @is_internal_job then
+ copy_result_files(@server.outgoing_path)
+ elsif @is_fullbuild_job then
+ copy_result_files(@parent.source_path)
+ end
+
+ # INFO. don't change this string
+ @log.info( "Job is completed!", Log::LV_USER)
+ @status = "FINISHED"
+ end
+
+
+ # check if local package version is greater than server
+ def check_package_version()
+ @log.info( "Checking package version ...", Log::LV_USER)
+
+ # package update
+ @pkgsvr_client.update
+
+ for pkg in @pkginfo.packages
+ ver_local = pkg.version
+ #ver_svr = @pkgsvr_client.get_package_version( pkg.package_name, @os )
+ ver_svr = @pkgsvr_client.get_attr_from_pkg( pkg.package_name, @os, "version")
+ if not ver_svr.nil? and Version.new(ver_local) <= Version.new(ver_svr) then
+ @log.error( "Version must be increased : #{ver_local} <= #{ver_svr}", Log::LV_USER)
+ return false
+ end
+ end
+
+ return true
+ end
+
+
+ # build dependency version
+ def check_build_dependency()
+ @log.info( "Checking build dependency ...", Log::LV_USER)
+ @pkgsvr_client.update
+ for dep in @pkginfo.get_build_dependencies( @os )
+ #ver_svr = @pkgsvr_client.get_package_version( dep.package_name, @os )
+ if dep.target_os_list.count != 0 then
+ dep_target_os = dep.target_os_list[0]
+ else
+ dep_target_os = @os
+ end
+ ver_svr = @pkgsvr_client.get_attr_from_pkg( dep.package_name, dep_target_os, "version")
+
+ if ver_svr.nil?
+ @log.error( "The package \"#{dep.package_name}\" for build-dependency is not found", Log::LV_USER)
+ return false
+ end
+
+ if not dep.match? ver_svr
+ @log.error( "Version for build-dependency in not matched : server version => #{ver_svr}", Log::LV_USER)
+ return false
+ end
+ end
+
+ return true
+ end
+
+
+ # build clean
+ def build()
+
+ # check there are pending pacakges which wait for me
+ # it will return nil if not exist
+ # this process must be skip if it is sub-job
+ if not @is_rev_build_check_job and not @is_internal_job then
+ @server.cancel_lock.synchronize{
+ @pending_ancestor = get_pending_job()
+ }
+ end
+
+ if not @pending_ancestor.nil? then
+ # resolve other pending job
+ resolve()
+ elsif @resolve then
+ # wait for being resolved by other jobs
+ # this condition must be placed after checking pending status
+ wait_resolve()
+ else
+ # build
+ build_normal()
+ end
+ end
+
+
+ # return pending job that wait for me
+ def get_pending_job()
+ @server.jobmgr.get_pending_jobs.each do |job|
+ if job.rev_fail_projects.include? @project then
+ return job
+ end
+ end
+
+ return nil
+ end
+
+
+ def build_normal()
+ @log.info( "Started to build this job...", Log::LV_USER)
+
+ # create builder
+ if @is_remote_job then
+ builder = RemoteBuilder.new("JB#{@id}", @remote_server.ip, @remote_server.port, @server.ftp_addr, @server.ftp_port, @server.ftp_username, @server.ftp_passwd)
+ @log.info( "JobBuilder##{@id} is created", Log::LV_USER)
+ @log.info( " - Remote Server : #{@remote_server.ip}:#{@remote_server.port}" )
+ @log.info( " - FTP Server : #{@server.ftp_addr}" )
+ else
+ builder = Builder.create( "JB#{@id}", @pkgserver_url, @log.path,
+ "#{@buildroot_dir}/#{@os}", @server.build_cache_dir )
+ if builder.nil?
+ @log.error( "Creating job builder failed", Log::LV_USER)
+ return false
+ end
+ @log.info( "JobBuilder##{@id} is created", Log::LV_USER)
+ @log.info( " - Package Server : #{@pkgserver_url}" )
+ @log.info( " - Build Cache Path : #{@server.build_cache_dir}" )
+ end
+ @log.info( " - Log Path : #{@log.path}" )
+
+ # set log output
+ builder.log.close
+ builder.log = @log
+
+ # if sub job(reverse-build), install parent-pkgs and not clean
+ use_clean = true
+ local_pkgs = []
+ local_pkgs += @external_pkgs
+ if @is_rev_build_check_job and not @parent.nil? then
+ use_clean = false
+ # get local packages to install
+ src_path = @parent.source_path
+ ver = @parent.pkginfo.get_version()
+ for pkg in @parent.pkginfo.get_target_packages(@os)
+ local_pkgs.push "#{src_path}/#{pkg.package_name}_#{ver}_#{@os}.zip"
+ end
+ end
+ if @is_fullbuild_job and not @parent.nil? then
+ use_clean = false
+ # get local packages to install
+ src_path = @parent.source_path
+ deps = @pkginfo.get_build_dependencies(@os)
+ for dep in deps
+ binpkgs = Dir.glob("#{src_path}/#{dep.package_name}_*_#{@os}.zip")
+ if binpkgs.count > 0 then
+ local_pkgs.push binpkgs[0]
+ end
+ end
+ end
+
+ # build
+ if @is_remote_job then
+ result = builder.build(@project.name, @project.passwd, @source_path, @os,
+ use_clean, @is_rev_build_check_job, @git_commit, local_pkgs)
+ else
+ result = builder.build(@source_path, @os, use_clean, local_pkgs, false )
+ end
+ if not result then
+ @log.error( "Building job failed", Log::LV_USER)
+ return false
+ end
+
+ # check reverse dependecy if not sub job
+ if not @is_rev_build_check_job and not @is_internal_job and
+ not check_reverse_build( [], true ).empty? then
+ @log.error( "Reverse-build-check failed!" )
+ return false
+ end
+
+ return true
+ end
+
+
+ # build projects that dependes on me
+ # can ignore some projects
+ def check_reverse_build( ignored_projects, exit_on_error)
+ @log.info( "Checking reverse build dependency ...", Log::LV_USER)
+
+ failed_projects = []
+
+ # get reverse-dependent projects
+ rev_pkgs = []
+ for pkg in @pkginfo.get_target_packages(@os)
+ rev_pkgs += @pkgsvr_client.get_reverse_build_dependent_packages(pkg.package_name, @os)
+ end
+ rev_pkgs.uniq!
+ rev_projects = @server.prjmgr.get_projects_from_pkgs(rev_pkgs)
+ rev_projects -= ignored_projects
+
+ # build rev-dep project as sub-job
+ for prj in rev_projects
+ if prj.type != "GIT" then next end
+ for os in prj.os_list
+ # check version
+ version = nil
+ for pkg in rev_pkgs
+ if os != pkg.os then next end
+ if prj.include_package?(pkg.package_name, pkg.version, os) then
+ version = pkg.version
+ break
+ end
+ end
+ if version.nil? then next end
+
+ # create sub jobs for checking
+ new_job = prj.create_new_job_from_version(os, version)
+ new_job.set_rev_build_check_job(self)
+ @log.info( " * Checking reverse-build ... #{prj.name}(#{new_job.id})", Log::LV_USER)
+ result = new_job.init()
+ rserver = @server.get_available_server( new_job )
+ if rserver != nil and rserver != @server then
+ new_job.set_remote_job( rserver )
+ end
+ if result then
+ new_job.execute(true)
+ if new_job.status == "ERROR" then result = false end
+ end
+
+ # check result
+ if not result then
+ failed_projects.push prj
+ if exit_on_error then
+ return failed_projects
+ end
+ end
+ end
+ end
+
+ return failed_projects
+ end
+
+
+ # wait to be resolved by other jobs
+ def wait_resolve()
+ @log.info( "Started to build this job and wait for being resolved...", Log::LV_USER)
+
+ # create builder
+ if @is_remote_job then
+ builder = RemoteBuilder.new("JB#{@id}", @remote_server.ip, @remote_server.port, @server.ftp_addr, @server.ftp_port, @server.ftp_username, @server.ftp_passwd)
+ @log.info( "JobBuilder##{@id} is created", Log::LV_USER)
+ @log.info( " - Remote Server : #{@remote_server.ip}:#{@remote_server.port}" )
+ @log.info( " - FTP Server : #{@server.ftp_addr}" )
+ else
+ builder = Builder.create( "JB#{@id}", @pkgserver_url, @log.path,
+ "#{@buildroot_dir}/#{@os}", @server.build_cache_dir )
+ if builder.nil?
+ @log.error( "Creating job builder failed", Log::LV_USER)
+ return false
+ end
+ @log.info( "JobBuilder##{@id} is created", Log::LV_USER)
+ @log.info( " - Package Server : #{@pkgserver_url}" )
+ @log.info( " - Build Cache Path : #{@server.build_cache_dir}" )
+ end
+ @log.info( " - Log Path : #{@log.path}" )
+
+ # set log output
+ builder.log.close
+ builder.log = @log
+
+ # build
+ if @is_remote_job then
+ result = builder.build(@project.name, @project.passwd, @source_path, @os,
+ true, false, @git_commit, [])
+ else
+ result = builder.build(@source_path, @os, true, [], false )
+ end
+ if not result then
+ @log.error( "Building job failed", Log::LV_USER)
+ return false
+ end
+
+ # check reverse dependecy
+ @rev_fail_projects = check_reverse_build([], false)
+ if @rev_fail_projects.empty? then
+ # if no problem?, it OK
+ return true
+ end
+
+ # pending
+ @status = "PENDING"
+ @log.info( "Entered the PENDING state ...", Log::LV_USER)
+ while @status == "PENDING"
+ sleep 1
+ end
+
+ return true
+ end
+
+
+ # resolve other pending job
+ def resolve()
+ deps = @pkginfo.get_build_dependencies(@os)
+ pkgs = deps.map{|x|@pkgsvr_client.get_pkg_from_list(x.package_name, @os)}
+ prjs = @server.prjmgr.get_projects_from_pkgs(pkgs)
+ @build_dep_prjs = prjs
+ old = ""
+ while not (@pending_ancestor.rev_fail_projects & prjs).empty?
+ @status = "PENDING"
+ new = (@pending_ancestor.rev_fail_projects & prjs).map{|x|x.name}.join("\" and \"")
+ if new != old then
+ @log.info("waiting \"#{new}\" projects", Log::LV_USER)
+ old = new
+ end
+ sleep 1
+ end
+ @status = "WORKING"
+
+ @log.info( "Started to build this job and resolve other pending job...", Log::LV_USER)
+
+ # create builder
+ if @is_remote_job then
+ builder = RemoteBuilder.new("JB#{@id}", @remote_server.ip, @remote_server.port, @server.ftp_addr, @server.ftp_port, @server.ftp_username, @server.ftp_passwd)
+ @log.info( "JobBuilder##{@id} is created", Log::LV_USER)
+ @log.info( " - Remote Server : #{@remote_server.ip}:#{@remote_server.port}" )
+ @log.info( " - FTP Server : #{@server.ftp_addr}" )
+ else
+ builder = Builder.create( "JB#{@id}", @pkgserver_url, @log.path,
+ "#{@buildroot_dir}/#{@os}", @server.build_cache_dir )
+ if builder.nil?
+ @log.error( "Creating job builder failed", Log::LV_USER)
+ return false
+ end
+ @log.info( "JobBuilder##{@id} is created", Log::LV_USER)
+ @log.info( " - Package Server : #{@pkgserver_url}" )
+ @log.info( " - Build Cache Path : #{@server.build_cache_dir}" )
+ end
+ @log.info( " - Log Path : #{@log.path}" )
+
+ # set log output
+ builder.log.close
+ builder.log = @log
+
+ # get local packages to overwite
+ # they must be composed of packages of pending jobs and its success list
+ local_pkgs=[]
+ local_pkgs += @external_pkgs
+ src_path = @pending_ancestor.source_path
+ ver = @pending_ancestor.pkginfo.get_version()
+ for pkg in @pending_ancestor.pkginfo.get_target_packages(@os)
+ local_pkgs.push "#{src_path}/#{pkg.package_name}_#{ver}_#{@os}.zip"
+ end
+ for job in @pending_ancestor.rev_success_jobs
+ src_path = job.source_path
+ ver = job.pkginfo.get_version()
+ for pkg in job.pkginfo.get_target_packages(@os)
+ local_pkgs.push "#{src_path}/#{pkg.package_name}_#{ver}_#{@os}.zip"
+ end
+ end
+
+ # build
+ if @is_remote_job then
+ result = builder.build(@project.name, @project.passwd, @source_path, @os, true, false, @git_commit, local_pkgs)
+ else
+ result = builder.build(@source_path, @os, true, local_pkgs, false )
+ end
+ if not result then
+ @log.error( "Building job failed", Log::LV_USER)
+ return false
+ end
+
+ # get ignored projects will not be built in reverse build check
+ # the projects are failed projects of pending jobs
+ # and they must be built by other jobs
+ ignored_projects = @pending_ancestor.rev_fail_projects
+
+ # check reverse dependecy
+ @pending_ancestor.rev_fail_projects = (@pending_ancestor.rev_fail_projects + check_reverse_build(ignored_projects, false)).uniq
+
+ # update the status of pending job
+ @status = "PENDING"
+ @pending_ancestor.rev_fail_projects.delete @project
+ @pending_ancestor.rev_success_jobs.push self
+ if @pending_ancestor.rev_fail_projects.empty? then
+ @pending_ancestor.status = "RESOLVED"
+ @pending_ancestor.rev_success_jobs.each do |job|
+ job.status = "RESOLVED"
+ end
+ else
+ @log.info( "Entered the PENDING state ...", Log::LV_USER)
+ while @status == "PENDING"
+ sleep 1
+ end
+ end
+
+ return true
+ end
+
+
+ def upload()
+ @log.info( "Uploading ...", Log::LV_USER)
+
+ # get package path list
+ binpkg_path_list = Dir.glob("#{@source_path}/*_*_#{@os}.zip")
+ srcpkg_path_list = Dir.glob("#{@source_path}/*.tar.gz")
+
+ # upload
+ u_client = Client.new( @server.pkgserver_url, nil, @log )
+ u_client.update
+ snapshot = u_client.upload( @server.pkgserver_addr, @server.pkgserver_port, @server.ftp_addr, @server.ftp_port, @server.ftp_username, @server.ftp_passwd, binpkg_path_list)
+
+ if snapshot.nil? then
+ @log.info( "Upload failed...", Log::LV_USER)
+
+ return false
+ end
+
+ # update local
+ @log.info( "Upload succeeded. Sync local pkg-server again...", Log::LV_USER)
+ @pkgsvr_client.update
+ @log.info("Snapshot: #{snapshot}", Log::LV_USER)
+
+ return true
+ end
+
+
+ def copy_result_files(dst_path)
+ @log.info( "Copying result files to #{dst_path}", Log::LV_USER)
+
+ # get package path list
+ binpkg_path_list = Dir.glob("#{@source_path}/*_*_#{@os}.zip")
+
+ for file in binpkg_path_list
+ @log.info( " * #{file}", Log::LV_USER)
+ FileUtils.cp(file,"#{dst_path}/")
+ end
+
+ return true
+ end
+
+end
--- /dev/null
+=begin
+
+ BuildServer.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require 'fileutils'
+$LOAD_PATH.unshift File.dirname(__FILE__)
+require "SocketJobRequestListener.rb"
+require "RemoteBuildJob.rb"
+require "LocalBuildJob.rb"
+require "JobManager.rb"
+require "JobClean.rb"
+require "RemoteBuildServer.rb"
+require "ProjectManager.rb"
+
+class BuildServer
+ attr_accessor :id, :path, :pkgserver_url, :pkgserver_addr, :pkgserver_port, :pkgserver_id, :port, :status, :friend_servers, :host_os, :log
+ attr_accessor :git_server_url, :git_bin_path
+ attr_accessor :job_log_url
+ attr_accessor :allowed_git_branch
+ attr_accessor :send_mail
+ attr_accessor :jobmgr
+ attr_accessor :test_time
+ attr_accessor :password
+ attr_accessor :finish
+ attr_accessor :build_cache_dir
+ attr_accessor :keep_time
+ attr_accessor :ftp_addr
+ attr_accessor :ftp_port
+ attr_accessor :ftp_username
+ attr_accessor :ftp_passwd
+ attr_accessor :cleaner
+ attr_accessor :prjmgr
+ attr_accessor :incoming_path, :outgoing_path
+ attr_accessor :cancel_lock
+ CONFIG_ROOT = "#{Utils::HOME}/.build_tools/build_server"
+ HOST_OS = Utils::HOST_OS
+
+ # initialize
+ def initialize (id, path, pkgsvr_url, pkgsvr_addr, pkgsvr_port, pkgsvr_id, ftpsvr_addr, ftpsvr_port, ftpsvr_username, ftpsvr_passwd)
+ @id = id
+ @path = path
+ @pkgserver_url = pkgsvr_url
+ @pkgserver_addr = pkgsvr_addr
+ @pkgserver_port = pkgsvr_port
+ @pkgserver_id = pkgsvr_id
+ @friend_servers = []
+ @req_listener = []
+ @finish = false
+ # port number
+ @port = 2222
+ # status
+ @status = "RUNNING"
+ # host_os
+ @host_os = HOST_OS
+ # log
+ @log =nil
+ @git_server_url = "gerrithost"
+ @git_bin_path = "/usr/bin/git"
+ @job_log_url = ""
+ @allowed_git_branch = ""
+ @send_mail = "NO"
+ # local package server
+ @pkgsvr_cache_path = nil
+ # Job Manager
+ @jobmgr = JobManager.new(self)
+ @test_time=0 #test time in mili-seconds
+ @password="0000"
+ @keep_time=86400
+ @ftp_addr = ftpsvr_addr
+ @ftp_port = ftpsvr_port
+ @ftp_username = ftpsvr_username
+ @ftp_passwd = ftpsvr_passwd
+ @cleaner=nil
+ @prjmgr = ProjectManager.new(self)
+ #
+ @incoming_path = "#{@path}/incoming"
+ @outgoing_path = "#{@path}/outgoing"
+ @cancel_lock = Mutex.new
+ end
+
+
+ # start server daemon
+ def start
+ # start
+ @log = Log.new( "#{BuildServer::CONFIG_ROOT}/#{@id}/log" )
+
+ # set build cache dir
+ @build_cache_dir="#{BuildServer::CONFIG_ROOT}/#{@id}/build_cache"
+ if not File.exist? @build_cache_dir then
+ FileUtils.mkdir_p @build_cache_dir
+ end
+
+ # init incoming/outgoing path
+ if not File.exist? @incoming_path then FileUtils.mkdir_p @incoming_path end
+ if not File.exist? @outgoing_path then FileUtils.mkdir_p @outgoing_path end
+
+ # init project mgr
+ @log.info "Setting Project Manager..."
+ @prjmgr.load()
+
+ # set local package server for cache
+ @log.info "Setting local package server..."
+ pkgsvr_id = @id
+ pkgsvr_dist = @pkgserver_url.split("/")[-1]
+
+ # set job request listener
+ @log.info "Setting listener..."
+ listener2 = SocketJobRequestListener.new(self)
+ listener2.start
+ @req_listener.push listener2
+
+ # set job cleaner
+ @log.info "Setting Job Cleaner..."
+ @cleaner = JobCleaner.new(self)
+ @cleaner.start
+
+ # main loop
+ @log.info "Entering main loop..."
+ if @test_time > 0 then start_time = Time.now end
+ while( not @finish )
+
+ # update friend server status
+ for server in @friend_servers
+ # update state
+ server.update_state
+ end
+
+ # handle jobs
+ @jobmgr.handle()
+
+ # sleep
+ if @test_time > 0 then
+ curr_time = Time.now
+ if (curr_time - start_time).to_i > @test_time then
+ puts "Test time is elapsed!"
+ break
+ end
+ else
+ sleep 1
+ end
+ end
+
+ # TODO: something should be done for server down
+
+ end
+
+
+ # stop sever daemon
+ def stop
+ @finish = true
+ end
+
+
+ # check the job can be built on this server
+ def can_build?(job)
+ # check max allowed jobs
+ if @jobmgr.max_working_jobs <= 0 then
+ return false
+ end
+
+ # check me
+ if job.can_be_built_on? @host_os then
+ return true
+ end
+
+ return false
+ end
+
+
+ # add new remote friend server
+ def add_remote_server( ip, port )
+
+ # if already exit, return false
+ for svr in @friend_servers
+ if svr.ip.eql? ip and svr.port == port then
+ return false
+ end
+ end
+
+ # create new one, and add it into list
+ new_server = RemoteBuildServer.new( ip, port, self )
+ @friend_servers.push new_server
+
+ return true
+ end
+
+
+ # get remote server
+ def get_available_server ( job )
+ candidates = []
+
+ # calculate empty rooms
+ # if fullbuild job, his parent should be excluded
+ local_empty_rooms = @jobmgr.get_number_of_empty_room
+ if job.is_fullbuild_job then
+ local_empty_rooms += 1
+ end
+
+ if local_empty_rooms > 0 and can_build?(job) then
+ candidates.push self
+ end
+
+ # get availables server
+ # but, job must not be "REGISTER" job
+ if job.type != "REGISTER" then
+ for server in @friend_servers
+ if ( server.status == "RUNNING" and server.can_build?( job ) and
+ not server.has_waiting_jobs and
+ server.get_number_of_empty_room > 0 )
+ candidates.push server
+ end
+ end
+ end
+
+ best_server = candidates[0]
+ if best_server.nil? or candidates.count == 1 then return best_server end
+
+ # get best
+ # it is better if working jobs count is less
+ max_empty_room = best_server.get_number_of_empty_room
+ for server in candidates
+ # check whether idle, use it
+ if not server.has_working_jobs then return server end
+
+ # skip
+ if server == best_server then next end
+
+ # compare remain rooms
+ empty_room = server.get_number_of_empty_room
+ if empty_room > max_empty_room then
+ max_empty_room = empty_root
+ best_server = server
+ end
+ end
+
+ return best_server
+ end
+
+
+ # check there is some servers that can build the job
+ def check_job_availability(job)
+
+ # check me
+ if can_build? job then return true end
+
+ #if not found, check friends
+ for server in @friend_servers
+ if server.status == "RUNNING" and
+ job.can_be_built_on? server.host_os then
+ return true
+ end
+ end
+
+ return false
+ end
+
+
+ # return available working slot
+ def get_number_of_empty_room
+ return @jobmgr.get_number_of_empty_room
+ end
+
+
+ # check there are working jobs
+ def has_working_jobs
+ return @jobmgr.has_working_jobs
+ end
+
+
+ # check there are waiting jobs
+ def has_waiting_jobs
+ return @jobmgr.has_waiting_jobs
+ end
+
+end
+
--- /dev/null
+=begin
+
+ BuildServerController.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+$LOAD_PATH.unshift File.dirname(__FILE__)
+require "BuildServer.rb"
+require "BuildComm.rb"
+
+class BuildServerController
+ @@instance_map = {}
+
+ # create
+ def self.create_server (id, path, pkgsvr_url, pkgsvr_addr, pkgsvr_port, pkgsvr_id, ftpsvr_addr, ftpsvr_port, ftpsvr_username, ftpsvr_passwd)
+
+ # check server config root
+ check_build_server_root
+
+ # check id
+ if File.exist? "#{BuildServer::CONFIG_ROOT}/#{id}"
+ raise RuntimeError, "Creating server failed. The server id is already exist"
+ end
+
+ # create new instance and return it
+ @@instance_map[id] = BuildServer.new( id, path, pkgsvr_url, pkgsvr_addr, pkgsvr_port, pkgsvr_id, ftpsvr_addr, ftpsvr_port, ftpsvr_username, ftpsvr_passwd)
+
+ # set default
+ @@instance_map[id].git_server_url="gerrithost:"
+ if Utils::HOST_OS == "windows" then
+ @@instance_map[id].git_bin_path="/c/Program\\ Files/Git/bin/git.exe"
+ else
+ @@instance_map[id].git_bin_path="/usr/bin/git"
+ end
+ @@instance_map[id].allowed_git_branch=nil
+ @@instance_map[id].jobmgr.max_working_jobs= 2
+ @@instance_map[id].job_log_url=""
+ @@instance_map[id].send_mail="NO"
+
+
+ # write config
+ write_server_config( @@instance_map[id] )
+
+ puts "Created new build server: \"#{id}\""
+ return @@instance_map[id]
+ end
+
+
+ def self.remove_server (id)
+
+ # check server config root
+ check_build_server_root
+
+ # check id
+ if File.exist? "#{BuildServer::CONFIG_ROOT}/#{id}"
+ FileUtils.rm_rf "#{BuildServer::CONFIG_ROOT}/#{id}"
+ @@instance_map[id] = nil
+ puts "Removed the server \"#{id}\""
+ else
+ puts "The server \"#{id}\" does not exist!"
+ end
+ end
+
+
+ # get
+ def self.get_server( id )
+
+ # check instance first
+ if not @@instance_map[id] == nil
+ return @@instance_map[id]
+ end
+
+ # check server config
+ if not File.exist? "#{BuildServer::CONFIG_ROOT}/#{id}/server.cfg"
+ raise RuntimeError, "The server \"#{id}\" does not exist!"
+ end
+
+ # get server config and return its object
+ @@instance_map[id] = read_server_config(id)
+
+ return @@instance_map[id]
+ end
+
+
+ # start server
+ def self.start_server( id, port = 2222 )
+ server = get_server(id)
+
+ # write run port
+ server_dir = "#{BuildServer::CONFIG_ROOT}/#{server.id}"
+ f = File.open( "#{server_dir}/run", "w" )
+ f.puts port
+ f.close
+
+ # start
+ server.port = port
+ server.start
+ end
+
+
+ # stop server
+ def self.stop_server( id )
+
+ # server
+ server = get_server(id)
+ client = BuildCommClient.create( "127.0.0.1", server.port )
+ if client.nil? then
+ puts "Server is not running!"
+ return false
+ end
+
+ # send request
+ stop_ok = false
+ if client.send "STOP,#{server.password}" then
+ # recevie & print
+ mismatched = false
+ result = client.read_lines do |l|
+ puts l
+ if l.include? "Password mismatched!" then
+ mismatched = true
+ end
+ end
+ if result and not mismatched then
+ stop_ok = true
+ end
+ end
+
+ # terminate
+ client.terminate
+
+ if not stop_ok then
+ puts "Server stop failed!"
+ end
+
+ return true
+ end
+
+
+ # add friend server
+ def self.add_friend_server( id, ip, port )
+ server = get_server(id)
+
+ # add
+ if server.add_remote_server( ip, port ) then
+
+ # write config
+ server_dir = "#{BuildServer::CONFIG_ROOT}/#{server.id}"
+ f = File.open( "#{server_dir}/friends", "a" )
+ f.puts "#{ip},#{port}"
+ f.close
+
+ puts "Friend server is added successfully!"
+
+ return true
+ else
+ puts "Friend server already exists in list!"
+ return false
+ end
+ end
+
+
+ # build git repository and upload
+ def self.build_git( id, repository, commit, os, url, resolve )
+
+ # server
+ server = get_server(id)
+ client = BuildCommClient.create( "127.0.0.1", server.port )
+ if client.nil? then return false end
+
+ # send request
+ client.send "BUILD,GIT,#{repository},#{commit},#{os}"
+
+ # recevie & print
+ client.print_stream
+
+ # terminate
+ client.terminate
+
+ return true
+ end
+
+
+ # resolve git and build it and upload
+ def resolve_git( id, repository, commit, os, url )
+ # server
+ server = get_server(id)
+ client = BuildCommClient.create( "127.0.0.1", server.port )
+ if client.nil? then return false end
+
+ # send request
+ client.send "RESOLVE,GIT,#{repository},#{commit},#{os}"
+
+ # recevie & print
+ client.print_stream
+
+ # terminate
+ client.terminate
+
+ return true
+ end
+
+
+ # build local project and upload
+ def self.build_local( id, local_path, os, url, resolve )
+ # server
+ server = get_server(id)
+ client = BuildCommClient.create( "127.0.0.1", server.port )
+ if client.nil? then return false end
+
+ # send request
+ client.send "BUILD,LOCAL,#{local_path},#{os}"
+
+ # recevie & print
+ client.print_stream
+
+ # terminate
+ client.terminate
+
+ return true
+ end
+
+
+ # resolve local project and build it and upload
+ def resolve_local( path, os )
+ # server
+ server = get_server(id)
+ client = BuildCommClient.create( "127.0.0.1", server.port )
+ if client.nil? then return false end
+
+ # send request
+ client.send "RESOLVE,LOCAL,#{local_path},#{os}"
+
+ # recevie & print
+ client.print_stream
+
+ # terminate
+ client.terminate
+
+ return true
+ end
+
+
+ # add project
+ def self.add_project( id, project_name, git_repos, git_branch, remote_server_id, passwd, os_string )
+ server = get_server(id)
+
+ # get supported os
+ if os_string.nil? then
+ os_list = ["linux", "windows"]
+ else
+ os_list = os_string.strip.split(",")
+ end
+
+ # add
+ if not git_repos.nil? and not git_branch.nil? then
+ result = server.prjmgr.add_git_project( project_name, git_repos, git_branch, passwd, os_list )
+ elsif not remote_server_id.nil? then
+ result = server.prjmgr.add_remote_project( project_name, remote_server_id, passwd, os_list)
+ else
+ result = false
+ end
+
+ if result then
+ puts "Adding project succeeded!"
+ return true
+ else
+ puts "Adding project failed!"
+ return false
+ end
+ end
+
+
+ # add binary project
+ def self.add_binary_project( id, project_name, pkg_name, passwd, os_string )
+ server = get_server(id)
+
+ # get supported os
+ if os_string.nil? then
+ os_list = ["linux", "windows"]
+ else
+ os_list = os_string.strip.split(",")
+ end
+
+ # add
+ result = server.prjmgr.add_binary_project( project_name, pkg_name, passwd, os_list )
+
+ if result then
+ puts "Adding project succeeded!"
+ return true
+ else
+ puts "Adding project failed!"
+ return false
+ end
+ end
+
+
+ # full build
+ def self.build_all_projects( id )
+
+ # server
+ server = get_server(id)
+ client = BuildCommClient.create( "127.0.0.1", server.port )
+ if client.nil? then
+ puts "Server is not running!"
+ return false
+ end
+
+ # send request
+ fullbuild_ok = false
+ if client.send "FULLBUILD,#{server.password}" then
+ # recevie & print
+ mismatched = false
+ result = client.read_lines do |l|
+ puts l
+ if l.include? "Password mismatched!" then
+ mismatched = true
+ end
+ end
+ if result and not mismatched then
+ fullbuild_ok = true
+ end
+ end
+
+ # terminate
+ client.terminate
+
+ if not fullbuild_ok then
+ puts "Full build failed!"
+ end
+
+ return true
+ end
+
+
+ def self.register_package(id, file_path)
+ # server
+ server = get_server(id)
+ client = BuildCommClient.create( "127.0.0.1", server.port )
+ if client.nil? then
+ puts "Server is not running!"
+ return false
+ end
+
+ if not File.exist? file_path then
+ puts "File not found!"
+ return false
+ end
+
+ file_path = File.expand_path(file_path)
+ # send request
+ success = false
+ if client.send "REGISTER,BINARY-LOCAL,#{file_path},#{server.password}" then
+ # recevie & print
+ mismatched = false
+ result = client.read_lines do |l|
+ puts l
+ if l.include? "Password mismatched!" then
+ mismatched = true
+ end
+ end
+ if result and not mismatched then
+ success = true
+ end
+ end
+
+ # terminate
+ client.terminate
+
+ if not success then
+ puts "Registering package failed!"
+ end
+
+ return true
+ end
+
+ private
+
+ # check build server config path
+ def self.check_build_server_root
+ if not File.exist? BuildServer::CONFIG_ROOT
+ puts "Server configuation is not found."
+ puts "Creating new server configuration... #{BuildServer::CONFIG_ROOT}"
+ FileUtils.mkdir_p "#{BuildServer::CONFIG_ROOT}"
+ end
+ end
+
+
+ # write server configuration
+ def self.write_server_config( server )
+ # create config folder
+ server_dir = "#{BuildServer::CONFIG_ROOT}/#{server.id}"
+ if not File.exist? server_dir then
+ FileUtils.mkdir_p( server_dir )
+ end
+
+ # write configuration
+ File.open( "#{server_dir}/server.cfg", "w" ) do |f|
+ f.puts "ID=#{server.id}"
+ f.puts "PATH=#{server.path}"
+ f.puts "PSERVER_URL=#{server.pkgserver_url}"
+ f.puts "PSERVER_ADDR=#{server.pkgserver_addr}"
+ f.puts "PSERVER_PORT=#{server.pkgserver_port}"
+ f.puts "PSERVER_ID=#{server.pkgserver_id}"
+ f.puts "GIT_SERVER_URL=#{server.git_server_url}"
+ f.puts "GIT_BIN_PATH=#{server.git_bin_path}"
+ f.puts "ALLOWED_GIT_BRANCH=#{server.allowed_git_branch}"
+ f.puts "MAX_WORKING_JOBS=#{server.jobmgr.max_working_jobs}"
+ f.puts "JOB_LOG_URL=#{server.job_log_url}"
+ f.puts "SEND_MAIL=#{server.send_mail}"
+ f.puts "TEST_TIME=#{server.test_time}" if server.test_time > 0
+ f.puts "PASSWORD=#{server.test_time}" if server.password != "0000"
+ f.puts "JOB_KEEP_TIME=#{server.keep_time}"
+ f.puts "FTP_ADDR=#{server.ftp_addr}"
+ f.puts "FTP_PORT=#{server.ftp_port}"
+ f.puts "FTP_USERNAME=#{server.ftp_username}"
+ f.puts "FTP_PASSWD=#{server.ftp_passwd}"
+ end
+ end
+
+
+ # read server configuration
+ def self.read_server_config( id )
+ path=""
+ pkgsvr_url=""
+ pkgsvr_addr=""
+ pkgsvr_port="3333"
+ pkgsvr_id=""
+ git_server_url="gerrithost:"
+ git_bin_path="/usr/bin/git"
+ allowed_git_branch=""
+ max_working_jobs= 2
+ job_log_url=""
+ send_mail="NO"
+ test_time=0
+ password="0000"
+ keep_time=86400
+ ftp_addr=""
+ ftp_port="21"
+ ftp_username=""
+ ftp_passwd=""
+
+ # read configuration
+ server_dir = "#{BuildServer::CONFIG_ROOT}/#{id}"
+ File.open( "#{server_dir}/server.cfg", "r" ) do |f|
+ f.each_line do |l|
+ idx = l.index("=") + 1
+ length = l.length - idx
+
+ if l.start_with?("PATH=")
+ path = l[idx,length].strip
+ elsif l.start_with?("PSERVER_URL=")
+ pkgsvr_url = l[idx,length].strip
+ elsif l.start_with?("PSERVER_ADDR=")
+ pkgsvr_addr = l[idx,length].strip
+ elsif l.start_with?("PSERVER_PORT=")
+ pkgsvr_port = l[idx,length].strip
+ elsif l.start_with?("PSERVER_ID=")
+ pkgsvr_id = l[idx,length].strip
+ elsif l.start_with?("GIT_SERVER_URL=")
+ git_server_url = l[idx,length].strip
+ elsif l.start_with?("GIT_BIN_PATH=")
+ git_bin_path = l[idx,length].strip
+ elsif l.start_with?("ALLOWED_GIT_BRANCH=")
+ allowed_git_branch = l[idx,length].strip
+ elsif l.start_with?("MAX_WORKING_JOBS=")
+ max_working_jobs = l[idx,length].strip.to_i
+ elsif l.start_with?("JOB_LOG_URL=")
+ job_log_url = l[idx,length].strip
+ elsif l.start_with?("SEND_MAIL=")
+ send_mail = l[idx,length].strip
+ elsif l.start_with?("TEST_TIME=")
+ test_time = l[idx,length].strip.to_i
+ elsif l.start_with?("PASSWORD=")
+ password = l[idx,length].strip.to_i
+ elsif l.start_with?("JOB_KEEP_TIME=")
+ keep_time = l[idx,length].strip.to_i
+ elsif l.start_with?("FTP_ADDR=")
+ ftp_addr = l[idx,length].strip
+ elsif l.start_with?("FTP_PORT=")
+ ftp_port = l[idx,length].strip
+ elsif l.start_with?("FTP_USERNAME=")
+ ftp_username = l[idx,length].strip
+ elsif l.start_with?("FTP_PASSWD=")
+ ftp_passwd = l[idx,length].strip
+ else
+ next
+ end
+ end
+ end
+
+ # create server object
+ obj = BuildServer.new( id, path, pkgsvr_url, pkgsvr_addr, pkgsvr_port, pkgsvr_id, ftp_addr, ftp_port, ftp_username, ftp_passwd )
+
+ # check running port
+ if File.exist? "#{server_dir}/run" then
+ f = File.open( "#{server_dir}/run", "r" )
+ l = f.gets
+ obj.port = l.strip.to_i
+ f.close
+ end
+
+ # check friend server
+ if File.exist? "#{server_dir}/friends" then
+ File.open( "#{server_dir}/friends", "r" ) do |f|
+ f.each_line do |l|
+ if l.split(",").count < 2 then next end
+ ip = l.split(",")[0].strip
+ port = l.split(",")[1].strip
+ obj.add_remote_server( ip, port.to_i )
+ end
+ end
+ end
+
+ # set git server url
+ obj.git_server_url = git_server_url
+
+ # set git binary path
+ obj.git_bin_path = git_bin_path
+
+ # set git binary path
+ obj.jobmgr.max_working_jobs = max_working_jobs
+
+ # set job log url
+ obj.job_log_url = job_log_url
+
+ # set send mail
+ obj.send_mail = send_mail
+
+ # set allowed git branch name
+ obj.allowed_git_branch = allowed_git_branch
+
+ # set test time
+ obj.test_time = test_time
+
+ # set password
+ obj.password = password
+
+ # set password
+ obj.keep_time = keep_time
+
+ # set ftp infomation
+ obj.ftp_addr = ftp_addr
+ obj.ftp_port = ftp_port
+ obj.ftp_username = ftp_username
+ obj.ftp_passwd = ftp_passwd
+
+ # save config
+ write_server_config( obj )
+
+ # create object & return it
+ return obj
+ end
+end
--- /dev/null
+=begin
+
+ BuildServerOptionParser.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require 'optparse'
+
+def option_error_check( options )
+ case options[:cmd]
+
+ when "create"
+ if options[:name].nil? or options[:name].empty? or
+ options[:url].nil? or options[:url].empty? or
+ options[:domain].nil? or options[:domain].empty? or
+ options[:fdomain].nil? or options[:fdomain].empty? then
+ raise ArgumentError, "Usage: build-svr create -n <server name> -u <package server url> -d <package server address> -t <ftp server url>"
+ end
+
+ when "remove"
+ if options[:name].nil? or options[:name].empty? then
+ raise ArgumentError, "Usage: build-svr remove -n <server name>"
+ end
+
+ when "start"
+ if options[:name].nil? or options[:name].empty? or
+ options[:port].nil? then
+ raise ArgumentError, "Usage: build-svr start -n <server name> -p <port>"
+ end
+
+ when "stop"
+ if options[:name].nil? or options[:name].empty? then
+ raise ArgumentError, "Usage: build-svr stop -n <server name>"
+ end
+
+ when "add-svr"
+ if options[:name].nil? or options[:name].empty? or
+ options[:domain].nil? or options[:domain].empty? then
+ raise ArgumentError, "Usage: build-svr add-svr -n <server name> -d <friend server address>"
+ end
+
+ when "add-prj"
+ if options[:name].nil? or options[:name].empty? or
+ options[:pid].nil? or options[:pid].empty? then
+ raise ArgumentError, "Usage: build-svr add-prj -n <server name> -N <project name> [-g <git repository>] [-b <git branch>] [-P <package name>] [-w <password>] [-o <os list>]"
+ end
+
+ when "fullbuild"
+ if options[:name].nil? or options[:name].empty? then
+ raise ArgumentError, "Usage: build-svr fullbuild -n <server name>"
+ end
+
+ when "register"
+ if options[:name].nil? or options[:name].empty? or
+ options[:package].nil? or options[:package].empty? then
+ raise ArgumentError, "Usage: build-svr register -n <server name> -P <package file>"
+ end
+ else
+ raise ArgumentError, "Input is incorrect : #{options[:cmd]}"
+ end
+end
+
+def option_parse
+ options = {}
+ banner = "Build-server administer service command-line tool." + "\n" \
+ + "\n" + "Usage: build-svr <SUBCOMMAND> [OPTS] or build-svr -h" + "\n" \
+ + "\n" + "Subcommands:" + "\n" \
+ + "\t" + "create Create the build-server." + "\n" \
+ + "\t" + "remove Remove the build-server." + "\n" \
+ + "\t" + "start Start the build-server." + "\n" \
+ + "\t" + "stop Stop the build-server." + "\n" \
+ + "\t" + "add-svr Add build-server for support multi-OS or distribute build job." + "\n" \
+ + "\t" + "add-prj Register information for project what you want build berfore building a project." + "\n" \
+ + "\t" + "register Register the package to the build-server." + "\n" \
+ + "\t" + "fullbuild Build all your projects and upload them to package server." + "\n" \
+ + "\n" + "Subcommand usage:" + "\n" \
+ + "\t" + "build-svr create -n <server name> -u <package server url> -d <package server address> -t <ftp server url>" + "\n" \
+ + "\t" + "build-svr remove -n <server name>" + "\n" \
+ + "\t" + "build-svr start -n <server name> -p <port>" + "\n" \
+ + "\t" + "build-svr stop -n <server name>" + "\n" \
+ + "\t" + "build-svr add-svr -n <server name> -d <friend server address>" + "\n" \
+ + "\t" + "build-svr add-prj -n <server name> -N <project name> [-g <git repository>] [-b <git branch>] [-P <package name>] [-w <password>] [-o <os list>]" + "\n" \
+ + "\t" + "build-svr register -n <server name> -P <package file>" + "\n" \
+ + "\t" + "build-svr fullbuild -n <server name>" + "\n" \
+ + "\n" + "Options:" + "\n"
+
+ optparse = OptionParser.new(nil, 32, ' '*8) do|opts|
+ # Set a banner, displayed at the top
+ # of the help screen.
+
+ opts.banner = banner
+
+ opts.on( '-n', '--name <server name>', 'build server name' ) do|name|
+ options[:name] = name
+ end
+
+ opts.on( '-u', '--url <package server url>', 'package server url: http://127.0.0.1/dibs/unstable' ) do|url|
+ options[:url] = url
+ end
+
+ opts.on( '-d', '--address <server address>', 'server address: 127.0.0.1:2224' ) do|domain|
+ options[:domain] = domain
+ end
+
+ options[:port] = 2222
+ opts.on( '-p', '--port <port>', 'server port number: 2224' ) do|port|
+ options[:port] = port.strip.to_i
+ end
+
+ opts.on( '-P', '--pkg <package name/file>', 'package file path or name' ) do|package|
+ options[:package] = package.strip
+ end
+
+ options[:os] = nil
+ opts.on( '-o', '--os <target os list>', 'ex) linux,windows' ) do|os|
+ options[:os] = os
+ end
+
+ opts.on( '-N', '--pname <project name>', 'project name' ) do|pid|
+ options[:pid] = pid
+ end
+
+ opts.on( '-g', '--git <git repository>', 'git repository' ) do|git|
+ options[:git] = git
+ end
+
+ opts.on( '-b', '--branch <git branch>', 'git branch' ) do|branch|
+ options[:branch] = branch
+ end
+
+ #opts.on( '-r', '--remote <remote server id>', 'remote server id' ) do|remote|
+ # options[:remote] = remote
+ #end
+
+ options[:passwd] = ""
+ opts.on( '-w', '--passwd <password>', 'password for managing project' ) do|passwd|
+ options[:passwd] = passwd
+ end
+
+ opts.on( '-t', '--ftp <ftp server url>', 'ftp server url: ftp://dibsftp:dibsftp@127.0.0.1:1024' ) do|domain|
+ options[:fdomain] = domain
+ end
+
+ opts.on( '-h', '--help', 'display this information' ) do
+ puts opts
+ exit
+ end
+
+ opts.on( '-v', '--version', 'display version' ) do
+ puts "DIBS(Distributed Intelligent Build System) version 1.2.0"
+ exit
+ end
+
+ end
+
+ cmd = ARGV[0]
+ if cmd.eql? "create" or cmd.eql? "remove" or cmd.eql? "start" or
+ cmd.eql? "stop" or cmd.eql? "add-svr" or cmd.eql? "fullbuild" or
+ cmd.eql? "add-prj" or cmd.eql? "register" or
+ cmd =~ /(-v)|(--version)/ or
+ cmd =~ /(help)|(-h)|(--help)/ then
+
+ if cmd.eql? "help" then
+ ARGV[0] = "-h"
+ end
+
+ options[:cmd] = ARGV[0]
+ else
+ raise ArgumentError, "Usage: build-svr <SUBCOMMAND> [OPTS] or build-svr -h"
+ end
+
+ optparse.parse!
+
+ option_error_check options
+
+ return options
+end
+
--- /dev/null
+=begin
+
+ CommonProject.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require 'fileutils'
+$LOAD_PATH.unshift File.dirname(__FILE__)
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+
+class CommonProject
+ attr_accessor :name, :type, :passwd, :os_list
+
+ # initialize
+ def initialize( name, type, server, os_list )
+ @name = name
+ @type = type
+ @passwd = ""
+ @os_list = os_list
+ @server = server
+ end
+
+
+ #return passwd
+ def is_passwd_set?()
+ return @passwd.empty? ? false:true
+ end
+
+
+ def passwd_match?(word)
+ if not is_passwd_set? then return true end
+
+ if word.nil? then return false end
+ if word.eql? @passwd then
+ return true
+ else
+ return false
+ end
+ end
+end
--- /dev/null
+=begin
+
+ FullBuildJob.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require "fileutils"
+$LOAD_PATH.unshift File.dirname(__FILE__)
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/builder"
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/pkg_server"
+require "client.rb"
+require "PackageManifest.rb"
+require "Version.rb"
+require "Builder.rb"
+require "RemoteBuilder.rb"
+require "BuildServer.rb"
+require "JobLog.rb"
+require "mail.rb"
+
+class FullBuildJob
+
+ attr_accessor :id, :server, :pre_jobs, :os, :type
+ attr_accessor :status, :log, :source_path
+ attr_accessor :pkgsvr_client, :thread
+ attr_accessor :is_fullbuild_job
+
+ # initialize
+ def initialize (server)
+ @server = server
+ @id = server.jobmgr.get_new_job_id()
+ @log = nil
+ @type = "FULLBUILD"
+
+ @status = "JUST_CREATED"
+ @host_os = Utils::HOST_OS
+ @pkgserver_url = @server.pkgserver_url
+ @job_root = "#{@server.path}/jobs/#{@id}"
+ @source_path = @job_root+"/temp"
+ @job_working_dir=@job_root+"/works"
+ @buildroot_dir = "#{@job_root}/buildroot"
+ @pre_jobs = [] #pre-requisite jobs
+
+ @is_fullbuild_job = false
+ end
+
+
+ # execute
+ def execute(sync=false)
+ @log.info( "Invoking a thread for FULL-BUILD Job #{@id}", Log::LV_USER)
+ if @status == "ERROR" then return end
+ @thread = Thread.new {
+ # main
+ thread_main()
+
+ # close
+ terminate()
+ }
+
+ if sync then
+ @thread.join
+ end
+
+ return true
+ end
+
+
+ #
+ def init
+ # mkdir
+ if not File.exist? @job_root then
+ FileUtils.mkdir_p @job_root
+ end
+
+ # create logger
+ if @log.nil? then
+ @log = JobLog.new(self, nil )
+ end
+
+ @log.info( "Initializing job...", Log::LV_USER)
+
+ # create dummy source path
+ if not File.exist? @source_path then
+ FileUtils.mkdir_p @source_path
+ end
+
+ # set up pkgsvr_client
+ @pkgsvr_client = Client.new(@pkgserver_url, @job_working_dir, @log)
+ @pkgsvr_client.update
+
+ return true
+ end
+
+
+ #terminate
+ def terminate()
+ # report error
+ if @status == "ERROR" then
+ @log.error( "Job is stopped by ERROR" , Log::LV_USER)
+ @server.cleaner.clean_afterwards(@id)
+ else
+ # clean up
+ @server.cleaner.clean(@id)
+ end
+
+ # close logger
+ @log.close
+ end
+
+
+ #cancel
+ def cancel()
+ #TODO
+ end
+
+
+ # check building is possible
+ def can_be_built_on?(host_os)
+ return true
+ end
+
+
+ def has_build_dependency?(other_job)
+ return true
+ end
+
+
+ def has_same_packages?( wjob )
+ return self == wjob ? true : false
+ end
+
+
+ def does_depend_on?( wjob )
+ return true
+ end
+
+
+ def does_depended_by?( wjob )
+ return true
+ end
+
+
+ def is_connected?
+ return true
+ end
+
+
+ # return the job is asyncronous job
+ def is_asynchronous_job?
+ return false
+ end
+
+ # set logger
+ def set_logger( logger )
+ @log = logger
+ end
+
+
+ #
+ # PROTECTED METHODS
+ #
+ protected
+
+
+ # main module
+ def thread_main
+ @log.info( "New Job #{@id} is started", Log::LV_USER)
+
+ # check passwd
+
+ # create sub jobs
+ build_jobs = []
+ for prj in @server.prjmgr.projects
+ if prj.type != "GIT" then next end
+ build_jobs += @server.prjmgr.create_new_jobs_for_all_os( prj.name )
+ end
+
+ # set full build job flag
+ for job in build_jobs
+ job.is_fullbuild_job = true
+ job.set_parent_job( self )
+ end
+
+ # add all jobs to jobmanager
+ job_status_map = {} # for tracking job status changes
+ for job in build_jobs
+ @server.jobmgr.add_internal_job( job )
+
+ @log.info( "Added new job \"#{job.id}\"(#{job.get_project().name}) for #{job.os}!",
+ Log::LV_USER)
+
+ if not @server.job_log_url.empty? then
+ @log.info( " * Log URL : #{@server.job_log_url}/#{job.id}/log", Log::LV_USER)
+ end
+
+ # set satus
+ job_status_map[job.id] = job.status
+ end
+
+ # show job status changes
+ all_jobs_finished = false
+ error_exist = false
+ while not all_jobs_finished
+ all_jobs_finished = true
+ for job in build_jobs
+
+ # check status chanaged, if then print
+ if job_status_map[ job.id ] != job.status then
+ @log.info("Job #{job.id}(#{job.get_project().name},#{job.os}) is #{job.status}", Log::LV_USER)
+ job_status_map[ job.id ] = job.status
+ end
+ if job.status != "ERROR" and job.status != "FINISHED" then
+ all_jobs_finished = false
+ end
+ if job.status == "ERROR" then error_exist = true end
+ end
+ sleep 1
+ end
+
+ # check error
+ if error_exist then
+ @status = "ERROR"
+ return
+ end
+
+ # INFO. don't change this string
+ @log.info( "Job is completed!", Log::LV_USER)
+ @status = "FINISHED"
+ end
+
+end
--- /dev/null
+=begin
+
+ GitBuildJob.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require "fileutils"
+require "thread"
+$LOAD_PATH.unshift File.dirname(__FILE__)
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+require "BuildJob.rb"
+require "utils.rb"
+
+# mutax for git operation
+$git_mutex = Mutex.new
+
+
+class GitBuildJob < BuildJob
+
+ # initialize
+ def initialize( project, os, server )
+ super(server.jobmgr.get_new_job_id(), project, os, server)
+ @git_repos = project.repository
+ @git_branch = project.branch
+ @git_commit = nil
+ end
+
+
+ def terminate()
+ # report error
+ if @status == "ERROR" then
+ @log.error( "Job is stopped by ERROR" , Log::LV_USER)
+ @server.cleaner.clean_afterwards(@id)
+ elsif @status == "CANCELED" then
+ @log.error( "Job is CANCELED" , Log::LV_USER)
+ @server.cleaner.clean_afterwards(@id)
+ else
+ # if succeeded, register source info and copy pkginfo.manifest
+ @project.add_source_info( @pkginfo.get_version(), @git_commit)
+ @project.copy_package_info( @pkginfo.get_version(),
+ "#{@source_path}/package/pkginfo.manifest")
+
+ # clean up
+ @server.cleaner.clean(@id)
+ end
+
+ # clean up builder directory if exist?
+ if Builder.exist? "JB#{@id}" then
+ Builder.remove("JB#{@id}")
+ end
+
+ # send mail
+ if ( @server.send_mail.eql? "YES" ) and ( not @pkginfo.nil? ) and ( not @pkginfo.packages.nil? ) then
+ mail_list = []
+ contents = []
+ done_pkg_list = []
+ contents.push " "
+ contents.push " Git information : #{@git_commit} "
+ contents.push " "
+ contents.push "%-30s| %10s | %10s" % ["package name", "version", "os"]
+ contents.push "---------------------------------------------------------------"
+ for pkg in @pkginfo.packages
+ if not pkg.os.eql? @os then next end
+ mail_list = mail_list | Mail.parse_email( pkg.maintainer )
+ contents.push("%-30s| %10s | %10s" % [ pkg.package_name, pkg.version, pkg.os] )
+ end
+
+ if @status == "ERROR" then
+ subject = "[DIBS] Build fail"
+ contents.push " "
+ contents.push "check log file"
+ contents.push "* Log : #{@server.job_log_url}/#{@id}/log"
+ elsif @status == "CANCELED" then
+ subject = "[DIBS] Build canceled"
+ else
+ subject = "[DIBS] Build success"
+ end
+ Mail.send_mail(mail_list, subject, contents.join("\n"))
+ end
+
+ # close logger
+ @log.close
+ end
+
+
+ # verify
+ def init
+ # mkdir
+ if not File.exist? @job_root then
+ FileUtils.mkdir_p @job_root
+ end
+
+ # create logger
+ if @log.nil? then
+ @log = JobLog.new(self, nil )
+ end
+
+ @log.info( "Initializing job...", Log::LV_USER)
+
+ $git_mutex.synchronize {
+ # git clone
+ if not git_cmd("clone #{@git_repos} temp", @job_root) then
+ @log.error( "Failed on \"git clone #{@git_repos}\"", Log::LV_USER)
+ @status = "ERROR"
+ return false
+ end
+
+ if @git_commit.nil? then
+ # git reset
+ if not git_cmd("reset --hard origin/#{@git_branch}", @source_path) then
+ @log.error( "Failed on \"git reset --hard origin/#{@git_branch}\"", Log::LV_USER)
+ @status = "ERROR"
+ return false
+ end
+
+ # get git commit-id
+ commit_id = ""
+ result_line = git_cmd_return("log -1",@source_path)
+ if result_line != nil then
+ result_line.each do |l|
+ if l.start_with?("commit ") then
+ commit_id = l.split(" ")[1].strip
+ end
+ end
+ end
+ @git_commit = commit_id
+ else
+ # git reset
+ if not git_cmd("reset --hard #{@git_commit}", @source_path) then
+ @log.error( "Failed on \"git reset --hard #{@git_commit}\"", Log::LV_USER)
+ @status = "ERROR"
+ return false
+ end
+ end
+ }
+
+ # check pkginfo.manifest
+ if not File.exist? "#{@source_path}/package/pkginfo.manifest"
+ @log.error( "package/pkginfo.manifest doest not exist", Log::LV_USER)
+ @status = "ERROR"
+ return false
+ end
+
+ # set up pkg info
+ @pkginfo = PackageManifest.new("#{@source_path}/package/pkginfo.manifest")
+
+ # set up pkgsvr_client
+ @pkgsvr_client = Client.new(@pkgserver_url, @job_working_dir, @log)
+ @pkgsvr_client.update
+
+ # checking version if not reverse-build job
+ if not @is_rev_build_check_job and not @is_remote_job and
+ not check_package_version() then
+
+ # if fullbuild job, its OK
+ if @is_fullbuild_job then
+ @status = "FINISHED"
+ return true
+ else
+ @status = "ERROR"
+ return false
+ end
+ end
+
+ # check availabiltiy
+ if not @server.check_job_availability( self ) then
+ @log.error( "No servers that are able to build your packages.", Log::LV_USER)
+ @status = "ERROR"
+ @server.log.info "Adding the job \"#{@id}\" is canceled"
+ end
+
+ return true
+ end
+
+
+ def set_git_commit( commit )
+ @git_commit = commit
+ end
+
+
+ def git_cmd(cmd, working_dir)
+ build_command = "cd \"#{working_dir}\";#{@server.git_bin_path} #{cmd}"
+ ret = Utils.execute_shell_with_log(build_command,@log)
+
+ return ret
+ end
+
+
+ def git_cmd_return(cmd, working_dir)
+ build_command = "cd \"#{working_dir}\";#{@server.git_bin_path} #{cmd}"
+ ret = Utils.execute_shell_return(build_command)
+
+ return ret
+ end
+
+end
--- /dev/null
+=begin
+
+ GitProject.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require 'fileutils'
+$LOAD_PATH.unshift File.dirname(__FILE__)
+require "CommonProject.rb"
+require "GitBuildJob.rb"
+require "Version.rb"
+require "PackageManifest.rb"
+
+
+class GitBuildProject < CommonProject
+ attr_accessor :repository, :branch
+
+ # initialize
+ def initialize( name, repos, branch, server, os_list )
+ super(name, "GIT", server, os_list)
+ @repository = repos
+ @branch = branch
+ @source_infos = {}
+ @package_infos = {}
+ end
+
+
+ # get commid-id of specified package version
+ def get_commit_id( version )
+ return get_source_info( version )
+ end
+
+
+ # create new job
+ def create_new_job( os )
+ return GitBuildJob.new( self, os, @server )
+ end
+
+
+ # create new job
+ def create_new_job_from_version( os, version=nil )
+ new_job=create_new_job( os )
+
+ # set commit id
+ if version.nil? then
+ version = get_latest_version()
+ end
+
+ commit = get_commit_id( version )
+ if not commit.nil? then
+ new_job.set_git_commit( commit )
+ end
+
+ return new_job
+ end
+
+ # get latest package version
+ def get_latest_version()
+ versions = @package_infos.keys
+ if not versions.empty? then
+ versions.sort! {|x,y| Version.new(x).compare(Version.new(y)) }
+ return versions[-1]
+ else
+ return nil
+ end
+ end
+
+
+ # get all package version
+ def get_all_versions()
+ return @package_infos.keys
+ end
+
+
+ # add source source info
+ def add_source_info( version, info )
+ @source_infos[version] = info
+
+ # write to file
+ sources_file = "#{@server.path}/projects/#{@name}/sources"
+ File.open( sources_file, "w" ) do |f|
+ @source_infos.each { |key,value|
+ f.puts "#{key},#{value}"
+ }
+ end
+ end
+
+
+ # get source info
+ def get_source_info( version )
+ return @source_infos[version]
+ end
+
+
+ # add package info
+ def add_package_info( version, path )
+ pkginfo =PackageManifest.new(path)
+ @package_infos[version] = pkginfo
+ end
+
+
+ # get package info
+ def get_package_info( version )
+ return @package_infos[version]
+ end
+
+
+ # copy package info
+ def copy_package_info(version, file_path)
+ # check pkginfo directory
+ pkginfo_dir = "#{@server.path}/projects/#{@name}/pkginfos"
+ if not File.exist? pkginfo_dir then
+ FileUtils.mkdir_p pkginfo_dir
+ end
+
+ # copy
+ pkginfo_file = "#{pkginfo_dir}/#{version}.manifest"
+ FileUtils.cp(file_path, pkginfo_file)
+
+ add_package_info(version, pkginfo_file)
+ end
+
+
+ def include_package?(name, version=nil, os=nil)
+ # check version first
+ if not version.nil? then
+ version = get_latest_version()
+ end
+
+ if version.nil? or @package_infos[version].nil? then return false end
+
+ # check name and version
+ pkginfo=@package_infos[version]
+ pkg_list = os.nil? ? pkginfo.packages : pkginfo.get_target_packages(os)
+ for pkg in pkg_list
+ if pkg.package_name.eql? name then return true end
+ end
+
+ return false
+ end
+end
--- /dev/null
+=begin
+
+ ScheduledActionHandler.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require "fileutils"
+require "thread"
+$LOAD_PATH.unshift File.dirname(__FILE__)
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+require "BuildServer.rb"
+require "Action.rb"
+require "ScheduledActionHandler.rb"
+
+$access_listfile = Mutex.new
+
+class JobCleanAction < Action
+
+ def initialize( time, job_path, list_file )
+ super(time,0)
+
+ @job_path = job_path
+ @job_id = @job_path.split("/")[-1]
+ @list_file = list_file
+ end
+
+
+ def init
+ $access_listfile.synchronize {
+ File.open(@list_file, "a") do |f|
+ f.puts "#{@job_id},#{time.year},#{time.month},#{time.day},#{time.hour},#{time.min},#{time.sec}"
+ end
+ }
+ end
+
+
+ def execute
+
+ # remove directories
+ if File.exist? "#{@job_path}/buildroot" then
+ FileUtils.rm_rf "#{@job_path}/buildroot"
+ end
+ if File.exist? "#{@job_path}/temp" then
+ FileUtils.rm_rf "#{@job_path}/temp"
+ end
+
+ # remove line for the job
+ $access_listfile.synchronize {
+ lines = []
+ # get all lines
+ if File.exist? @list_file then
+ File.open(@list_file,"r") do |f|
+ f.each_line do |l|
+ lines.push l
+ end
+ end
+ end
+
+ # write the line except my job_id
+ File.open(@list_file,"w") do |f|
+ for l in lines
+ if l.split(",")[0].eql? @job_id then next end
+ f.puts l
+ end
+ end
+ }
+ end
+end
+
+
+class JobCleaner
+ attr_accessor :quit
+
+ # init
+ def initialize( server )
+ @server = server
+ @handler = ScheduledActionHandler.new
+ @list_file = "#{BuildServer::CONFIG_ROOT}/#{@server.id}/clean"
+ end
+
+
+ # start thread
+ def start()
+
+ list_file2 = "#{BuildServer::CONFIG_ROOT}/#{@server.id}/clean_backup"
+ jobs_path = "#{@server.path}/jobs"
+ if not File.exist? jobs_path then
+ FileUtils.mkdir_p jobs_path
+ end
+
+ # read clean list
+ clean_list = []
+ if File.exist? @list_file then
+ FileUtils.mv(@list_file,list_file2)
+ File.open(list_file2, "r") do |f|
+ f.each_line do |l|
+ id = l.split(",")[0]
+ year = l.split(",")[1]
+ month = l.split(",")[2]
+ day = l.split(",")[3]
+ hour = l.split(",")[4]
+ min = l.split(",")[5]
+ sec = l.split(",")[6]
+
+ # create job and register
+ job_path = "#{jobs_path}/#{id}"
+ time = Time.mktime(year.to_i, month.to_i, day.to_i, hour.to_i, min.to_i, sec.to_i)
+ @server.log.info "Registered clean-action for the job in list : #{id}"
+ @handler.register(JobCleanAction.new(time,job_path,@list_file))
+
+ # add clean list
+ clean_list.push id
+ end
+ end
+ end
+
+
+ # scan all jobs
+ for id in Dir.new(jobs_path).entries
+ # skip . or ..
+ if id.eql? "." or id.eql? ".." then next end
+
+ if not clean_list.include? id then
+ job_path = "#{jobs_path}/#{id}"
+ time = Time.now
+ @server.log.info "Registered clean-action for old job : #{id}"
+ @handler.register(JobCleanAction.new(time,job_path,@list_file))
+ end
+ end
+
+ # start handler
+ @handler.start
+ end
+
+
+ # clean after some time
+ def clean_afterwards(job_id)
+ curr = Time.now
+ time = Time.now + @server.keep_time
+ job_path = "#{@server.path}/jobs/#{job_id}"
+ @handler.register(JobCleanAction.new(time, job_path, @list_file))
+ end
+
+
+ # clean directly
+ def clean(job_id)
+ time = Time.now
+ job_path = "#{@server.path}/jobs/#{job_id}"
+ @handler.register(JobCleanAction.new(time, job_path, @list_file))
+ end
+end
--- /dev/null
+=begin
+
+ JobLog.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+$LOAD_PATH.unshift File.dirname(__FILE__)
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__)) + "/common"
+require "log"
+require "logger"
+require "BuildComm.rb"
+
+class JobLog < Log
+
+ def initialize(job, stream_out)
+ if job.nil? then
+ super(nil)
+ else
+ if not File.exist? "#{job.server.path}/jobs/#{job.id}" then
+ FileUtils.mkdir_p "#{job.server.path}/jobs/#{job.id}"
+ end
+ super("#{job.server.path}/jobs/#{job.id}/log")
+ end
+ @parent_job=job
+ @second_out = stream_out
+ end
+
+
+ def set_second_out( out )
+ @second_out = out
+ end
+
+
+ def init
+ # comm-begin
+ if not @second_out.nil? and not @second_out.closed? then
+ BuildCommServer.send_begin(@second_out)
+ end
+ end
+
+
+ def close
+ # close communication
+ if not @second_out.nil? then
+ begin
+ if not @second_out.closed? then
+ BuildCommServer.send_end(@second_out)
+ end
+ rescue
+ end
+ BuildCommServer.disconnect(@second_out)
+ end
+
+ @second_out = nil
+ end
+
+
+ def is_connected?
+ if @second_out.nil? or @second_out.closed? then
+ return false
+ else
+ return true
+ end
+ end
+
+
+ def has_second_out?
+ if @second_out.nil? then
+ return false
+ else
+ return true
+ end
+ end
+
+
+ protected
+
+ # overide
+ def output_extra(msg)
+ begin
+ if not @second_out.nil? then
+ BuildCommServer.send( @second_out, msg )
+ end
+ rescue
+ close()
+ error "Connection closed by remote client"
+
+ if not @parent_job.nil? then
+ @parent_job.status="ERROR"
+ # terminate job
+ @parent_job.terminate
+ # exit thread if independent worker thread
+ if @parent_job.thread == Thread.current then
+ error "Thread wiil be terminated"
+ @parent_job.thread=nil
+ Thread.exit
+ end
+ end
+
+ end
+ end
+
+end
--- /dev/null
+=begin
+
+ JobManager.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require 'fileutils'
+$LOAD_PATH.unshift File.dirname(__FILE__)
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/pkg_server"
+require "SocketJobRequestListener.rb"
+require "RemoteBuildJob.rb"
+require "LocalBuildJob.rb"
+require "RegisterPackageJob.rb"
+require "packageServer.rb"
+
+class JobManager
+ attr_accessor :max_working_jobs, :jobs
+
+ # initialize
+ def initialize( parent )
+ @parent = parent
+ @jobs = []
+ @internal_jobs = []
+ @max_working_jobs=2
+ @new_job_index = 0
+ end
+
+
+ # get new id
+ def get_new_job_id
+ # check file
+ server_dir = "#{BuildServer::CONFIG_ROOT}/#{@parent.id}"
+ if File.exist? "#{server_dir}/latest_job" then
+ f = File.open( "#{server_dir}/latest_job", "r" )
+ @new_job_index = f.gets.strip.to_i + 1
+ f.close
+ end
+
+ # get new id
+ new_id = @new_job_index
+
+ # save it
+ f = File.open( "#{server_dir}/latest_job", "w" )
+ f.puts "#{new_id}"
+ f.close
+
+ return new_id
+ end
+
+
+ def create_new_register_job( file_path )
+ return RegisterPackageJob.new( file_path, @parent )
+ end
+
+ # add a normal job
+ def add_job ( new_job )
+ @parent.log.info "Added new job \"#{new_job.id}\""
+ new_job.status = "JUST_CREATED"
+ @jobs.push( new_job )
+ end
+
+
+ # add internal job (reverse-build or full-build)
+ def add_internal_job( new_job )
+ @parent.log.info "Added new job \"#{new_job.id}\""
+ new_job.status = "JUST_CREATED"
+ @internal_jobs.push( new_job )
+ end
+
+
+ # intialize normal job
+ def initialize_job ( job )
+ job.status = "INITIALIZING"
+ Thread.new {
+ # init
+ if not job.init or job.status == "ERROR" then
+ job.status = "ERROR"
+ @parent.log.info "Adding the job \"#{job.id}\" is canceled"
+ job.terminate()
+ Thread.current.exit
+ end
+ if job.status != "FINISHED" then
+ job.status = "WAITING"
+ end
+ @parent.log.info "Checking the job \"#{job.id}\" was finished!"
+ }
+ end
+
+
+ #execute
+ def execute(job)
+ job.status = "WORKING"
+
+ # start build
+ job.execute
+ @parent.log.info "Moved the job \"#{job.id}\" to working job list"
+ end
+
+
+ # execute remote
+ def execute_remote(job, rserver)
+
+ # start build
+ job.set_remote_job(rserver)
+ if job.execute() then
+ # status change & job control
+ job.status = "REMOTE_WORKING"
+ @parent.log.info "Moved the job \"#{job.id}\" to remote job list"
+ else
+ @parent.log.info "Moving the job \"#{job.id}\" to remote failed"
+ end
+ end
+
+
+ # handle
+ def handle()
+
+ # for internal jobs
+ for job in @internal_jobs
+ # if "ERROR", "FINISHED", "CANCELED" remove it from list
+ if job.status == "ERROR"
+ @parent.log.info "Job \"#{job.id}\" is stopped by ERROR"
+ @internal_jobs.delete job
+ elsif job.status == "FINISHED"
+ @internal_jobs.delete job
+ elsif job.status == "CANCELED"
+ @internal_jobs.delete job
+ end
+
+ # if "JUST_CREATED", initialize it
+ if job.status == "JUST_CREATED" then
+ initialize_job( job )
+ end
+ end
+
+ # for normal job
+ for job in @jobs
+ # if "ERROR", "FINISHED", "CANCELED" remove it from list
+ if job.status == "ERROR"
+ @parent.log.info "Job \"#{job.id}\" is stopped by ERROR"
+ @jobs.delete job
+ elsif job.status == "FINISHED"
+ @jobs.delete job
+ elsif job.status == "CANCELED"
+ @jobs.delete job
+ end
+
+ # if "JUST_CREATED", initialize it
+ if job.status == "JUST_CREATED" then
+ initialize_job( job )
+ end
+
+ # check the connection if job is not asynchronous job
+ if ( job.status == "WAITING" or job.status == "REMOTE_WORKING") and
+ not job.is_asynchronous_job? and
+ not job.is_connected? then
+
+ job.status = "ERROR"
+ @jobs.delete( job )
+ @parent.log.info "Job \"#{job.id}\" is disconnected by user. Removed!"
+ end
+ end
+
+ # check internal job first, if not exist, get new available job
+ if @internal_jobs.count > 0 then
+ job = get_available_internal_job
+ else
+ job = get_available_job
+ end
+
+ # available job not exist?, continue
+ if not job.nil? then
+ # oherwise, check remote server
+ rserver = @parent.get_available_server( job )
+ if rserver != nil and rserver == @parent then
+ execute(job)
+ elsif rserver != nil then
+ execute_remote(job, rserver)
+ else
+ #puts "No available server"
+ end
+ end
+
+ end
+
+
+ # select the job whith no build-dependency problem
+ def get_available_job
+ return get_available_job_in_list(@jobs)
+ end
+
+
+ # select the job whith no build-dependency problem
+ def get_available_internal_job
+ return get_available_job_in_list(@internal_jobs)
+ end
+
+
+
+ # return "max_working_jobs_cnt - current_working_jobs_cnt"
+ def get_number_of_empty_room
+ working_cnt = 0
+ for job in @jobs + @internal_jobs
+ if job.status == "WORKING" then
+ working_cnt = working_cnt + 1
+ end
+ end
+
+ return @max_working_jobs - working_cnt
+ end
+
+
+ # check there are working jobs
+ def has_working_jobs
+ working_cnt = 0
+ for job in @jobs + @internal_jobs
+ if job.status == "WORKING" then
+ return true
+ end
+ end
+
+ return false
+ end
+
+
+ # check there are waiting jobs
+ def has_waiting_jobs
+ waiting_cnt = 0
+ for job in @jobs + @internal_jobs
+ if job.status == "WAITING" then
+ return true
+ end
+ end
+
+ return false
+ end
+
+
+ def get_working_jobs
+ result = []
+ for job in @jobs + @internal_jobs
+ if job.status == "WORKING" then
+ result.push job
+ end
+ end
+
+ return result
+ end
+
+
+ def get_waiting_jobs
+ result = []
+ for job in @jobs + @internal_jobs
+ if job.status == "WAITING" then
+ result.push job
+ end
+ end
+
+ return result
+ end
+
+
+ def get_remote_jobs
+ result = []
+ for job in @jobs + @internal_jobs
+ if job.status == "REMOTE_WORKING" then
+ result.push job
+ end
+ end
+
+ return result
+ end
+
+
+ def get_pending_jobs
+ result = []
+ for job in @jobs
+ if job.status == "PENDING" then
+ result.push job
+ end
+ end
+ return result
+ end
+
+
+ protected
+ # select the job whith no build-dependency problem
+ def get_available_job_in_list( jobs )
+
+ # gather all working jobs and full-build jobs
+ all_working_jobs = []
+ full_build_jobs = []
+ uninit_fjob_exist = false #uninitialized full build job exist flag
+ for job in jobs
+ if job.status == "WORKING" or job.status == "REMOTE_WORKING" then
+ all_working_jobs.push job
+ end
+ if job.is_fullbuild_job then
+ if job.status == "WAITING" then
+ full_build_jobs.push job
+ end
+ if job.status == "JUST_CREATED" or job.status == "INITIALIZING" then
+ uninit_fjob_exist = true
+ end
+ end
+ end
+
+ # for waiting jobs
+ for job in jobs
+ if job.status != "WAITING" then next end
+
+ # check build dependency against working job
+ pre_jobs = []
+ for wjob in all_working_jobs
+ if job.has_build_dependency?( wjob ) then
+ pre_jobs.push wjob
+ end
+ end
+
+ # if full build job, do something special
+ if job.is_fullbuild_job then
+ # wait all full build jobs are ready
+ if uninit_fjob_exist then next end
+ # if full build job, check build-dep among full-build jobs
+ for fjob in full_build_jobs
+ if job == fjob then next end
+ if job.does_depend_on?( fjob ) then
+ pre_jobs.push fjob
+ end
+ end
+ end
+
+ # check pre-requisite jobs are changed, notify to user
+ is_changed = false
+ if pre_jobs.count != job.pre_jobs.count then
+ is_changed=true
+ else
+ for pjob in pre_jobs
+ if not job.pre_jobs.include? pjob then
+ is_changed = true
+ break
+ end
+ end
+ end
+ if pre_jobs.count > 0 and is_changed then
+ job.log.info( "Waiting for finishing following jobs:", Log::LV_USER)
+ for bjob in pre_jobs
+ if bjob.type == "BUILD" then
+ job.log.info( " * #{bjob.id} #{bjob.pkginfo.packages[0].source}", Log::LV_USER)
+ elsif bjob.type == "FULLBUILD" then
+ job.log.info( " * #{bjob.id} (Full Build Job)", Log::LV_USER)
+ end
+ end
+ end
+ job.pre_jobs = pre_jobs
+
+ # no pre-requisite jobs, return its job
+ if job.pre_jobs.count == 0 then
+ pre_jobs.push fjob
+ return job
+ end
+ end
+
+ return nil
+ end
+end
--- /dev/null
+=begin
+
+ LocalBuildJob.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+$LOAD_PATH.unshift File.dirname(__FILE__)
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+require "BuildJob.rb"
+require "utils.rb"
+
+class LocalBuildJob < BuildJob
+ attr_accessor :id, :status, :pkginfo, :pkgsvr_client, :thread, :log, :rev_fail_list, :rev_success_list, :source_path
+
+ # initialize
+ def initialize (local_path, os, pkgserver_url, options, server, parent, outstream, resolve )
+ super(server.jobmgr.get_new_job_id(), server)
+ @rev_fail_list = []
+ @rev_success_list = []
+ @parent = parent
+ @local_path = local_path
+ @os = os
+ @host_os = Utils::HOST_OS
+ @pkgserver_url = pkgsvr_url
+ @options = options
+ @resolve = resolve
+ @outstream = outstream
+
+ @status = "JUST_CREATED"
+ @sub_jobs = []
+ @job_root = "#{@server.path}/jobs/#{@id}"
+ @source_path = @local_path
+ @pkginfo = nil
+ @pkgsvr_client = nil
+ @job_working_dir=@job_root+"/works"
+
+ @thread = nil
+
+ # mkdir
+ FileUtils.rm_rf "#{@server.path}/jobs/#{@id}"
+ FileUtils.mkdir_p "#{@server.path}/jobs/#{@id}"
+
+ # create logger
+ @log = JobLog.new( self, "#{@server.path}/jobs/#{@id}/log", outstream )
+ end
+
+
+ def terminate()
+
+ # report error
+ if @status == "ERROR" then
+ @log.error( "Job is stopped by ERROR", Log::LV_USER)
+ @server.cleaner.clean_afterwards(@id)
+ else
+ # if succeeded, clean up
+ @server.cleaner.clean(@id)
+ end
+
+ # clean up builder directory if exist?
+ if Builder.exist? "JB#{@id}" then
+ Builder.remove("JB#{@id}")
+ end
+
+ # send mail
+ if ( @server.send_mail.eql? "YES" ) and ( not @pkginfo.nil? ) and ( not @pkginfo.packages.nil? ) then
+ mail_list = []
+ contents = []
+ done_pkg_list = []
+ contents.push " "
+ contents.push "%-30s| %10s | %10s" % ["package name", "version", "os"]
+ contents.push "---------------------------------------------------------------"
+ for pkg in @pkginfo.packages
+ if not pkg.os.eql? @os then next end
+ mail_list = mail_list | Mail.parse_email( pkg.maintainer )
+ contents.push("%-30s| %10s | %10s" % [ pkg.package_name, pkg.version, pkg.os] )
+ end
+
+ if @status == "ERROR" then
+ subject = "[DIBS] Build fail"
+ contents.push " "
+ contents.push "check log file"
+ contents.push "* Log : #{@server.job_log_url}/#{@id}/log"
+ else
+ subject = "[DIBS] Build success"
+ end
+ Mail.send_mail(mail_list, subject, contents.join("\n"))
+ end
+
+ # close logger
+ @log.close
+
+ # send END signal , if connectionn is valid
+ if @status != "ERROR" and not @outstream.nil? then
+ BuildCommServer.send_end(@outstream)
+ end
+
+ # close outstream
+ if not @outstream.nil? then
+ BuildCommServer.disconnect( @outstream )
+ end
+ end
+
+
+ # verify
+ def pre_verify
+ @log.info( "Verifying job input...", Log::LV_USER)
+
+ # check pkginfo.manifest
+ if not File.exist? "#{@source_path}/package/pkginfo.manifest"
+ @log.error( "#{@source_path}/package/pkginfo.manifest doest not exist", Log::LV_USER)
+ @status = "ERROR"
+ return false
+ end
+
+ # set pkginfo
+ @pkginfo = PackageManifest.new("#{@source_path}/package/pkginfo.manifest")
+
+ # set up pkgsvr_client
+ @pkgsvr_client = Client.new(@pkgserver_url, @job_working_dir, @log)
+ @pkgsvr_client.update
+
+ return true
+ end
+
+end
--- /dev/null
+=begin
+
+ ProjectManager.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require 'fileutils'
+$LOAD_PATH.unshift File.dirname(__FILE__)
+require "GitBuildProject.rb"
+require "BinaryUploadProject.rb"
+require "PackageManifest.rb"
+require "package.rb"
+require "FullBuildJob.rb"
+
+class ProjectManager
+ attr_accessor :projects
+
+ # initialize
+ def initialize( server )
+ @server = server
+ @projects = []
+ @project_root = "#{@server.path}/projects"
+ end
+
+
+ # load existing project from server configuration
+ def load()
+ # check project root
+ if not File.exist? @project_root then
+ FileUtils.mkdir_p @project_root
+ end
+
+ # scan all projects
+ for name in Dir.new(@project_root).entries
+ # skip . or ..
+ if name.eql? "." or name.eql? ".." then next end
+
+ # create project
+ @server.log.info "Loading project : #{name}"
+ prj = load_project( name )
+ if not prj.nil? then
+ @projects.push prj
+ end
+ end
+
+ end
+
+
+ # get_project of the name
+ def get_project ( name )
+ for prj in @projects
+ if prj.name.eql? name then return prj end
+ end
+
+ return nil
+ end
+
+
+ def add_git_project(name , repos, branch, passwd, os_list)
+ prj = get_project( name)
+ if not prj.nil? then return false end
+
+ new_prj = GitBuildProject.new(name, repos, branch, @server, os_list)
+ if not passwd.nil? and not passwd.empty? then
+ new_prj.passwd = passwd
+ end
+ @projects.push new_prj
+
+ # check project directory
+ if not File.exist? "#{@project_root}/#{name}" then
+ FileUtils.mkdir_p "#{@project_root}/#{name}"
+ end
+
+ # write configuration
+ write_configuration(name, repos, branch, passwd, os_list)
+
+ return true
+ end
+
+
+ def add_binary_project(name, pkg_name, passwd, os_list)
+ prj = get_project( name)
+ if not prj.nil? then return false end
+
+ new_prj = BinaryUploadProject.new(name, pkg_name, @server, os_list)
+ if not passwd.nil? and not passwd.empty? then
+ new_prj.passwd = passwd
+ end
+ @projects.push new_prj
+
+ # check project directory
+ if not File.exist? "#{@project_root}/#{name}" then
+ FileUtils.mkdir_p "#{@project_root}/#{name}"
+ end
+
+ # write configuration
+ write_configuration_for_binary_project(name, pkg_name, passwd, os_list)
+
+ return true
+ end
+
+
+ def add_remote_project( name, server_id)
+ end
+
+
+ # create new job for project
+ def create_new_job( name, os )
+ prj = get_project( name )
+ if prj.nil? then return nil end
+
+ return prj.create_new_job( os )
+ end
+
+
+ def create_new_jobs_for_all_os( name )
+ result = []
+
+ prj = get_project( name )
+ if prj.nil? then return nil end
+
+ for new_os in prj.os_list
+ new_job = create_new_job(name, new_os)
+ if not new_job.nil? then
+ result.push new_job
+ end
+ end
+
+ return result
+ end
+
+
+ # get project that includes specified pkg name and os
+ def get_projects_from_pkgs(pkgs)
+ result = []
+ for prj in @projects
+ for pkg in pkgs
+ name = pkg.package_name
+ ver = pkg.version
+ os = pkg.os
+
+ # check project provide target package
+ if prj.include_package?(name, ver, os) then
+ result.push prj
+ project_found = true
+ break
+ end
+
+ if project_found then break end
+ end
+ end
+
+ return result
+ end
+
+
+ def get_project_from_package_name(pkg_name)
+ for prj in @projects
+ # check project provide target package
+ if prj.include_package?(pkg_name) then
+ return prj
+ end
+ end
+
+ return nil
+ end
+
+
+ def create_new_fullbuild_job()
+ return FullBuildJob.new(@server)
+ end
+
+ protected
+
+ # load and create project
+ def load_project(name)
+
+ # check config file
+ config_file = "#{@project_root}/#{name}/build"
+ if not File.exist? config_file then return nil end
+
+ # read configuration
+ type="GIT"
+ passwd=""
+ repos="none"
+ branch="master"
+ os_list = ["linux","windows"]
+ rserver_id=nil
+ pkg_name=nil
+ File.open( config_file, "r" ) do |f|
+ f.each_line do |l|
+ idx = l.index("=") + 1
+ length = l.length - idx
+
+ if l.start_with?("TYPE=")
+ type = l[idx,length].strip
+ elsif l.start_with?("PASSWD=")
+ passwd = l[idx,length].strip
+ elsif l.start_with?("GIT_REPOSITORY=")
+ repos = l[idx,length].strip
+ elsif l.start_with?("GIT_BRANCH=")
+ branch = l[idx,length].strip
+ elsif l.start_with?("OS_LIST=")
+ os_list = l[idx,length].strip.split(",")
+ elsif l.start_with?("REMOTE_SERVER_ID=")
+ rserver_id = l[idx,length].strip
+ elsif l.start_with?("PACKAGE_NAME=")
+ pkg_name = l[idx,length].strip
+ else
+ next
+ end
+ end
+ end
+
+ # write back & create project
+ if type == "GIT" then
+ write_configuration(name, repos, branch, passwd, os_list)
+ new_project = GitBuildProject.new(name, repos, branch, @server, os_list)
+
+ # read source info
+ sources_file = "#{@project_root}/#{name}/sources"
+ if File.exist? sources_file then
+ File.open(sources_file, "r") do |f|
+ f.each_line do |l|
+ version = l.split(",")[0].strip
+ info = l.split(",")[1].strip
+
+ new_project.add_source_info( version, info )
+ end
+ end
+ end
+
+ # read pkginfo
+ pkginfo_dir = "#{@project_root}/#{name}/pkginfos"
+ if not File.exist? pkginfo_dir then FileUtils.mkdir_p pkginfo_dir end
+ for file in Dir.new(pkginfo_dir).entries
+ if file.eql? "." or file.eql? ".." then next end
+
+ vlen = file.length - ".manifest".length
+ version = file[0,vlen]
+ new_project.add_package_info( version, "#{pkginfo_dir}/#{file}" )
+ end
+
+ elsif type == "BINARY" then
+ write_configuration_for_binary_project(name, pkg_name, passwd, os_list)
+ new_project = BinaryUploadProject.new(name, pkg_name, @server, os_list)
+ end
+
+
+ # set passwd if exist
+ if not passwd.empty? then
+ new_project.passwd = passwd
+ end
+
+
+ return new_project
+ end
+
+
+ # write configuration
+ def write_configuration(name, repos, branch, passwd, os_list )
+ config_file = "#{@project_root}/#{name}/build"
+ File.open( config_file, "w" ) do |f|
+ f.puts "TYPE=GIT"
+ if not passwd.nil? and not passwd.empty? then
+ f.puts "PASSWD=#{passwd}"
+ end
+ f.puts "GIT_REPOSITORY=#{repos}"
+ f.puts "GIT_BRANCH=#{branch}"
+ f.puts "OS_LIST=#{os_list.join(",")}"
+ end
+ end
+
+
+ # write configuration
+ def write_configuration_for_binary_project(name, pkg_name, passwd, os_list )
+ config_file = "#{@project_root}/#{name}/build"
+ File.open( config_file, "w" ) do |f|
+ f.puts "TYPE=BINARY"
+ if not passwd.nil? and not passwd.empty? then
+ f.puts "PASSWD=#{passwd}"
+ end
+ f.puts "PACKAGE_NAME=#{pkg_name}"
+ f.puts "OS_LIST=#{os_list.join(",")}"
+ end
+ end
+end
--- /dev/null
+=begin
+
+ RegisterBinaryJob.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require "fileutils"
+$LOAD_PATH.unshift File.dirname(__FILE__)
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/builder"
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/pkg_server"
+require "client.rb"
+require "PackageManifest.rb"
+require "Version.rb"
+require "BuildServer.rb"
+require "JobLog.rb"
+require "mail.rb"
+require "utils.rb"
+
+class RegisterPackageJob
+
+ attr_accessor :id, :server, :pre_jobs, :os, :type
+ attr_accessor :status, :log, :source_path
+ attr_accessor :pkgsvr_client, :thread
+ attr_accessor :is_fullbuild_job
+ attr_accessor :pkg_name, :pkginfo
+
+
+ # initialize
+ def initialize( local_path, server, ftpurl=nil )
+ @server = server
+ @id = server.jobmgr.get_new_job_id()
+ @log = nil
+ @type = "REGISTER"
+
+ @status = "JUST_CREATED"
+ @host_os = Utils::HOST_OS
+ @pkgserver_url = @server.pkgserver_url
+ @job_root = "#{@server.path}/jobs/#{@id}"
+ @source_path = @job_root+"/temp"
+ @job_working_dir=@job_root+"/works"
+ @buildroot_dir = "#{@job_root}/buildroot"
+ @pre_jobs = []
+
+ @local_path=local_path
+ @filename = File.basename(local_path)
+ if @filename =~ /.*_.*_.*\.zip/ then
+ @pkg_type = "BINARY"
+ new_name = @filename.sub(/(.*)_(.*)_(.*)\.zip/,'\1,\2,\3')
+ @pkg_name = new_name.split(",")[0]
+ @os = new_name.split(",")[2]
+ else
+ @pkg_type = "ARCHIVE"
+ @pkg_name = @filename
+ end
+ @pkginfo = nil #This info is valid only for BINARY package
+ end
+
+
+ # execute
+ def execute(sync=false)
+ @log.info( "Invoking a thread for REGISTER Job #{@id}", Log::LV_USER)
+ if @status == "ERROR" then return end
+ @thread = Thread.new {
+ # main
+ thread_main()
+
+ # close
+ terminate()
+ }
+
+ if sync then
+ @thread.join
+ end
+
+ return true
+ end
+
+
+ #
+ def init
+ # mkdir
+ if not File.exist? @job_root then
+ FileUtils.mkdir_p @job_root
+ end
+
+ # create logger
+ if @log.nil? then
+ @log = JobLog.new(self, nil )
+ end
+
+ @log.info( "Initializing job...", Log::LV_USER)
+
+ # create dummy source path
+ if not File.exist? @source_path then
+ FileUtils.mkdir_p @source_path
+ end
+
+ # set up pkgsvr_client
+ @pkgsvr_client = Client.new(@pkgserver_url, @job_working_dir, @log)
+ @pkgsvr_client.update
+
+ # download from sites
+ if not File.exist? @local_path then
+
+ end
+
+ # copy package file to source path
+ if not File.exist? @local_path then
+ @log.error( "File not found!", Log::LV_USER)
+ @status = "ERROR"
+ return false
+ else
+ FileUtils.cp(@local_path,"#{@source_path}/#{File.basename(@local_path)}")
+ end
+
+ # checking version if not reverse-build job
+ if @pkg_type == "BINARY" then
+ # extrac pkg file
+ cmd = "cd \"#{@source_path}\";unzip #{@local_path}"
+ if not Utils.execute_shell(cmd) then
+ @log.error( "Extracting package file failed!", Log::LV_USER)
+ @status = "ERROR"
+ return false
+ end
+
+ # set up pkg info
+ @pkginfo = PackageManifest.new("#{@source_path}/pkginfo.manifest")
+
+ if not check_package_version() then
+ @status = "ERROR"
+ return false
+ end
+ end
+
+ return true
+ end
+
+
+ #terminate
+ def terminate()
+ # report error
+ if @status == "ERROR" then
+ @log.error( "Job is stopped by ERROR" , Log::LV_USER)
+ @server.cleaner.clean_afterwards(@id)
+ else
+ # clean up
+ @server.cleaner.clean(@id)
+ end
+
+ # close logger
+ @log.close
+ end
+
+
+ #cancel
+ def cancel()
+ #TODO
+ end
+
+
+ # check building is possible
+ def can_be_built_on?(host_os)
+ return true
+ end
+
+
+ def has_build_dependency?(other_job)
+ if has_same_packages?(other_job) or
+ does_depended_by?(other_job) then
+
+ return true
+ else
+ return false
+ end
+ end
+
+
+ def has_same_packages?( wjob )
+ if @type == wjob.type and
+ @pkg_name == wjob.pkg_name then
+
+ return true
+ else
+ return false
+ end
+ end
+
+
+ def does_depend_on?( wjob )
+ return false
+ end
+
+
+ def does_depended_by?( wjob )
+ if @pkg_type == "BINARY" then
+ for dep in wjob.pkginfo.get_build_dependencies(wjob.os)
+ # dep package of working job must have same name and target os
+ # with packages in my job
+ if dep.package_name == @pkg_name and
+ dep.target_os_list.include? @os then
+ #puts "Checking... A <- B"
+ return true
+ end
+ end
+ else
+ for dep in wjob.pkginfo.get_source_dependencies(wjob.os,@host_os)
+ if dep.package_name == @pkg_name then
+ return true
+ end
+ end
+ end
+
+ return false
+ end
+
+
+ def is_connected?
+ return true
+ end
+
+
+ # return the job is asyncronous job
+ def is_asynchronous_job?
+ return false
+ end
+
+ # set logger
+ def set_logger( logger )
+ @log = logger
+ end
+
+
+ #
+ # PROTECTED METHODS
+ #
+ protected
+
+
+ # main module
+ def thread_main
+ @log.info( "New Job #{@id} is started", Log::LV_USER)
+
+ # clean build
+ if not check_reverse_build() then
+ @log.error( "Reverse-build-check failed!" )
+ return false
+ end
+
+ # upload
+ if not upload() then
+ @status = "ERROR"
+ return
+ end
+
+ # INFO. don't change this string
+ @log.info( "Job is completed!", Log::LV_USER)
+ @status = "FINISHED"
+ end
+
+
+ # build projects that dependes on me
+ # can ignore some projects
+ def check_reverse_build()
+ @log.info( "Checking reverse build dependency ...", Log::LV_USER)
+
+ # get reverse-dependent projects
+ rev_pkgs = []
+ if @pkg_type == "BINARY" then
+ rev_pkgs += @pkgsvr_client.get_reverse_build_dependent_packages(@pkg_name, @os)
+ else
+ rev_pkgs += @pkgsvr_client.get_reverse_source_dependent_packages(@pkg_name)
+ end
+
+ rev_projects = @server.prjmgr.get_projects_from_pkgs(rev_pkgs)
+
+ # build rev-dep project as sub-job
+ for prj in rev_projects
+ if prj.type != "GIT" then next end
+ for os in prj.os_list
+ # check version
+ version = nil
+ for pkg in rev_pkgs
+ if prj.include_package?(pkg.package_name, pkg.version, os) then
+ version = pkg.version
+ break
+ end
+ end
+ if version.nil? then next end
+
+ # create sub jobs for checking
+ new_job = prj.create_new_job_from_version(os, version)
+ new_job.set_rev_build_check_job(self)
+ @log.info( " * Checking reverse-build ... #{prj.name}(#{new_job.id})", Log::LV_USER)
+ result = new_job.init()
+ rserver = @server.get_available_server( new_job )
+ if rserver != nil and rserver != @server then
+ new_job.set_remote_job( rserver )
+ end
+ if result then
+ new_job.execute(true)
+ if new_job.status == "ERROR" then result = false end
+ end
+
+ # check result
+ if not result then
+ return false
+ end
+ end
+ end
+
+ return true
+ end
+
+
+ def upload()
+ @log.info( "Uploading ...", Log::LV_USER)
+
+ # get package path list
+ binpkg_path_list = [ "#{@source_path}/#{@filename}" ]
+
+ # upload
+ u_client = Client.new( @server.pkgserver_url, nil, @log )
+ u_client.update
+ snapshot = u_client.upload( @server.pkgserver_addr, @server.pkgserver_port, @server.ftp_addr, @server.ftp_port, @server.ftp_username, @server.ftp_passwd, binpkg_path_list)
+
+ if snapshot.nil? then
+ @log.info( "Upload failed...", Log::LV_USER)
+
+ return false
+ end
+
+ # update local
+ @log.info( "Upload succeeded. Sync local pkg-server again...", Log::LV_USER)
+ @pkgsvr_client.update
+ @log.info("Snapshot: #{snapshot}", Log::LV_USER)
+
+ return true
+ end
+
+
+ # check if local package version is greater than server
+ def check_package_version()
+ @log.info( "Checking package version ...", Log::LV_USER)
+
+ # package update
+ @pkgsvr_client.update
+
+ for pkg in @pkginfo.packages
+ ver_local = pkg.version
+ #ver_svr = @pkgsvr_client.get_package_version( pkg.package_name, @os )
+ ver_svr = @pkgsvr_client.get_attr_from_pkg( pkg.package_name, @os, "version")
+ if not ver_svr.nil? and Version.new(ver_local) <= Version.new(ver_svr) then
+ @log.error( "Version must be increased : #{ver_local} <= #{ver_svr}", Log::LV_USER)
+ return false
+ end
+ end
+
+ return true
+ end
+end
--- /dev/null
+=begin
+
+ RemoteBuildJob.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+$LOAD_PATH.unshift File.dirname(__FILE__)
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+require "BuildJob.rb"
+require "utils.rb"
+
+class RemoteBuildJob < BuildJob
+ attr_accessor :id
+
+ # initialize
+ def initialize (id,server)
+ super(id,nil,nil,server)
+ @id = id
+ @type = nil
+ end
+end
--- /dev/null
+=begin
+
+ RemoteBuildServer.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require 'fileutils'
+$LOAD_PATH.unshift File.dirname(__FILE__)
+require "RemoteBuildJob.rb"
+require "BuildComm.rb"
+
+class RemoteBuildServer
+ attr_accessor :ip, :port, :status, :host_os
+ attr_accessor :max_working_jobs, :working_jobs, :waiting_jobs
+ attr_accessor :pkgserver_url, :path
+
+ # initialize
+ def initialize(ip, port, parent)
+ @ip = ip
+ @port = port
+ @status = "DISCONNECTED"
+ @host_os = Utils::HOST_OS
+ @max_working_jobs = 2
+ @working_jobs = []
+ @waiting_jobs = []
+ @pkgserver_url = parent.pkgserver_url
+ @path = ""
+ end
+
+
+ # check the job can be built on this server
+ def can_build?(job)
+
+ # check me
+ if job.can_be_built_on? @host_os then
+ return true
+ end
+
+ return false
+ end
+
+
+ # query remote server info & update server state
+ def update_state
+
+ # send
+ #@status = "DISCONNECTED"
+ client = BuildCommClient.create( @ip, @port )
+ if client.nil? then return end
+ if client.send("QUERY,SYSTEM") then
+ result = client.read_lines do |l|
+ tok = l.split(",").map { |x| x.strip }
+ @host_os = tok[0]
+ @max_working_jobs = tok[1].to_i
+ @status = "RUNNING"
+ end
+ if not result then @status = "DISCONNECTED" end
+ end
+ client.terminate
+ if @status == "DISCONNECTED" then return end
+
+ # send
+ @working_jobs = []
+ @waiting_jobs = []
+ client = BuildCommClient.create( @ip, @port )
+ if client.nil? then return end
+ if client.send("QUERY,JOB") then
+ result = client.read_lines do |l|
+ tok = l.split(",").map { |x| x.strip }
+
+ job_status = tok[0]
+ job_id = tok[1]
+ new_job = RemoteBuildJob.new(job_id,self)
+ case job_status
+ when "WAITING"
+ @waiting_jobs.push new_job
+ when "WORKING"
+ @working_jobs.push new_job
+ else
+ #puts "Uncontrolled status"
+ end
+ end
+ if not result then @status = "DISCONNECTED" end
+ else
+ @status = "DISCONNECTED"
+ end
+ client.terminate
+ end
+
+
+ # return available working slot
+ def get_number_of_empty_room
+ return @max_working_jobs - @working_jobs.count
+ end
+
+
+ # check there are working jobs
+ def has_working_jobs
+ return (@working_jobs.count > 0)
+ end
+
+
+ # check there are waiting jobs
+ def has_waiting_jobs
+ return (@waiting_jobs.count > 0)
+ end
+end
+
--- /dev/null
+=begin
+
+ RemoteBuilder.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+$LOAD_PATH.unshift File.dirname(__FILE__)
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/pkg_server"
+require "utils"
+require "PackageManifest"
+require "log"
+
+class RemoteBuilder
+ attr_accessor :id, :log
+
+ # initialize
+ def initialize( id, addr, port, ftp_addr, ftp_port, ftp_username, ftp_passwd)
+ @id = id
+ @addr = addr
+ @port = port
+ @ftp_addr = ftp_addr
+ @ftp_port = ftp_port
+ @ftp_username = ftp_username
+ @ftp_passwd = ftp_passwd
+ @log = Log.new(nil)
+ end
+
+
+ # build
+ def build( project_name, project_passwd, source_path, os, clean, rev_build_check_job, srcinfo, local_pkgs )
+ # send local packages
+ for pkg_path in local_pkgs
+ @log.info( "Sending file... : #{pkg_path}", Log::LV_USER )
+ result = send_binary_package( pkg_path )
+ if not result then
+ @log.error( "File transfering failed!", Log::LV_USER )
+ return false
+ end
+ end
+
+ # send build request
+ result, result_files = send_build_request(project_name, project_passwd, os, clean,
+ rev_build_check_job, srcinfo, local_pkgs)
+ if not result then
+ @log.error( "Building job on remote server failed!", Log::LV_USER )
+ return false
+ end
+
+ # receive binary package
+ for file_name in result_files
+ @log.info( "Receiving file... : #{file_name}", Log::LV_USER )
+ result = receive_binary_package( "#{source_path}/#{file_name}" )
+ if not result then
+ @log.error( "File transfering failed!", Log::LV_USER )
+ return false
+ end
+ end
+
+ return true
+ end
+
+
+ # upload binary packages that is need to be overwrite
+ # before remote package
+ def send_binary_package(file_path)
+ # create client
+ client = BuildCommClient.create( @addr, @port )
+ if client.nil? then
+ @log.error( "Creating communication client failed!", Log::LV_USER)
+ return false
+ end
+
+ # upload file
+ result = true
+ file_name = file_path.split("/")[-1]
+ if client.send("UPLOAD,#{file_name}") then
+ result=client.send_file( @ftp_addr, @ftp_port, @ftp_username, @ftp_passwd, file_path )
+ if not result then
+ @log.error( "File uploading failed...#{file_name}", Log::LV_USER)
+ end
+ end
+
+ #close connections
+ client.terminate
+
+ return result
+ end
+
+
+ # send build request
+ def send_build_request( project_name, project_passwd, os, clean, rev_build_job, commit,local_pkgs)
+ result_files = []
+
+ client = BuildCommClient.create( @addr, @port )
+ if client.nil? then
+ @log.error( "Creating communication client failed!", Log::LV_USER)
+ return false, result_files
+ end
+
+ # get local package names
+ local_pkg_names = local_pkgs.map { |path| File.basename(path) }
+
+ # send
+ # BUILD,GIT,project_name,os,pkgsvr_url,async,internal,commit,pkgs
+ result = true
+ commit=commit.nil? ? "":commit
+ pkg_list=local_pkg_names.join(",")
+ rev=rev_build_job ? "YES":"NO"
+ if client.send("BUILD,GIT,#{project_name},#{project_passwd},#{os},NO,YES,#{rev},#{commit},#{pkg_list}") then
+ result = client.read_lines do |l|
+ # check build result
+ if l.include? "Job is stopped by ERROR" then
+ result = false
+ break
+ end
+
+ # gather result files
+ if l =~ /Creating package file \.\.\. (.*)/ then
+ file_name = $1
+ result_files.push file_name
+ end
+
+ # ddd list
+ @log.output( l.strip, Log::LV_USER)
+ end
+ end
+
+ # close socket
+ client.terminate
+
+ return result, result_files
+ end
+
+
+ # receive binary package of remote server
+ def receive_binary_package(file_path)
+ # create client
+ client = BuildCommClient.create( @addr, @port )
+ if client.nil? then
+ @log.error( "Creating communication client failed!", Log::LV_USER)
+ return false
+ end
+
+ # download file
+ result = true
+ file_name = file_path.split("/")[-1]
+ if client.send("DOWNLOAD,#{file_name}") then
+ result=client.receive_file( @ftp_addr, @ftp_port, @ftp_username, @ftp_passwd, file_path )
+ if not result then
+ @log.error( "File downloading failed...#{file_name}", Log::LV_USER)
+ end
+ end
+
+ #close connections
+ client.terminate
+
+ return result
+ end
+end
--- /dev/null
+=begin
+
+ SocketJobRequestListener.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+$LOAD_PATH.unshift File.dirname(__FILE__)
+require "JobLog.rb"
+require "BuildComm.rb"
+
+
+class SocketJobRequestListener
+
+ # initialize
+ def initialize (parent)
+ @parent_server = parent
+ @thread = nil
+ @finish_loop = false
+ @comm_server = nil
+ @log = @parent_server.log
+ end
+
+ # start listening
+ def start()
+ @thread = Thread.new {
+ main()
+ }
+ end
+
+
+
+ # quit listening
+ def stop_listening()
+ @finish_loop = true
+ end
+
+ private
+
+ # thread main
+ def main()
+ # server open
+ begin
+ ftp_url = Utils.generate_ftp_url(@parent_server.ftp_addr, @parent_server.ftp_port,
+ @parent_server.ftp_username, @parent_server.ftp_passwd)
+ @comm_server = BuildCommServer.new(@parent_server.port, @log, ftp_url)
+ rescue
+ @log.info "Server creation failed"
+ puts "Server creation failed"
+ @parent_server.stop
+ return
+ end
+
+ # loop
+ @log.info "Entering Control Listening Loop ... "
+ @finish_loop = false
+ @comm_server.wait_for_connection(@finish_loop) do |req|
+ handle_job_request( req )
+ end
+
+ # quit
+ @comm_server.terminate
+ end
+
+
+ # wait for job requests
+ def wait_for_job_requests
+ req_list = []
+ req_list.push @tcp_server.accept
+
+ return req_list
+ end
+
+
+ # handle job request
+ def handle_job_request( req )
+
+ # read request
+ req_line = req.gets
+ if req_line.nil? then return end
+
+ # parse request
+ cmd = ""
+ if req_line.split(",").count > 0 then
+ cmd = req_line.split(",")[0].strip
+ end
+
+ case cmd
+ when "BUILD"
+ handle_cmd_build( req_line, req )
+ when "RESOLVE"
+ handle_cmd_resolve( req_line, req )
+ when "QUERY"
+ handle_cmd_query( req_line, req )
+ when "CANCEL"
+ handle_cmd_cancel( req_line, req )
+ when "STOP"
+ handle_cmd_stop( req_line, req )
+ when "FULLBUILD"
+ handle_cmd_fullbuild( req_line, req )
+ when "REGISTER"
+ handle_cmd_register( req_line, req )
+ when "DOWNLOAD"
+ Thread.new {
+ handle_cmd_download( req_line, req )
+ }
+ when "UPLOAD"
+ Thread.new {
+ handle_cmd_upload( req_line, req )
+ }
+ else
+ @log.info "Received Unknown REQ: #{req_line}"
+ raise "Unknown request: #{req_line}"
+ end
+
+ end
+
+
+ # "BUILD"
+ def handle_cmd_build( line, req )
+ tok = line.split(",").map { |x| x.strip }
+ if tok.count < 3 then
+ @log.info "Received Wrong REQ: #{line}"
+ raise "Invalid request format is used: #{line}"
+ end
+
+ case tok[1]
+ # BUILD,GIT,proj,os,url,async,internal
+ # "internal" means that this job requested by other server.
+ when "GIT"
+ # parse
+ project_name=tok[2]
+ passwd=tok[3]
+ os=tok[4]
+ async = (not tok[5].nil? and tok[5]=="YES" ? true:false)
+ is_internal = (not tok[6].nil? and tok[6]=="YES" ? true:false)
+
+ # check project
+ prj = check_project_exist(project_name, req)
+ if prj.nil? then
+ raise "Requested project does not exist!"
+ end
+
+ # check passwd
+ if not check_project_password(prj, passwd, req) then
+ raise "Project's password is not matched!!"
+ end
+
+ # create new job
+ @log.info "Received a request for building this project : #{tok[2]}"
+ new_job_list = create_new_job( project_name, os, req )
+ if new_job_list.empty? then
+ raise "Creating build job failed : #{project_name}, #{os}"
+ end
+
+ for new_job in new_job_list
+ # set internal flags
+ if is_internal then
+ # set job type
+ new_job.set_internal_job()
+ # check revere_build_check_job
+ rev_job = (not tok[7].nil? and tok[7].eql? "YES") ? true:false
+ if rev_job then new_job.set_rev_build_check_job(nil) end
+ # set commit id
+ commit_id = tok[8]
+ if not commit_id.nil? and not commit_id.empty? then
+ new_job.set_git_commit(commit_id)
+ end
+ # set external pkgs
+ i = 9
+ pkg_file = tok[i]
+ while not pkg_file.nil? do
+ new_job.add_external_package( "#{@parent_server.incoming_path}/#{pkg_file}" )
+ i = i + 1
+ pkg_file = tok[i]
+ end
+ end
+ end
+
+ # create logger and set
+ if new_job_list.count == 1 then
+ logger = JobLog.new( new_job_list[0], req )
+ if not async then new_job.set_logger(logger) end
+ else
+ logger = JobLog.new( nil, req )
+ end
+ logger.init
+
+ # notify that job has been received
+ for job in new_job_list
+ logger.info( "Added new job \"#{job.id}\" for #{job.os}!", Log::LV_USER)
+ if not @parent_server.job_log_url.empty? then
+ logger.info( " * Log URL : #{@parent_server.job_log_url}/#{job.id}/log", Log::LV_USER)
+ end
+ end
+
+ # if asynchronouse, quit connection
+ if os == "all" or async then
+ logger.info( "Above job(s) will be processed asynchronously!", Log::LV_USER)
+ logger.close
+ end
+
+ # add
+ for new_job in new_job_list
+ @parent_server.jobmgr.add_job( new_job )
+ end
+ else
+ @log.info "Received Wrong REQ: #{line}"
+ raise "Invalid request format is used: #{line}"
+ end
+ end
+
+
+ # "RESOLVE"
+ def handle_cmd_resolve( line ,req)
+ tok = line.split(",").map { |x| x.strip }
+ if tok.count < 3 then
+ @log.info "Received Wrong REQ: #{line}"
+ raise "Invalid request format is used: #{line}"
+ end
+
+ case tok[1]
+ # RESOLVE,GIT,repos,commit,os,url
+ when "GIT"
+ # parse
+ project_name=tok[2]
+ passwd=tok[3]
+ os=tok[4]
+ async = (not tok[5].nil? and tok[6]=="YES" ? true:false)
+
+ # check project
+ prj = check_project_exist(project_name, req)
+ if prj.nil? then
+ raise "Requested project does not exist!"
+ end
+
+ # check passwd
+ if not check_project_password(prj, passwd, req) then
+ raise "Project's password is not matched!!"
+ end
+
+ # create new job
+ @log.info "Received a request for resolving this project : #{tok[2]}"
+ new_job_list = create_new_job( project_name, os, req )
+ if new_job_list.empty? then
+ raise "Creating build job failed : #{project_name}, #{os}"
+ end
+
+ # resolve
+ for new_job in new_job_list
+ new_job.set_resolve_flag()
+ end
+
+ # create logger and set
+ if new_job_list.count == 1 then
+ logger = JobLog.new( new_job_list[0], req )
+ if not async then new_job.set_logger(logger) end
+ else
+ logger = JobLog.new( nil, req )
+ end
+ logger.init
+
+ # notify that job has been received
+ for job in new_job_list
+ logger.info( "Added new job \"#{job.id}\" for #{job.os}!", Log::LV_USER)
+ if not @parent_server.job_log_url.empty? then
+ logger.info( " * Log URL : #{@parent_server.job_log_url}/#{job.id}/log", Log::LV_USER)
+ end
+ end
+
+ # if asynchronouse, quit connection
+ if os == "all" or async then
+ logger.info( "Above job(s) will be processed asynchronously!", Log::LV_USER)
+ logger.close
+ end
+
+ for new_job in new_job_list
+ @parent_server.jobmgr.add_job( new_job )
+ end
+ else
+ @log.info "Received Wrong REQ: #{line}"
+ raise "Invalid request format is used: #{line}"
+ end
+ end
+
+
+ # "QUERY"
+ def handle_cmd_query( line, req )
+ tok = line.split(",").map { |x| x.strip }
+ if tok.count < 2 then
+ @log.info "Received Wrong REQ: #{line}"
+ raise "Invalid request format is used: #{line}"
+ end
+
+ case tok[1]
+
+ # QUERY, FTP
+ when "FTP"
+ BuildCommServer.send_begin(req)
+ BuildCommServer.send(req,"#{@parent_server.ftp_addr},#{@parent_server.ftp_username},#{@parent_server.ftp_passwd}")
+ BuildCommServer.send_end(req)
+ BuildCommServer.disconnect(req)
+
+ # QUERY,JOB
+ when "JOB"
+ #puts "Received QUERY JOB"
+
+ BuildCommServer.send_begin(req)
+ for job in @parent_server.jobmgr.get_working_jobs
+ BuildCommServer.send(req,"WORKING,#{job.id},#{job.pkginfo.packages[0].source}")
+ end
+ for job in @parent_server.jobmgr.get_waiting_jobs
+ BuildCommServer.send(req,"WAITING,#{job.id},#{job.pkginfo.packages[0].source}")
+ end
+ for job in @parent_server.jobmgr.get_remote_jobs
+ BuildCommServer.send(req,"REMOTE ,#{job.id},#{job.pkginfo.packages[0].source}")
+ end
+ BuildCommServer.send_end(req)
+ BuildCommServer.disconnect(req)
+
+ # QUERY,SYSTEM
+ when "SYSTEM"
+ #puts "Received QUERY SYSTEM"
+
+ BuildCommServer.send_begin(req)
+ BuildCommServer.send(req,"#{@parent_server.host_os},#{@parent_server.jobmgr.max_working_jobs}")
+ BuildCommServer.send_end(req)
+ BuildCommServer.disconnect(req)
+ when "PROJECT"
+ BuildCommServer.send_begin(req)
+ # print GIT projects
+ for prj in @parent_server.prjmgr.projects
+ if prj.type != "GIT" then next end
+ BuildCommServer.send(req,"G,#{prj.name},#{prj.repository},#{prj.branch}")
+ end
+ # print BINARY projects
+ for prj in @parent_server.prjmgr.projects
+ if prj.type != "BINARY" then next end
+ BuildCommServer.send(req,"B,#{prj.name},#{prj.pkg_name}")
+ end
+ # print REMOTE project
+ for prj in @parent_server.prjmgr.projects
+ if prj.type != "REMOTE" then next end
+ BuildCommServer.send(req,"R,#{prj.name}")
+ end
+ BuildCommServer.send_end(req)
+ BuildCommServer.disconnect(req)
+
+ else
+ @log.info "Received Wrong REQ: #{line}"
+ raise "Invalid request format is used: #{line}"
+ end
+ end
+
+
+ # "CANCEL"
+ def handle_cmd_cancel( line, req )
+ tok = line.split(",").map { |x| x.strip }
+ if tok.count < 2 then
+ @log.info "Received Wrong REQ: #{line}"
+ raise "Invalid request format is used: #{line}"
+ end
+ cancel_job = nil
+
+ #CANCEL, JOB
+ @parent_server.jobmgr.jobs.each do |j|
+ if "#{j.id}" == "#{tok[1]}" then
+ cancel_job = j
+ break
+ end
+ end
+
+ BuildCommServer.send_begin(req)
+ if cancel_job.nil? then
+ BuildCommServer.send(req, "There is no job \"#{tok[1]}\"")
+ raise "There is no job \"#{tok[1]}\""
+ else
+ # check passwd
+ if not check_project_password( cancel_job.get_project, tok[2], req) then
+ raise "Project's password is not matched!!"
+ end
+
+ BuildCommServer.send(req, "\"#{cancel_job.id} #{cancel_job.pkginfo.packages[0].source} #{cancel_job.status}\"")
+ cancel_job.cancel
+ end
+ BuildCommServer.send_end(req)
+ BuildCommServer.disconnect(req)
+ end
+
+
+ # "STOP"
+ def handle_cmd_stop( line, req )
+ tok = line.split(",").map { |x| x.strip }
+ if tok.count < 2 then
+ @log.info "Received Wrong REQ: #{line}"
+ raise "Invalid request format is used: #{line}"
+ end
+
+ BuildCommServer.send_begin(req)
+ if tok[1] != @parent_server.password then
+ BuildCommServer.send(req,"Password mismatched!")
+ else
+ BuildCommServer.send(req,"Server will be down!")
+ end
+ BuildCommServer.send_end(req)
+ BuildCommServer.disconnect(req)
+ if tok[1] == @parent_server.password then
+ @parent_server.finish = true
+ end
+ end
+
+
+ # "FULLBUILD"
+ def handle_cmd_fullbuild( line, req )
+ tok = line.split(",").map { |x| x.strip }
+ if tok.count < 2 then
+ @log.info "Received Wrong REQ: #{line}"
+ raise "Invalid request format is used: #{line}"
+ end
+
+ # create full build job
+ new_job = @parent_server.prjmgr.create_new_fullbuild_job()
+ logger = JobLog.new( new_job, req )
+ new_job.set_logger(logger)
+ logger.init
+
+ # add to job
+ @parent_server.jobmgr.add_job( new_job )
+ end
+
+
+ # "REGISTER"
+ def handle_cmd_register( line, req )
+ tok = line.split(",").map { |x| x.strip }
+ if tok.count < 4 then
+ @log.info "Received Wrong REQ: #{line}"
+ raise "Invalid request format is used: #{line}"
+ end
+
+ type = tok[1]
+
+ case type
+ # REGISTER,BINARY-LOCAL,local_path
+ # REGISTER,SOURCE-LOCAL,local_path
+ when "BINARY-LOCAL", "SOURCE-LOCAL"
+ file_path = tok[2]
+ new_job = @parent_server.jobmgr.create_new_register_job( file_path )
+ logger = JobLog.new( new_job, req )
+ new_job.set_logger(logger)
+ logger.init
+
+ # add
+ @parent_server.jobmgr.add_job( new_job )
+
+ # REGISTER,BINARY,filename,passwd
+ when "BINARY"
+ # parse
+ filename = tok[2]
+ passwd = tok[3]
+
+ # check project
+ prj = check_project_for_package_file_name(filename, req)
+ if prj.nil? then
+ raise "No project is defined for this binary : #{filename}!"
+ end
+
+ # check passwd
+ if not check_project_password(prj, passwd, req) then
+ raise "Project's password is not matched!!"
+ end
+
+ # create new job
+ @log.info "Received a request for uploading binaries : #{tok[2]}"
+ new_job = create_new_upload_job( prj.name, filename, req )
+ if new_job.nil? then
+ raise "Creating build job failed : #{prj.name}, #{filename}"
+ end
+
+ # create logger and set
+ logger = JobLog.new( new_job, req )
+ new_job.set_logger(logger)
+ logger.init
+
+ # notify that job has been received
+ logger.info( "Added new job \"#{new_job.id}\" for #{new_job.os}!", Log::LV_USER)
+ if not @parent_server.job_log_url.empty? then
+ logger.info( " * Log URL : #{@parent_server.job_log_url}/#{new_job.id}/log", Log::LV_USER)
+ end
+
+ # add
+ @parent_server.jobmgr.add_job( new_job )
+ else
+ @log.info "Received Wrong REQ: #{line}"
+ raise "Invalid request format is used: #{line}"
+ end
+
+ end
+
+
+ # "UPLOAD"
+ def handle_cmd_upload( line, req )
+ tok = line.split(",").map { |x| x.strip }
+ if tok.count < 1 then
+ @log.info "Received Wrong REQ: #{line}"
+ raise "Invalid request format is used: #{line}"
+ end
+
+ file_name = tok[1]
+ @log.info "Received a request for upload file : #{file_name}"
+ BuildCommServer.send_begin(req)
+ begin
+ @comm_server.receive_file(req, @parent_server.incoming_path)
+ rescue => e
+ puts "Failed to receive file"
+ puts e.message
+ puts e.backtrace.inspect
+ end
+ BuildCommServer.send_end(req)
+ end
+
+
+ # "DOWNLOAD"
+ def handle_cmd_download( line, req )
+ tok = line.split(",").map { |x| x.strip }
+ if tok.count < 1 then
+ @log.info "Received Wrong REQ: #{line}"
+ raise "Invalid request format is used: #{line}"
+ end
+
+ file_name = tok[1]
+
+ @log.info "Received a request for download file : #{file_name}"
+ BuildCommServer.send_begin(req)
+ begin
+ @comm_server.send_file(req, "#{@parent_server.outgoing_path}/#{file_name}")
+ rescue => e
+ puts "transfer failed"
+ puts e.message
+ puts e.backtrace.inspect
+ end
+ BuildCommServer.send_end(req)
+ end
+
+
+
+ private
+ def check_project_exist(project_name, req)
+ prj = @parent_server.prjmgr.get_project(project_name)
+ if prj.nil? then
+ BuildCommServer.send_begin(req)
+ req.puts "Error: Requested project does not exist!"
+ req.puts "Info: Check project name using \"query\" command option !"
+ BuildCommServer.send_end(req)
+ return nil
+ end
+
+ return prj
+ end
+
+ private
+ def check_project_for_package_file_name(filename, req)
+ # get package name
+ new_name = filename.sub(/(.*)_(.*)_(.*)\.zip/,'\1,\2,\3')
+ pkg_name = new_name.split(",")[0]
+
+ prj = @parent_server.prjmgr.get_project_from_package_name(pkg_name)
+ if prj.nil? then
+ BuildCommServer.send_begin(req)
+ req.puts "Error: Requested project does not exist!"
+ req.puts "Info: Check project name using \"query\" command option !"
+ BuildCommServer.send_end(req)
+ return nil
+ end
+
+ return prj
+ end
+
+
+ private
+ def check_project_password(prj, passwd, req)
+
+ if prj.is_passwd_set? and not prj.passwd_match?(passwd) then
+ BuildCommServer.send_begin(req)
+ req.puts "Error: Project's password is not matched!"
+ req.puts "Error: Use -w option to input your project password"
+ BuildCommServer.send_end(req)
+ return false
+ end
+
+ return true
+ end
+
+
+ private
+ def create_new_job( project_name, os, req )
+ result = []
+
+ if os == "all" then
+ jobs = @parent_server.prjmgr.create_new_jobs_for_all_os(project_name)
+ result += jobs
+ else
+ new_job = @parent_server.prjmgr.create_new_job(project_name, os)
+ if not new_job.nil? then
+ result.push new_job
+ end
+ end
+
+ if result.empty? then
+ BuildCommServer.send_begin(req)
+ req.puts "Error: Creating job failed: #{project_name}, #{os}"
+ BuildCommServer.send_end(req)
+ end
+
+ return result
+ end
+
+
+ def create_new_upload_job( project_name, filename, req)
+
+ new_job = @parent_server.prjmgr.get_project(project_name).create_new_job(filename)
+
+ if new_job.nil? then
+ BuildCommServer.send_begin(req)
+ req.puts "Error: Creating job failed: #{project_name} #{filename}"
+ BuildCommServer.send_end(req)
+ return nil
+ end
+
+ return new_job
+ end
+end
--- /dev/null
+=begin
+
+ Builder.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+$LOAD_PATH.unshift File.dirname(__FILE__)
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/pkg_server"
+require "client"
+require "utils"
+require "PackageManifest"
+require "log"
+
+class Builder
+ private_class_method :new
+ attr_accessor :id, :pkgserver_url, :log, :buildroot_dir, :cache_dir
+
+ CONFIG_ROOT = Utils::HOME + "/.build_tools/builder"
+ @@instance_map = {}
+
+ # initialize
+ def initialize (id, pkgserver_url, log_path, buildroot_dir, cache_dir)
+ @id = id
+ @pkgserver_url = pkgserver_url
+ @host_os = Utils::HOST_OS
+ @buildroot_dir = buildroot_dir
+ @cache_dir = cache_dir
+ @log = Log.new(log_path)
+ end
+
+
+ # create
+ def self.create (id, pkgserver_url, log_path, buildroot_dir, cache_dir)
+
+ # check builder config root
+ check_builder_config_root
+
+ # if exist , overwrite
+ if File.exist? "#{CONFIG_ROOT}/#{id}"
+ FileUtils.rm_rf "#{CONFIG_ROOT}/#{id}"
+ end
+
+ # create buildroot if not set
+ if buildroot_dir.nil? then
+ buildroot_dir = "#{CONFIG_ROOT}/#{id}/buildroot"
+ if not File.exist? buildroot_dir then
+ FileUtils.mkdir_p buildroot_dir
+ end
+ end
+
+ # create cachedir if not set
+ if cache_dir.nil? then
+ cache_dir = "#{CONFIG_ROOT}/#{id}/build_cache"
+ if not File.exist? cache_dir then
+ FileUtils.mkdir_p cache_dir
+ end
+ end
+
+ # create new instance and return it
+ @@instance_map[id] = new( id, pkgserver_url, log_path, buildroot_dir, cache_dir )
+
+ # write config
+ write_builder_config( @@instance_map[id] )
+ return @@instance_map[id]
+ end
+
+
+ def self.remove( id )
+ # check builder config root
+ check_builder_config_root
+
+ # check id
+ if File.exist? "#{CONFIG_ROOT}/#{id}"
+ FileUtils.rm_rf "#{CONFIG_ROOT}/#{id}"
+ @@instance_map[id] = nil
+ puts "Removed the builder \"#{id}\""
+ end
+ end
+
+
+ def self.exist?( id )
+ # check builder config root
+ check_builder_config_root
+
+ # check id
+ if File.exist? "#{CONFIG_ROOT}/#{id}" then
+ return true
+ else
+ return false
+ end
+ end
+
+ # get
+ def self.get( id )
+
+ # check instance first
+ if not @@instance_map[id] == nil
+ return @@instance_map[id]
+ end
+
+ # check builder config
+ if not File.exist? "#{CONFIG_ROOT}/#{id}/builder.cfg"
+ raise RuntimeError, "The builder \"#{id}\" does not exist."
+ end
+
+ # get builder config and return its object
+ @@instance_map[id] = read_builder_config(id)
+
+ return @@instance_map[id]
+ end
+
+
+ # clean
+ def clean( src_path )
+
+ build_root_dir = @buildroot_dir
+
+ # create pkginfo
+ pkginfo = PackageManifest.new("#{src_path}/package/pkginfo.manifest")
+
+ # make clean
+ for pkg in pkginfo.packages
+ for os1 in ["linux","windows","darwin"]
+ if File.exist? "#{src_path}/package/#{pkg.package_name}.package.#{os1}" then
+ FileUtils.rm_rf "#{src_path}/package/#{pkg.package_name}.package.#{os1}"
+ end
+ end
+ end
+
+ # execute
+ return execute_build_command("clean", src_path, build_root_dir, @host_os )
+ end
+
+
+ # build
+ def build( src_path, os, clean, local_pkgs, use_cache )
+
+ # create pkginfo
+ pkginfo = PackageManifest.new("#{src_path}/package/pkginfo.manifest")
+
+ # check there are packages which can be built
+ if not pkginfo.package_exist?(os, Utils::HOST_OS ) then
+ @log.error( "There are no packages which can be built on this host OS: #{Utils::HOST_OS}")
+ @log.error( " * Check \"Build-host-os\" in pkginfo.manifest" )
+ return false
+ end
+
+ # set build root
+ build_root_dir = @buildroot_dir
+ if not File.exist? build_root_dir then
+ FileUtils.mkdir_p build_root_dir
+ end
+
+ # create client
+ @log.info( "Downloding client is initializing...", Log::LV_USER)
+ cl = Client.new(@pkgserver_url, build_root_dir, @log)
+ if clean then
+ cl.clean(true)
+ cl.update
+ end
+
+ # install build dependencies
+ package_overwrite_list = []
+ @log.info( "Installing dependent packages...", Log::LV_USER)
+ pkginfo.get_build_dependencies( os ).each do |dep|
+ if dep.target_os_list.count != 0 then
+ dep_target_os = dep.target_os_list[0]
+ else
+ dep_target_os = os
+ end
+ @log.info( " * #{dep.package_name}", Log::LV_USER)
+
+ # get local dependent package
+ pkgexp = Regexp.new("\/#{dep.package_name}_.*_#{dep_target_os}\.zip$")
+ package_overwrite_list += local_pkgs.select{|l| l =~ pkgexp}
+
+ # install pkgs
+ if not cl.install(dep.package_name, dep_target_os, true, false) then
+ @log.error( "Installing \"#{dep.package_name}\" failed!", Log::LV_USER)
+ return false
+ end
+ end
+
+ # overwrite local dependent packages
+ package_overwrite_list.each do |l|
+ @log.info( "Overwriting...#{l}", Log::LV_USER)
+ cl.install_local_pkg(l,false)
+ end
+
+ @log.info( "Downloading dependent source packages...", Log::LV_USER)
+ pkginfo.get_source_dependencies(os,@host_os).each do |dep|
+ @log.info( " * #{dep.package_name}", Log::LV_USER)
+
+ if cl.download_dep_source(dep.package_name).nil? then
+ @log.error( "Downloading \"#{dep.package_name}\" failed!", Log::LV_USER)
+ return false
+ end
+ end
+
+ # make clean
+ @log.info( "Make clean...", Log::LV_USER)
+ for pkg in pkginfo.packages
+ for os1 in ["linux","windows","darwin"]
+ if File.exist? "#{src_path}/package/#{pkg.package_name}.package.#{os1}" then
+ FileUtils.rm_rf "#{src_path}/package/#{pkg.package_name}.package.#{os1}"
+ end
+ end
+ end
+
+ # convert path if windows
+ if Utils::HOST_OS == "windows" then
+ build_root_dir = Utils.get_unix_path( build_root_dir )
+ end
+
+ if not execute_build_command("clean", src_path, build_root_dir, os) then
+ return false
+ end
+
+ # execute build script
+ #if use_cache then
+ # @log.info( "Make build from cache...", Log::LV_USER)
+ # if not execute_build_command("build_cache", src_path, build_root_dir, os) then
+ # @log.warn( "Build from cache failed, \"build\" target will used instead...", Log::LV_USER)
+ # if not execute_build_command("build", src_path, build_root_dir, os) then
+ # return false
+ # end
+ # end
+ #else
+ # @log.info( "Make build...", Log::LV_USER)
+ # if not execute_build_command("build", src_path, build_root_dir, os) then
+ # return false
+ # end
+ #
+ # # saving build cache
+ # if not execute_build_command("save_cache", src_path, build_root_dir, os) then
+ # @log.warn( "Saving cache failed...", Log::LV_USER)
+ # else
+ # @log.info( "Saved build information to cache...", Log::LV_USER)
+ # end
+ #end
+ if not execute_build_command("build", src_path, build_root_dir, os) then
+ return false
+ end
+
+ # execute install script
+ @log.info( "Make install...", Log::LV_USER)
+ if not execute_build_command("install", src_path, build_root_dir, os) then
+ return false
+ end
+
+ # write pkginfo
+ @log.info( "Generatiing pkginfo.manifest...", Log::LV_USER)
+ if not write_pkginfo_files(pkginfo,os,src_path) then
+ @log.error( "Failed to write pkginfo.manifest", Log::LV_USER)
+ return false
+ end
+
+ # zip
+ @log.info( "Zipping...", Log::LV_USER)
+ if not make_zip(pkginfo,os,src_path) then
+ @log.error( "Creating packages failed!", Log::LV_USER)
+ return false
+ end
+
+ return true
+ end
+
+
+ private
+
+
+ # check builder config root
+ def self.check_builder_config_root
+ if not File.exist? Builder::CONFIG_ROOT
+ puts "Builder configuation is not found."
+ puts "Creating new builder configuration... #{Builder::CONFIG_ROOT}"
+ FileUtils.mkdir_p "#{Builder::CONFIG_ROOT}"
+ end
+ end
+
+
+ # write builder configuration
+ def self.write_builder_config( obj )
+ # create config folder
+ builder_dir = "#{CONFIG_ROOT}/#{obj.id}"
+ if not File.exist? builder_dir then
+ FileUtils.mkdir_p( "#{builder_dir}" )
+ end
+
+ # write configuration
+ File.open( "#{builder_dir}/builder.cfg", "w" ) do |f|
+ f.puts "ID=#{obj.id}"
+ f.puts "PSERVER_URL=#{obj.pkgserver_url}"
+ f.puts "LOG-PATH=#{obj.log.path}"
+ f.puts "CACHE-DIR=#{obj.cache_dir}"
+ end
+ end
+
+
+ # read builder configuration
+ def self.read_builder_config( id )
+ pkgserver_url=""
+
+ # read configuration
+ builder_dir = "#{CONFIG_ROOT}/#{id}"
+ log_path = nil
+ cache_dir = "#{CONFIG_ROOT}/#{id}/build_cache"
+ buildroot_dir = "#{CONFIG_ROOT}/#{id}/buildroot"
+ File.open( "#{builder_dir}/builder.cfg", "r" ) do |f|
+ f.each_line do |l|
+ if l.start_with?("PSERVER_URL=")
+ pkgserver_url = l.split("=")[1].strip
+ elsif l.start_with?("LOG-PATH=")
+ log_path = l.split("=")[1].strip
+ log_path = nil if log_path == "STDOUT"
+ elsif l.start_with?("CACHE-DIR=")
+ cache_dir = l.split("=")[1].strip
+ elsif l.start_with?("BUILDROOT-DIR=")
+ buildroot_dir = l.split("=")[1].strip
+ else
+ next
+ end
+ end
+ end
+
+ if log_path.empty? then log_path = nil end
+
+ # create object & return it
+ return new( id, pkgserver_url, log_path, buildroot_dir, cache_dir )
+ end
+
+
+ # execute build command
+ def execute_build_command( target, src_path, build_root_dir, os )
+
+
+ pkginfo = PackageManifest.new("#{src_path}/package/pkginfo.manifest")
+ env_def =
+ "BUILD_TARGET_OS=#{os} \
+ SRCDIR=\"#{src_path}\" \
+ PKG_CACHE_DIR=\"#{@cache_dir}/#{pkginfo.packages[0].source}/#{os}\" \
+ ROOTDIR=\"#{build_root_dir}\" "
+
+ # read build script
+ # this will ignore last lines without block
+ contents = []
+ File.open( "#{src_path}/package/build.#{@host_os}", "r" ) do |f|
+ lines = []
+ f.each_line do |l|
+ lines.push l
+ if l.start_with? "}" then
+ contents = contents + lines
+ lines = []
+ end
+ end
+ end
+
+ # generate shell script
+ File.open( "#{src_path}/.build.sh", "w" ) do |f|
+ f.puts "#!/bin/sh -xe"
+ for l in contents
+ f.puts l
+ end
+
+ case target
+ when "clean"
+ f.puts " "
+ when "build"
+ f.puts " "
+ when "build_cache"
+ f.puts "CACHEDIR=${PKG_CACHE_DIR}/$(cache_key)"
+ when "save_cache"
+ f.puts "rm -rf ${PKG_CACHE_DIR}/*"
+ f.puts "CACHEDIR=${PKG_CACHE_DIR}/$(cache_key)"
+ f.puts "mkdir -p ${CACHEDIR}"
+ when "install"
+ f.puts " "
+ else
+ @log.warn( "Wron build-target is used: \"#{target}\"", Log::LV_USER)
+ return false
+ end
+ f.puts "#{target}"
+ f.puts "echo \"success\""
+ end
+ Utils.execute_shell_with_log( "chmod +x #{src_path}/.build.sh", @log )
+ build_command = "cd \"#{src_path}\";" + env_def + "./.build.sh"
+
+ # execute script
+ if not Utils.execute_shell_with_log( build_command, @log ) then
+ @log.warn( "Failed on build script: \"#{target}\"", Log::LV_USER)
+ return false
+ else
+ Utils.execute_shell_with_log( "rm -rf #{src_path}/.build.sh", @log )
+ return true
+ end
+ end
+
+
+ # write pkginfo.manifest and install/remove script
+ def write_pkginfo_files(pkginfo,os,src_path)
+ for pkg in pkginfo.packages
+ # skip if not support the target os
+ if not pkg.os.include? os
+ next
+ end
+
+ # install script files
+ copy_post_install_script(pkg,os,src_path);
+ copy_post_remove_script(pkg,os,src_path);
+
+ # write manifest file
+ install_dir = "#{src_path}/package/#{pkg.package_name}.package.#{os}"
+
+ # if there is no intall directory, error
+ if not File.exist? install_dir then
+ @log.error( "Following directory must be created before writing pkginfo.manifest", Log::LV_USER)
+ @log.error( " * package/#{pkg.package_name}.package.#{os}", Log::LV_USER)
+ return false
+ end
+
+ # write pkginfo.manifest
+ File.open("#{install_dir}/pkginfo.manifest", "w") do |f|
+ pkg.print_to_file_with_os( f, os )
+ end
+ end
+
+ return true
+ end
+
+
+ # copy post-install script
+ def copy_post_install_script(pkg,os,src_path)
+
+ tar = nil
+
+ if File.exist? "#{src_path}/package/#{pkg.package_name}.install.#{os}"
+ src = "#{src_path}/package/#{pkg.package_name}.install.#{os}"
+ else
+ src = nil
+ end
+
+ if not src.nil? then
+ if os == "linux" or os == "darwin" then
+ tar = "#{src_path}/package/#{pkg.package_name}.package.#{os}/install.sh"
+ elsif os == "windows" then
+ tar = "#{src_path}/package/#{pkg.package_name}.package.#{os}/install.BAT"
+ else
+ puts "Unknown OS: #{os} "
+ return
+ end
+
+ FileUtils.cp(src, tar)
+ end
+
+ return
+ end
+
+
+ # copy post-remove script
+ def copy_post_remove_script(pkg,os,src_path)
+
+ tar = nil
+
+ if File.exist? "#{src_path}/package/#{pkg.package_name}.remove.#{os}"
+ src = "#{src_path}/package/#{pkg.package_name}.remove.#{os}"
+ else
+ src = nil
+ end
+
+ if not src.nil?
+ if os == "linux" or os == "darwin" then
+ tar = "#{src_path}/package/#{pkg.package_name}.package.#{os}/remove.sh"
+ elsif os == "windows" then
+ tar = "#{src_path}/package/#{pkg.package_name}.package.#{os}/remove.BAT"
+ else
+ puts "Unknown OS: #{os} "
+ return
+ end
+
+ FileUtils.cp(src, tar)
+ end
+ end
+
+
+ # create package file
+ def make_zip(pkginfo,os,src_path)
+ for pkg in pkginfo.packages
+ # skip if not support the target os
+ if not pkg.os.include? os
+ next
+ end
+
+ # cd install dir
+ install_dir = "#{src_path}/package/#{pkg.package_name}.package.#{os}"
+
+ # zip
+ @log.info( "Creating package file ... #{pkg.package_name}_#{pkg.version}_#{os}.zip", Log::LV_USER)
+ @log.info("cd \"#{install_dir}\"; zip -r -y #{src_path}/#{pkg.package_name}_#{pkg.version}_#{os}.zip *")
+ Utils.execute_shell_with_log("cd \"#{install_dir}\"; zip -r -y #{src_path}/#{pkg.package_name}_#{pkg.version}_#{os}.zip *", @log)
+ if not File.exist? "#{src_path}/#{pkg.package_name}_#{pkg.version}_#{os}.zip" then
+ return false
+ end
+ end
+ return true
+ end
+end
--- /dev/null
+=begin
+
+ CleanOptionParser.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require 'optparse'
+require 'logger'
+
+def parse()
+
+ #option parsing
+ option = {}
+ optparse = OptionParser.new(nil, 32, ' '*8) do |opts|
+ opts.banner = "Clean the package service command-line tool." + "\n" \
+ + "\n" + "Usage: pkg-clean [-h] or [-v]" + "\n" \
+ + "\n" + "Options:" + "\n"
+
+ opts.on('-h','--help', 'display manual') do
+ puts opts
+ exit
+ end
+
+ opts.on('-v','--version', 'display version') do
+ puts "DIBS(Distributed Intelligent Build System) version 1.2.0"
+ exit
+ end
+ end
+
+ optparse.parse!
+
+ return option
+end
--- /dev/null
+=begin
+
+ optionparser.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require 'optparse'
+require 'logger'
+
+def parse()
+
+ #option parsing
+ option = {}
+ optparse = OptionParser.new do |opts|
+ opts.banner = "Build and packaging service command-line tool." + "\n" \
+ + "\n" + "Usage: pkg-build -u <package server url> [-o <os>] [-c] [-h]" + "\n" \
+ + "\n" + "Options:" + "\n"
+
+ opts.on('-u','--url <package server url>', 'remote package server url: http://127.0.0.1/dibs/unstable') do |url|
+ option[:url] = url
+ end
+
+ option[:os] = nil
+ opts.on('-o','--os <os>', 'operating system ') do |os|
+ option[:os] = os
+ end
+
+ option[:clean] = false
+ opts.on('-c','--clean', 'clean build') do
+ option[:clean] = true
+ end
+
+ option[:rev] = false
+ #opts.on('-r','--rev', 'reverse build dependency check') do
+ # option[:rev] = true
+ #end
+
+ opts.on('-h','--help', 'display manual') do
+ puts opts
+ exit
+ end
+
+ opts.on('-v','--version', 'display version') do
+ puts "DIBS(Distributed Intelligent Build System) version 1.2.0"
+ exit
+ end
+ end
+
+ optparse.parse!
+
+ if option[:url].nil? or option[:url].empty? then
+ raise ArgumentError, "Usage: pkg-build -u <package server url> [-o <os>] [-c] [-h]"
+ end
+
+ return option
+end
--- /dev/null
+=begin
+
+ Action.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+class Action
+ attr_accessor :time, :period
+
+ def initialize( time, period )
+ @time = time
+ @period = period
+ end
+
+
+ # initialize action
+ def init()
+ end
+
+
+ # execute action
+ def execute()
+ end
+
+end
--- /dev/null
+=begin
+
+ PackageManifest.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+$LOAD_PATH.unshift File.dirname(__FILE__)
+require "parser"
+
+class PackageManifest
+ attr_accessor :packages
+
+ def initialize( file_path )
+ @pkg_map = Parser.read_multy_pkginfo_from file_path
+ @packages = @pkg_map.values
+ end
+
+
+ # scan all build dependencies
+ def get_build_dependencies( target_os )
+ # for all
+ list = []
+ for pkg in @packages
+ # package that has the target os
+ if not pkg.os.include?(target_os)
+ next
+ end
+
+ # package that has the target os
+ for dep in pkg.build_dep_list
+ list.push dep
+ end
+ end
+ list.uniq!
+
+ return list
+ end
+
+
+ # scan all source dependencies
+ def get_source_dependencies( target_os, host_os )
+ # for all
+ list = []
+ for pkg in @packages
+ # only package that used in target os
+ if not pkg.os.include?(target_os)
+ next
+ end
+
+ # package that has the host os
+ if not pkg.build_host_os.include?(host_os)
+ next
+ end
+
+ # package that has the target os
+ for dep in pkg.source_dep_list
+ # if dep.target_os_list.include? target_os
+ list.push dep
+ # end
+ end
+ end
+ list.uniq!
+
+ return list
+ end
+
+
+ # scan all install dependencies
+ def get_install_dependencies( target_os )
+ # for all
+ list = []
+ for pkg in @packages
+ # only package that used in target os
+ if not pkg.os.include?(target_os)
+ next
+ end
+
+ # package that has the target os
+ for dep in pkg.install_dep_list
+ list.push dep
+ end
+ end
+ list.uniq!
+
+ return list
+ end
+
+
+ def package_exist?(target_os, host_os)
+ for pkg in @packages
+ # only package that used in target os
+ if pkg.os.include?(target_os) and
+ pkg.build_host_os.include?(host_os)
+ return true
+ end
+ end
+
+ return false
+ end
+
+
+ def get_version()
+ return @packages[0].version
+ end
+
+
+ def get_target_packages(target_os)
+ pkgs = []
+ for pkg in @packages
+ if pkg.os.include?(target_os) then
+ pkgs.push pkg
+ end
+ end
+
+ return pkgs
+ end
+end
--- /dev/null
+=begin
+
+ ScheduledActionHandler.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+$LOAD_PATH.unshift File.dirname(__FILE__)
+
+class ScheduledActionHandler
+ attr_accessor :quit
+
+ # init
+ def initialize( )
+ @thread = nil
+ @quit = false
+ @actions = []
+ end
+
+
+ # register a action
+ def register( action )
+ # init action
+ action.init
+ # add to list
+ @actions.push action
+ end
+
+
+ # start thread
+ def start()
+ @thread = Thread.new {
+ # main
+ thread_main()
+
+ # close
+ terminate()
+ }
+ end
+
+
+ protected
+
+ def thread_main
+
+ while not @quit
+
+ current_time = Time.new
+
+ # get list
+ action_list = Array.new(@actions)
+ for action in action_list
+ # if its time is reached, execute action
+ if not action.time.nil? and current_time > action.time then
+ action.execute
+
+ # if periodic action, renew the time
+ # else remove it from list
+ if action.period != 0 then
+ action.time = action.time + action.period
+ else
+ @actions.delete(action)
+ end
+ end
+ end
+
+ # sleep 1 min
+ sleep 5
+ end
+ end
+
+
+ def terminate
+ end
+
+end
--- /dev/null
+=begin
+
+ Version.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+
+class Version < Array
+ def initialize s
+ super(s.split('.').map { |e| e.to_i })
+ end
+ def < x
+ (self <=> x) < 0
+ end
+ def <= x
+ (self <=> x) <= 0
+ end
+ def > x
+ (self <=> x) > 0
+ end
+ def >= x
+ (self <=> x) >= 0
+ end
+ def == x
+ (self <=> x) == 0
+ end
+ def compare x
+ if self < x then return -1
+ elsif self == x then return 0
+ else return 1 end
+ end
+end
--- /dev/null
+=begin
+
+ dependency.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+$LOAD_PATH.unshift File.dirname(__FILE__)
+require "Version"
+
+class Dependency
+ attr_accessor :package_name, :comp, :base_version, :target_os_list
+ def initialize (package_name, comp, base_version, target_os_list)
+ @package_name = package_name
+ @comp = comp
+ @base_version = base_version
+ @target_os_list = target_os_list
+ end
+
+ def to_s
+ string = @package_name
+ if not @comp.nil? and not @base_version.nil? then
+ string = string + " ( #{@comp} #{@base_version} )"
+ end
+
+ if not @target_os_list.empty? then
+ string = string + " [ #{@target_os_list.join("|")} ]"
+ end
+ return string
+ end
+
+ def match? ver
+ if @base_version.nil?
+ return true
+ end
+
+ # compare to base version
+ if @comp == ">>"
+ return Version.new(ver) > Version.new(@base_version)
+ elsif @comp == ">="
+ return Version.new(ver) >= Version.new(@base_version)
+ elsif @comp == "=="
+ return Version.new(ver) == Version.new(@base_version)
+ elsif @comp == "<="
+ return Version.new(ver) <= Version.new(@base_version)
+ elsif @comp == "<<"
+ return Version.new(ver) < Version.new(@base_version)
+ else
+ return true
+ end
+ end
+end
+
--- /dev/null
+
+require 'socket'
+
+class FileTransfer
+
+ @@log = nil
+
+ def FileTransfer.set_logger(logger)
+ @@log = logger
+ end
+
+ def FileTransfer.putfile(ip, port, username, passwd, bpath)
+ filename = File.basename(bpath)
+ uniqdir = Utils.create_uniq_name
+ ftp_filepath = File.join(uniqdir, filename)
+
+ begin
+ ftp = Net::FTP.new
+ if port.nil? or port == "" then
+ ftp.connect(ip)
+ else
+ ftp.connect(ip, port)
+ end
+ ftp.login(username, passwd)
+ ftp.binary = true
+ ftp.mkdir(uniqdir)
+ ftp.chdir(uniqdir)
+ ftp.put(bpath)
+ ftp.quit
+ rescue => e
+ if not @@log.nil? then
+ @@log.error "FileTransfer::putfile"
+ end
+ raise e
+ end
+ return ftp_filepath
+ end
+
+ def FileTransfer.getfile(ip, port, username, passwd, bpath, target)
+ dirname = File.dirname(bpath)
+ filename = File.basename(bpath)
+
+ # target can be directory or file
+ if File.directory? target then
+ dst_file = File.join(target,filename)
+ else
+ dst_file = target
+ end
+
+ begin
+ ftp = Net::FTP.new
+ if port.nil? or port == "" then
+ ftp.connect(ip)
+ else
+ ftp.connect(ip, port)
+ end
+ ftp.login(username, passwd)
+ ftp.binary = true
+ ftp.chdir(dirname)
+ ftp.get(filename, dst_file)
+ ftp.quit
+ rescue => e
+ @@log.error "FileTransfer::getfile"
+ raise e
+ end
+ return bpath
+ end
+
+ def FileTransfer.cleandir(ip, port, username, passwd, path)
+ dirname = File.dirname(path)
+
+ begin
+ ftp = Net::FTP.new
+ if port.nil? or port == "" then
+ ftp.connect(ip)
+ else
+ ftp.connect(ip, port)
+ end
+ ftp.login(username, passwd)
+ old_dir = ftp.pwd
+ ftp.chdir(dirname)
+ list = ftp.ls
+ # TODO: if list is directory?
+ for l in list
+ file = l.split(" ")[-1].strip
+ ftp.delete(file)
+ end
+ ftp.chdir(old_dir)
+ ftp.rmdir(dirname)
+ ftp.quit
+ rescue => e
+ @@log.error "FileTransfer::cleandir"
+ raise e
+ end
+
+ return true
+ end
+end
--- /dev/null
+=begin
+
+ log.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require "logger"
+
+class Log
+
+ attr_accessor :path
+
+ # Log LEVEL
+ LV_NORMAL = 1
+ LV_USER = 2
+
+
+ # init
+ def initialize(path, lv=LV_USER)
+ @path = path
+ if @path.nil? then
+ @logger = Logger.new(STDOUT)
+ else
+ @logger = Logger.new(path, "monthly")
+ end
+ # if log level is bigger/equal to second out level
+ # , we will send the log to second-out
+ @second_out_level = lv
+ @second_out = nil
+ # diable logger format
+ @default_formatter = @logger.formatter
+ @no_prefix_formatter = proc do |severity, datetime, progname, msg|
+ " >#{msg}"
+ end
+ end
+
+
+ def info(msg, lv=LV_NORMAL)
+ if @path.nil? and not @second_out.nil? then puts "Info: #{msg}"
+ else @logger.info msg end
+ if not @second_out.nil? and lv >= @second_out_level then
+ output_extra "Info: " + msg
+ end
+ end
+
+ def warn(msg, lv=LV_NORMAL)
+ if @path.nil? and not @second_out.nil? then puts "Warn: #{msg}"
+ else @logger.warn msg end
+ if not @second_out.nil? and lv >= @second_out_level then
+ output_extra "Warn: " + msg
+ end
+ end
+
+
+ def error(msg, lv=LV_NORMAL)
+ if @path.nil? and not @second_out.nil? then puts "Error: #{msg}"
+ else @logger.error msg end
+ if not @second_out.nil? and lv >= @second_out_level then
+ output_extra "Error: " + msg
+ end
+ end
+
+
+ def output(msg, lv=LV_NORMAL)
+ if @path.nil? and not @second_out.nil? then puts msg
+ else @logger.info msg end
+ if not @second_out.nil? and lv >= @second_out_level then
+ output_extra msg
+ end
+ end
+
+
+ def close
+ @second_out= nil
+ end
+
+
+ protected
+ def output_extra(msg)
+ #do nothing
+ end
+
+end
--- /dev/null
+=begin
+
+ mail.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require 'net/smtp'
+$LOAD_PATH.unshift File.dirname(__FILE__)
+require "mailConfig"
+
+class Mail
+
+ def Mail.send_mail( mail_to, subject, contents )
+
+ if mail_to.nil? or mail_to.empty? \
+ or subject.nil? or subject.empty? \
+ or contents.nil? or contents.empty? then
+ return false
+ end
+
+ message = <<MESSAGE_END
+From: #{SENDER}
+TO: #{mail_to}
+Subject: #{subject}
+
+#{contents}
+
+MESSAGE_END
+
+ Mail.send_mail2( mail_to, message )
+ end
+
+ def Mail.send_mail2( mail_to_list, message )
+ if mail_to_list.empty? then
+ puts "There is no maintainer email address "
+ else
+ begin
+ Net::SMTP.start('localhost') do |smtp|
+ smtp.send_message( message, SENDER, mail_to_list)
+ end
+ rescue => e
+ puts "Can't send result email"
+ puts e.message
+ end
+ end
+ end
+
+ def Mail.parse_email( low_email_list )
+ mail_list = []
+ low_email_list.split(",").each do | low_email |
+ ms = low_email.index('<')
+ me = low_email.index('>')
+ if ms.nil? or me.nil? then
+ next
+ else
+ mail = low_email[(ms+1)..(me-1)]
+ end
+
+ if mail.include?("@") then mail_list.push mail end
+ end
+
+ return mail_list
+ end
+end
--- /dev/null
+SENDER = "sdk.slp@samsung.com"
+SERVER_ADDR = "http://172.21.17.46:8080"
--- /dev/null
+=begin
+
+ package.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+class Package
+ attr_accessor :package_name, :label, :version, :os, :build_host_os, :maintainer, :attribute, :install_dep_list, :build_dep_list, :source_dep_list, :conflicts, :source, :src_path, :path, :origin, :checksum, :size, :description
+ def initialize (package_name)
+ @package_name = package_name
+ @label = ""
+ @version = ""
+ @os = ""
+ @build_host_os = []
+ @maintainer = ""
+ @attribute = []
+ @install_dep_list = []
+ @build_dep_list = []
+ @source_dep_list = []
+ @conflicts = []
+ @source = ""
+ @src_path = ""
+ @path = ""
+ @origin = ""
+ @checksum = ""
+ @size = ""
+ @description = ""
+ end
+ def print
+ puts "Package : " + @package_name
+ if not @label.empty? then puts "Label : " + @label end
+ if not @version.empty? then puts "Version : " + @version end
+ if not @os.empty? then puts "OS : " + @os end
+ if not @build_host_os.empty? then puts "Build-host-os : " + @build_host_os.join("|") end
+ if not @maintainer.empty? then puts "Maintainer : " + @maintainer end
+ if not @attribute.empty? then puts "Attribute : " + @attribute.join("|") end
+ if not @install_dep_list.empty? then
+ puts "Install-dependency : " + @install_dep_list.map {|x| x.to_s}.join(", ")
+ end
+ if not @build_dep_list.empty? then
+ puts "Build-dependency : " + @build_dep_list.map {|x| x.to_s}.join(", ")
+ end
+ if not @source_dep_list.empty? then
+ puts "Source-dependency : " + @source_dep_list.map {|x| x.to_s}.join(", ")
+ end
+ if not @conflicts.empty? then
+ puts "Conflicts : " + @conflicts.map {|x| x.to_s}.join(", ")
+ end
+ if not @source.empty? then puts "Source : " + @source end
+ if not @src_path.empty? then puts "Src-path : " + @src_path end
+ if not @path.empty? then puts "Path : " + @path end
+ if not @origin.empty? then puts "Origin : " + @origin end
+ if not @checksum.empty? then puts "SHA256 : " + @checksum end
+ if not @size.empty? then puts "Size : " + @size end
+ if not @description.empty? then puts "Description : " + @description end
+ end
+
+ def to_s
+ string = "Package : " + @package_name
+ if not @label.empty? then string = string + "\n" + "Label : " + @label end
+ if not @version.empty? then string = string + "\n" + "Version : " + @version end
+ if not @os.empty? then string = string + "\n" + "OS : " + @os end
+ if not @build_host_os.empty? then string = string + "\n" + "Build-host-os : " + @build_host_os.join("|") end
+ if not @maintainer.empty? then string = string + "\n" + "Maintainer : " + @maintainer end
+ if not @attribute.empty? then string = string + "\n" + "Attribute : " + @attribute.join("|") end
+ if not @install_dep_list.empty? then
+ string = string + "\n" + "Install-dependency : " + @install_dep_list.map {|x| x.to_s}.join(", ")
+ end
+ if not @build_dep_list.empty? then
+ string = string + "\n" + "Build-dependency : " + @build_dep_list.map {|x| x.to_s}.join(", ")
+ end
+ if not @source_dep_list.empty? then
+ string = string + "\n" + "Source-dependency : " + @source_dep_list.map {|x| x.to_s}.join(", ")
+ end
+ if not @conflicts.empty? then
+ string = string + "\n" + "Conflicts : " + @conflicts.map {|x| x.to_s}.join(", ")
+ end
+ if not @source.empty? then string = string + "\n" + "Source : " + @source end
+ if not @src_path.empty? then string = string + "\n" + "Src-path : " + @src_path end
+ if not @path.empty? then string = string + "\n" + "Path : " + @path end
+ if not @origin.empty? then string = string + "\n" + "Origin : " + @origin end
+ if not @checksum.empty? then string = string + "\n" + "SHA256 : " + @checksum end
+ if not @size.empty? then string = string + "\n" + "Size : " + @size end
+ if not @description.empty? then string = string + "\n" + "Description : " + @description end
+ return string
+ end
+ def print_to_file(file)
+ file.puts "Package : " + @package_name
+ if not @label.empty? then file.puts "Label : " + @label end
+ if not @version.empty? then file.puts "Version : " + @version end
+ if not @os.empty? then file.puts "OS : " + @os end
+ if not @build_host_os.empty? then file.puts "Build-host-os : " + @build_host_os.join("|") end
+ if not @maintainer.empty? then file.puts "Maintainer : " + @maintainer end
+ if not @attribute.empty? then file.puts "Attribute : " + @attribute.join("|") end
+ if not @install_dep_list.empty? then
+ file.puts "Install-dependency : " + @install_dep_list.map {|x| x.to_s}.join(", ")
+ end
+ if not @build_dep_list.empty? then
+ file.puts "Build-dependency : " + @build_dep_list.map {|x| x.to_s}.join(", ")
+ end
+ if not @source_dep_list.empty? then
+ file.puts "Source-dependency : " + @source_dep_list.map {|x| x.to_s}.join(", ")
+ end
+ if not @conflicts.empty? then
+ file.puts "Conflicts : " + @conflicts.map {|x| x.to_s}.join(", ")
+ end
+ if not @source.empty? then file.puts "Source : " + @source end
+ if not @src_path.empty? then file.puts "Src-path : " + @src_path end
+ if not @path.empty? then file.puts "Path : " + @path end
+ if not @origin.empty? then file.puts "Origin : " + @origin end
+ if not @checksum.empty? then file.puts "SHA256 : " + @checksum end
+ if not @size.empty? then file.puts "Size : " + @size end
+ if not @description.empty? then file.puts "Description : " + @description end
+ end
+
+ def print_to_file_with_os(file,target_os)
+ file.puts "Package : " + @package_name
+ if not @version.empty? then file.puts "Version : " + @version end
+ if not @label.empty? then file.puts "Label : " + @label end
+ file.puts "OS : " + target_os
+ if not @build_host_os.empty? then file.puts "Build-host-os : " + @build_host_os.join("|") end
+ if not @maintainer.empty? then file.puts "Maintainer : " + @maintainer end
+ if not @attribute.empty? then file.puts "Attribute : " + @attribute.join("|") end
+ if not @install_dep_list.empty? then
+ file.puts "Install-dependency : " + @install_dep_list.map {|x| x.to_s}.join(", ")
+ end
+ if not @build_dep_list.empty? then
+ file.puts "Build-dependency : " + @build_dep_list.map {|x| x.to_s}.join(", ")
+ end
+ if not @source_dep_list.empty? then
+ file.puts "Source-dependency : " + @source_dep_list.map {|x| x.to_s}.join(", ")
+ end
+ if not @conflicts.empty? then
+ file.puts "Conflicts : " + @conflicts.map {|x| x.to_s}.join(", ")
+ end
+ if not @source.empty? then file.puts "Source : " + @source end
+ if not @src_path.empty? then file.puts "Src-path : " + @src_path end
+ if not @path.empty? then file.puts "Path : " + @path end
+ if not @origin.empty? then file.puts "Origin : " + @origin end
+ if not @checksum.empty? then file.puts "SHA256 : " + @checksum end
+ if not @size.empty? then file.puts "Size : " + @size end
+ if not @description.empty? then file.puts "Description : " + @description end
+ end
+end
--- /dev/null
+=begin
+
+ parser.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+$LOAD_PATH.unshift File.dirname(__FILE__)
+require "package"
+require "dependency"
+
+class Parser
+ def Parser.read_multy_pkginfo_from (file)
+ pkglist = {}
+ File.open file,"r" do |f|
+ #variable initialize
+ package_name = ""
+ label = ""
+ version = ""
+ os = ""
+ build_host_os = []
+ maintainer = ""
+ attribute = []
+ install_dep_list = []
+ build_dep_list = []
+ source_dep_list = []
+ conflicts = []
+ source = ""
+ src_path = ""
+ path = ""
+ origin = ""
+ checksum = ""
+ size = ""
+ description = ""
+
+ f.each_line do |l|
+ # separator
+ if l.strip.empty? then
+ #make package and initialize
+ if not package_name.empty? and not os.empty? then
+ package = Package.new(package_name)
+ if not label.empty? then package.label = label end
+ if not version.empty? then package.version = version end
+ if not os.empty? then package.os = os end
+ if not build_host_os.empty? then package.build_host_os = build_host_os end
+ if not maintainer.empty? then package.maintainer = maintainer end
+ if not attribute.empty? then package.attribute = attribute end
+ if not install_dep_list.empty? then package.install_dep_list = install_dep_list end
+ if not build_dep_list.empty? then package.build_dep_list = build_dep_list end
+ if not source_dep_list.empty? then package.source_dep_list = source_dep_list end
+ if not conflicts.empty? then package.conflicts = conflicts end
+ if not source.empty? then package.source = source end
+ if not src_path.empty? then package.src_path = src_path end
+ if not path.empty? then package.path = path end
+ if not origin.empty? then package.origin = origin end
+ if not checksum.empty? then package.checksum = checksum end
+ if not size.empty? then package.size = size end
+ if not description.empty? then package.description = description end
+ pkglist[[package_name,os]] = package
+ package_name = ""
+ label = ""
+ version = ""
+ os = ""
+ bulid_host_os = []
+ maintainer = ""
+ attribute = []
+ install_dep_list = []
+ build_dep_list = []
+ source_dep_list = []
+ conflicts = []
+ source = ""
+ src_path = ""
+ path = ""
+ origin = ""
+ checksum = ""
+ size = ""
+ description = ""
+ end
+ next
+ end
+ # commant
+ if l.strip.start_with? "#" then next end
+ #contents
+ dsic_on = false
+ case l.strip.split(':')[0].strip
+ when /^Package/i then
+ package_name = l.sub(/^[ \t]*Package[ \t]*:[ \t]*/i,"").strip
+ disc_on=false
+ when /^Label/i then
+ label = l.sub(/^[ \t]*Label[ \t]*:[ \t]*/i,"").strip
+ disc_on=false
+ when /^Version/i then
+ version = l.sub(/^[ \t]*Version[ \t]*:[ \t]*/i,"").strip
+ disc_on=false
+ when /^OS/i then
+ os = l.sub(/^[ \t]*OS[ \t]*:[ \t]*/i,"").strip
+ disc_on=false
+ when /^Build-host-os/i then
+ build_host_os = l.sub(/^[ \t]*Build-host-os[ \t]*:[ \t]*/i,"").tr(" \t\n\r", "").split("|")
+ disc_on=false
+ when /^Maintainer/i then
+ maintainer = l.sub(/^[ \t]*Maintainer[ \t]*:[ \t]*/i,"").strip
+ disc_on=false
+ when /^Attribute/i then
+ attribute = l.sub(/^[ \t]*Attribute[ \t]*:[ \t]*/i,"").tr(" \t\n\r","").split("|")
+ disc_on=false
+ when /^Install-dependency/i then
+ install_dep_list = dep_parser l.sub(/^[ \t]*Install-dependency[ \t]*:[ \t]*/i,"").split(',')
+ disc_on=false
+ when /^Build-dependency/i then
+ build_dep_list = dep_parser l.sub(/^[ \t]*Build-dependency[ \t]*:[ \t]*/i,"").split(',')
+ disc_on=false
+ when /^Source-dependency/i then
+ source_dep_list = dep_parser l.sub(/^[ \t]*Source-dependency[ \t]*:[ \t]*/i,"").split(',')
+ disc_on=false
+ when /^Conflicts/i then
+ conflicts = dep_parser l.sub(/^[ \t]*Conflicts[ \t]*:[ \t]*/i,"").split(',')
+ disc_on=false
+ when /^Source/i then
+ source = l.sub(/^[ \t]*Source[ \t]*:[ \t]*/i,"").strip
+ disc_on=false
+ when /^Src-path/i then
+ src_path = l.sub(/^[ \t]*Src-path[ \t]*:[ \t]*/i,"").strip
+ disc_on=false
+ when /^Path/i then
+ path = l.sub(/^[ \t]*Path[ \t]*:[ \t]*/i,"").strip
+ disc_on=false
+ when /^Origin/i then
+ origin = l.sub(/^[ \t]*Origin[ \t]*:[ \t]*/i,"").strip
+ disc_on=false
+ when /^SHA256/i then
+ checksum = l.sub(/^[ \t]*SHA256[ \t]*:[ \t]*/i,"").strip
+ disc_on=false
+ when /^Size/i then
+ size = l.sub(/^[ \t]*Size[ \t]*:[ \t]*/i,"").strip
+ disc_on=false
+ when /^Description/i then
+ description = l.sub(/^[ \t]*Description[ \t]*:[ \t]*/i,"")
+ disc_on=true
+ else
+ if disc_on then
+ description = description + l
+ else
+ puts "unknown section : #{l}"
+ end
+ end
+
+ end
+ #i essent
+
+ # check last package
+ if not package_name.empty? and not os.empty? then
+ package = Package.new(package_name)
+ if not label.empty? then package.label = label end
+ if not version.empty? then package.version = version end
+ if not os.empty? then package.os = os end
+ if not build_host_os.empty? then package.build_host_os = build_host_os end
+ if not maintainer.empty? then package.maintainer = maintainer end
+ if not attribute.empty? then package.attribute = attribute end
+ if not install_dep_list.empty? then package.install_dep_list = install_dep_list end
+ if not build_dep_list.empty? then package.build_dep_list = build_dep_list end
+ if not source_dep_list.empty? then package.source_dep_list = source_dep_list end
+ if not conflicts.empty? then package.conflicts = conflicts end
+ if not source.empty? then package.source = source end
+ if not src_path.empty? then package.src_path = src_path end
+ if not path.empty? then package.path = path end
+ if not origin.empty? then package.origin = origin end
+ if not checksum.empty? then package.checksum = checksum end
+ if not size.empty? then package.size = size end
+ if not description.empty? then package.description = description end
+ pkglist[[package_name,os]] = package
+ end
+ end
+ return pkglist
+ end
+
+ def Parser.read_single_pkginfo_from (file)
+ return read_repo_pkg_list_from(file).values[0]
+ end
+
+ def Parser.read_repo_pkg_list_from (file)
+ result = {}
+ read_multy_pkginfo_from(file).values.each { |x| result[x.package_name]=x }
+ return result
+ end
+
+ private
+ def Parser.dep_parser (string_list)
+ dependency_list = []
+ string_list.each do |dep|
+ #variable initialize
+ package_name = ""
+ comp = nil
+ base_version = nil
+ target_os_list = []
+ #string trim
+ dependency = dep.tr " \t\r\n", ""
+ #version extract
+ vs = dependency.index('(')
+ ve = dependency.index(')')
+ if not vs.nil? and not ve.nil? then
+ comp = dependency[(vs+1)..(vs+2)]
+ base_version = dependency[(vs+3)..(ve-1)]
+ end
+ #os list extract
+ os = dependency.index('[')
+ oe = dependency.index(']')
+ if not os.nil? and not oe.nil? then
+ target_os_list = dependency[(os+1)..(oe-1)].split("|")
+ end
+ # package_name extract
+ pe = dependency.index(/[\]\[\)\(]/)
+ if pe.nil?
+ package_name = dependency
+ else
+ package_name = dependency[0..pe-1]
+ end
+ #package_name check
+ if not package_name.empty? then
+ dependency_list.push Dependency.new(package_name,comp,base_version,target_os_list)
+ end
+ end
+ return dependency_list
+ end
+end
--- /dev/null
+=begin
+
+ utils.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+class Utils
+
+ if defined?(HOST_OS).nil? then
+ case `uname -s`.strip
+ when "Linux"
+ HOST_OS = "linux"
+ when /MINGW32.*/
+ HOST_OS = "windows"
+ when "Darwin"
+ HOST_OS = "darwin"
+ else
+ end
+ end
+
+ # set static variable in WORKING_DIR, HOME
+ if defined?(WORKING_DIR).nil? then WORKING_DIR = Dir.pwd end
+ if defined?(HOME).nil? then
+ # get home directory, using Dir.chdir
+ Dir.chdir
+ HOME = Dir.pwd
+ Dir.chdir WORKING_DIR
+ end
+
+ def Utils.create_uniq_name
+ time = Time.new
+ # uniq snapshot_name name is year_month_day_hour_min_sec_microsec
+ return time.strftime("%m%d%H%M%S") + time.usec.to_s()
+ end
+
+ def Utils.is_url_remote(url)
+ if url.nil? then
+ return false
+ end
+
+ protocol = url.split(':')[0]
+
+ case protocol
+ when "http" then
+ return true
+ else
+ return false
+ end
+ end
+
+ # if source_ver > target_ver, return -1
+ # if source_ver < target_ver, return 1
+ # if source_ver == target_ver, return 0
+ def Utils.compare_version(source_ver, target_ver)
+ sver = source_ver.split('-')[0]
+ tver = target_ver.split('-')[0]
+
+ arr_sver = sver.split('.')
+ arr_tver = tver.split('.')
+
+ slen = arr_sver.length
+ tlen = arr_tver.length
+ len = tlen
+
+ if slen > tlen then
+ gap = slen - tlen
+ gap.times do
+ arr_tver.push("0")
+ end
+ len = slen
+ elsif tlen > slen then
+ gap = tlen - slen
+ gap.times do
+ arr_sver.push("0")
+ end
+ len = tlen
+ end
+
+ len.times do |i|
+ if arr_sver[i].to_i < arr_tver[i].to_i then
+ return 1
+ elsif arr_sver[i].to_i > arr_tver[i].to_i then
+ return -1
+ end
+ end
+
+ return 0
+ end
+
+
+ def Utils.execute_shell(cmd)
+ ret = false
+ if HOST_OS.eql? "windows" then
+ mingw_path = "sh.exe -c "
+ cmd = cmd.gsub("\"", "\\\"")
+ cmd = mingw_path + "\"#{cmd}\""
+ end
+
+ `#{cmd}`
+ if $?.to_i == 0 then ret = true else ret = false end
+
+ return ret
+ end
+
+
+ def Utils.execute_shell_return(cmd)
+ result_lines = []
+
+ if HOST_OS.eql? "windows" then
+ mingw_path = "sh.exe -c "
+ cmd = cmd.gsub("\"", "\\\"")
+ cmd = mingw_path + "\"#{cmd}\""
+ end
+
+ # get result
+ IO.popen("#{cmd} 2>&1") { |io|
+ io.each do |line|
+ result_lines.push line
+ end
+ }
+
+ if $?.to_i == 0 then
+ return result_lines
+ else
+ return nil
+ end
+ end
+
+ def Utils.execute_shell_return_ret(cmd)
+ if HOST_OS.eql? "windows" then
+ mingw_path = "sh.exe -c "
+ cmd = cmd.gsub("\"", "\\\"")
+ cmd = mingw_path + "\"#{cmd}\""
+ end
+
+ return `#{cmd}`
+ end
+
+ def Utils.execute_shell_with_log(cmd, log)
+
+ if HOST_OS.eql? "windows" then
+ mingw_path = "sh.exe -c "
+ cmd = cmd.gsub("\"", "\\\"")
+ cmd = mingw_path + "\"#{cmd}\""
+ end
+
+ # print log
+ IO.popen("#{cmd} 2>&1") { |io|
+ io.each do |line|
+ log.output line
+ end
+ }
+
+ if $?.to_i == 0 then
+ return true
+ else
+ return false
+ end
+ end
+
+
+ def Utils.is_absolute_path(path)
+ if HOST_OS.eql? "linux" or HOST_OS.eql? "darwin" then
+ # if path start "/" then absoulte path
+ if path.start_with?("/") then
+ return true
+ else
+ return false
+ end
+ elsif HOST_OS.eql? "windows" then
+ # if path start "c:/" or "D:/" or ... then absoulte path
+ if path =~ /^[a-zA-Z]:[\/]/ then
+ return true
+ else
+ return false
+ end
+ else
+ puts "HOST_OS is invalid"
+ end
+ end
+
+
+ # this will be used on MinGW/MSYS
+ def Utils.get_unix_path(path)
+ if HOST_OS.eql? "linux" or HOST_OS.eql? "darwin" then
+ return path
+ elsif HOST_OS.eql? "windows" then
+ new_path = path
+ if is_absolute_path( new_path ) then
+ new_path = "/" + new_path[0,1] + new_path[2..-1]
+ end
+ return new_path
+ else
+ puts "HOST_OS is invalid"
+ return path
+ end
+ end
+
+ def Utils.file_lock(lock_file_name)
+ lock_file = File.new(lock_file_name, File::RDWR|File::CREAT, 0644)
+ lock_file.flock(File::LOCK_EX)
+ lock_file.rewind
+ lock_file.flush
+ lock_file.truncate(lock_file.pos)
+
+ return lock_file
+ end
+
+ def Utils.file_unlock(lock_file)
+ lock_file.close
+ end
+
+ def Utils.parse_server_addr(saddr)
+ addr = saddr.split(":")
+ return nil unless addr.length == 2
+ return addr
+ end
+
+ def Utils.parse_ftpserver_url(surl)
+ return nil unless surl.start_with? "ftp://"
+
+ surl = surl[6..-1]
+ parse1 = surl.split("@")
+ return nil unless parse1.length == 2
+
+ idpw = parse1[0]
+ url = parse1[1]
+ parse1 = idpw.split(":")
+ return nil unless parse1.length == 2
+
+ id = parse1[0]
+ passwd = parse1[1]
+ if url.end_with? "/" then url = url.chop end
+
+ parse1 = url.split(":")
+ if parse1.length == 2 then
+ ip = parse1[0]
+ port = parse1[1]
+ elsif parse1.length == 1 then
+ ip = parse1[0]
+ port = 21
+ else
+ return nil
+ end
+
+ return [ip, port, id, passwd]
+ end
+
+
+ def Utils.generate_ftp_url(addr, port, username, passwd)
+ return "ftp://#{username}:#{passwd}@#{addr}:#{port}"
+ end
+
+
+ def Utils.extract_a_file(file_path, target_file, path)
+ dirname = File.dirname(file_path)
+ filename = File.basename(file_path)
+ ext = File.extname(filename)
+
+ # path should be unix path if it is used in tar command
+ _package_file_path = Utils.get_unix_path(file_path)
+ _path = Utils.get_unix_path(path)
+
+ case ext
+ when ".zip" then
+ if not path.nil? then
+ extract_file_command = "unzip -xo #{_package_file_path} #{target_file} -d #{_path}"
+ else
+ extract_file_command = "unzip -xo #{_package_file_path} #{target_file}"
+ end
+ when ".tar" then
+ if not path.nil? then
+ extract_file_command = "tar xf #{_package_file_path} -C #{_path} #{target_file}"
+ else
+ extract_file_command = "tar xf #{_package_file_path} #{target_file}"
+ end
+ end
+
+ # check exit code
+ ret = execute_shell "#{extract_file_command}"
+ if not ret then return false end
+
+ # check result file
+ if not path.nil? then
+ target_file_path = File.join(path, target_file)
+ else
+ target_file_path = target_file
+ end
+
+ if not File.exist? target_file_path then
+ return false
+ else
+ return true
+ end
+ end
+end
--- /dev/null
+require 'socket'
+
+$LOAD_PATH.unshift File.dirname(__FILE__)
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/build_server"
+require "packageServerConfig"
+require "fileTransfer"
+require "BuildComm"
+require "net/ftp"
+
+class SocketRegisterListener
+
+ # initialize
+ def initialize (parent)
+ @parent_server = parent
+ @thread = nil
+ @finish_loop = false
+ @log = @parent_server.log
+ end
+
+ # start listening
+ def start()
+ @log.info "SocketRegisterListener start"
+ @thread = Thread.new {
+ main()
+ }
+ end
+
+ # quit listening
+ def stop_listening()
+ @finish_loop = true
+ end
+
+ private
+
+ # thread main
+ def main()
+ @log.info "SocketRegisterListener entering main loop"
+ # server open
+ begin
+ @comm_server = BuildCommServer.new(@parent_server.port, @log)
+ rescue => e
+ @log.info "Server creation failed"
+ @log.error e.message
+ @log.error e.backtrace.inspect
+ return
+ end
+
+ # loop
+ @log.info "Entering Control Listening Loop ... "
+ @finish_loop = false
+ @comm_server.wait_for_connection(@finish_loop) do |req|
+ begin
+ handle_job_request( req )
+ rescue => e
+ @log.info "error occured in handle_job_request function"
+ @log.error e.message
+ @log.error e.backtrace.inspect
+ end
+ end
+
+ # quit
+ @comm_server.terminate
+ end
+
+ # wait for job requests
+ def wait_for_job_requests
+ req_list = []
+ req_list.push @tcp_server.accept
+
+ return req_list
+ end
+
+ # handle job request
+ def handle_job_request( req )
+
+ # read request
+ req_line = req.gets
+ if req_line.nil? then return end
+
+ # parse request
+ cmd = ""
+ if req_line.split(",").count > 0 then
+ cmd = req_line.split(",")[0].strip
+ end
+
+ case cmd
+ when "UPLOAD"
+ Thread.new {
+ handle_cmd_upload( req_line, req )
+ }
+ when "REGISTER"
+ handle_cmd_register( req_line, req )
+ when "STOP"
+ handle_cmd_stop( req_line, req )
+ else
+ @log.error "Received Unknown REQ: #{req_line}"
+ end
+ @log.info "REQ processing done"
+ end
+
+ # "UPLOAD"
+ def handle_cmd_upload( line, req )
+ @log.info "Received File transfer REQ : #{line}"
+ BuildCommServer.send_begin(req)
+ begin
+ @comm_server.receive_file(req, @parent_server.incoming_path)
+ rescue => e
+ @log.error "Failed to transfer file"
+ @log.error e.message
+ @log.error e.backtrace.inspect
+ BuildCommServer.send_end(req)
+ return
+ end
+ BuildCommServer.send_end(req)
+ end
+
+ # "Register"
+ def handle_cmd_register( line, req )
+ @log.info "Received register REQ : #{line}"
+
+ @parent_server.reload_dist_package()
+
+ tok = line.split(",").map { |x| x.strip }
+ BuildCommServer.send_begin(req)
+ if tok.count < 3 then
+ @log.error "Received Wrong REQ : #{line}"
+ BuildCommServer.send(req, "ERROR,Invalid REQ format")
+ return
+ end
+ dist_name = tok[1].strip
+
+ file_path_list = []
+
+ idx = 2
+ while idx < tok.length do
+ file_path_list.push "#{@parent_server.incoming_path}/#{tok[idx]}"
+ idx = idx + 1
+ end
+
+ begin
+ snapshot_name = @parent_server.register( file_path_list, dist_name, true, false)
+ rescue => e
+ @log.error "register failed"
+ @log.error e.message
+ @log.error e.backtrace.inspect
+ BuildCommServer.send(req, "ERROR,#{e.message}")
+ @parent_server.release_lock_file
+ return
+ end
+
+ BuildCommServer.send(req,"SUCC,#{snapshot_name}")
+ BuildCommServer.send_end(req)
+ end
+
+ # "STOP"
+ def handle_cmd_stop( line, req )
+ @log.info "Received STOP REQ"
+
+ @parent_server.finish = true
+ BuildCommServer.send_begin(req)
+ BuildCommServer.send(req,"SUCC")
+ BuildCommServer.send_end(req)
+ BuildCommServer.disconnect(req)
+ @log.info "Package server stop"
+ end
+end
+
--- /dev/null
+
+=begin
+
+ client.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require "fileutils"
+require "thread"
+$LOAD_PATH.unshift File.dirname(__FILE__)
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/build_server"
+require "downloader"
+require "installer"
+require "fileTransfer"
+require "packageServerConfig"
+require "package"
+require "parser"
+require "utils"
+require "log"
+require "Version"
+require "net/ftp"
+$update_mutex = Mutex.new
+class Client
+
+ # constant
+ SUPPORTED_OS = ["linux", "windows", "darwin"]
+ PKG_LIST_FILE_PREFIX = "pkg_list_"
+ INSTALLED_PKG_LIST_FILE = "installedpackage.list"
+ CONFIG_PATH = "#{PackageServerConfig::CONFIG_ROOT}/client"
+ PACKAGE_INFO_DIR = ".info"
+ DEFAULT_INSTALL_DIR = "#{Utils::HOME}/build_root"
+ DEFAULT_SERVER_ADDR = "http://172.21.17.55/dibs/unstable"
+
+ attr_accessor :server_addr, :location, :pkg_hash_os, :is_server_remote, :installed_pkg_hash_loc, :archive_pkg_list, :all_dep_list, :log
+
+ public
+ # initialize
+ # create "remote package hash" and "installed package hash"
+ # @server_addr = server address (can be included distribution, snapshot)
+ # @location = client location (download and install file to this location)
+ def initialize(server_addr, location, logger)
+
+ # create directory
+ if not File.exist? CONFIG_PATH then FileUtils.mkdir_p "#{CONFIG_PATH}" end
+
+ # set default server address, location
+ if server_addr.nil? then server_addr = get_default_server_addr() end
+ if location.nil? then location = get_default_inst_dir() end
+
+ # chop server address, if end with "/"
+ if server_addr.strip.end_with? "/" then server_addr = server_addr.chop end
+
+ @server_addr = server_addr
+ @location = location
+ @pkg_hash_os = {}
+ @installed_pkg_hash_loc = {}
+ @archive_pkg_list = []
+ @all_dep_list = []
+ @is_server_remote = Utils.is_url_remote(server_addr)
+
+ # set log
+ if logger.nil? or logger.class.to_s.eql? "String" then
+ @log = Log.new(logger)
+ else
+ @log = logger
+ end
+
+ FileInstaller.set_logger(@log)
+ FileDownLoader.set_logger(@log)
+ FileTransfer.set_logger(@log)
+
+ # read installed pkg list, and create hash
+ if not File.exist? @location then FileUtils.mkdir_p "#{@location}" end
+ create_installed_pkg_hash()
+
+ # readk remote pkg list, and hash list
+ create_remote_pkg_hash(false)
+ @log.info "Initialize - #{server_addr}, #{location}"
+ end
+
+ public
+ # update package list from server
+ def update()
+ # update operation must be processed one by one
+ $update_mutex.synchronize {
+ if not create_remote_pkg_hash(true) then
+ @log.error "\"#{@server_addr}\" does not have package list file properly."
+ return false
+ end
+ create_default_config(@server_addr)
+ @log.info "Update package list from \"#{@server_addr}\".. OK"
+ }
+ return true
+ end
+
+ public
+ # download package
+ def download(pkg_name, os, trace)
+
+ dependent_pkg_list = []
+
+ # get dependent list
+ if trace then
+ dependent_pkg_list = get_install_dependent_packages(pkg_name, os, true, false)
+ if dependent_pkg_list.nil? then
+ @log.error "Failed to get dependency for \"#{pkg_name}\" package"
+ return nil
+ end
+ else dependent_pkg_list = [pkg_name] end
+
+ surl = nil
+ addr_arr = @server_addr.split('/')
+ if addr_arr[-2].eql? "snapshots" then
+ surl = @server_addr + "/../.."
+ else
+ surl = @server_addr
+ end
+
+ # download files
+ file_local_path = []
+ dependent_pkg_list.each do |p|
+ pkg_path = get_attr_from_pkg(p, os, "path")
+ pkg_ver = get_attr_from_pkg(p, os, "version")
+ if pkg_path.nil? or pkg_ver.nil? then
+ @log.error "\"#{p}\" package does not exist in package server. If it exist in package server, then try \"pkg-cli update\""
+ return nil
+ end
+ url = surl + pkg_path
+ filename = pkg_path.split('/')[-1]
+ if not FileDownLoader.download(url, @location) then
+ @log.error "Failed download #{pkg_name} [#{pkg_ver}]"
+ return nil
+ end
+
+ file_path = File.join(@location, filename)
+ file_local_path.push(file_path)
+ @log.info "Downloaded \"#{p} [#{pkg_ver}]\" package file.. OK"
+ #@log.info " [path : #{file_path}]"
+ end
+
+ if trace then
+ @log.info "Downloaded \"#{pkg_name}\" package with all dependent packages.. OK"
+ else
+ @log.info "Downloaded only \"#{pkg_name}\" package.. OK"
+ end
+ @log.info " [path : #{file_local_path.join(", ")}]"
+
+ return file_local_path
+ end
+
+ public
+ # download source package
+ def download_source(pkg_name, os)
+
+ # get source file path
+ src_path = get_attr_from_pkg(pkg_name, os, "src_path")
+ if src_path.nil? or src_path.empty? then
+ @log.error "#{pkg_name} package does not have source"
+ return nil
+ end
+ file_url = nil
+
+ addr_arr = @server_addr.split('/')
+ if addr_arr[-2].eql? "snapshots" then
+ surl = @server_addr + "/../.." + src_path
+ else
+ surl = @server_addr + src_path
+ end
+
+ # download file
+ filename = src_path.split('/')[-1]
+ if not FileDownLoader.download(surl, @location) then
+ @log.error "Failed download #{pkg_name} source"
+ return nil
+ end
+ file_local_path = File.join(@location, filename)
+ @log.info "Downloaded source of #{pkg_name} package.. OK"
+ @log.info " [path : #{file_local_path}]"
+
+ return file_local_path
+ end
+
+ public
+ # download dependent source
+ def download_dep_source(file_name)
+
+ file_url = nil
+
+ addr_arr = @server_addr.split('/')
+ if addr_arr[-2].eql? "snapshots" then
+ file_url = @server_addr + "/../../source/" + file_name
+ else
+ file_url = @server_addr + "/source/#{file_name}"
+ end
+ if not FileDownLoader.download(file_url, @location) then
+ @log.error "Failed download #{file_name}"
+ return nil
+ end
+ file_local_path = File.join(@location, file_name)
+ @log.info "Downloaded \"#{file_name}\" source file.. OK"
+ @log.info " [path : #{file_local_path}]"
+
+ return file_local_path
+ end
+
+ public
+ # check archive file
+ def check_archive_file(file_name)
+
+ result = false
+ filename = "archive_pkg_list"
+ local_file_path = File.join(CONFIG_PATH, filename)
+ if File.exist? local_file_path then
+ File.open(local_file_path, "r") do |f|
+ f.each_line do |l|
+ if l.strip.eql? file_name.strip then
+ result = true
+ break
+ end
+ end
+ end
+ end
+ return result
+ end
+
+ public
+ # upload package
+ def upload(ip, port, ftp_addr, ftp_port, ftp_username, ftp_passwd, binary_path_list)
+
+ # check ip and port
+ if ip.nil? or port.nil? then
+ @log.error "Ip and port should be set."
+ return nil
+ end
+
+ # check binary path list
+ if binary_path_list.nil? or binary_path_list.empty? then
+ @log.error "Binary package path should be set."
+ return nil
+ end
+
+ # upload file
+ binary_list = []
+ binary_path_list.each do |bpath|
+ filename = File.basename(bpath)
+ client = BuildCommClient.create(ip, port)
+
+ if client.nil? then
+ @log.error "Failed to create BuildCommClient instance.."
+ return nil
+ end
+
+ @log.info "Send ready REQ.. [UPLOAD]"
+ result = client.send("UPLOAD")
+ if not result then
+ @log.error "Failed to send ready REQ.."
+ return nil
+ end
+
+ begin
+ result = client.send_file(ftp_addr, ftp_port, ftp_username, ftp_passwd, bpath)
+ rescue => e
+ @log.error "FTP failed to put file (exception)"
+ @log.error "#{e.message}"
+ @log.error e.backtrace.inspect
+ return nil
+ end
+
+ if not result then
+ @log.error "FTP failed to put file (result is false)"
+ return nil
+ end
+
+ client.terminate
+ binary_list.push(filename)
+ end
+
+ # register file
+ client = BuildCommClient.create(ip, port)
+ dist = get_distribution
+ if dist.empty? then
+ @log.error "Distribution is empty.."
+ return nil
+ end
+
+ @log.info "Send register message.. [REGISTER,#{dist},#{binary_list.join(",")}]"
+ snapshot = nil
+ if client.send "REGISTER,#{dist},#{binary_list.join(",")}" then
+ output = client.read_lines do |l|
+ line = l.split(",")
+ if line[0].strip == "ERROR" then
+ @log.error l.strip
+ return nil
+ elsif line[0].strip == "SUCC" then
+ snapshot = line[1].strip
+ end
+ end
+ if not output then
+ @log.error "Failed to register"
+ return nil
+ end
+ end
+
+ client.terminate
+ snapshot = @server_addr + "/snapshots/" + snapshot
+ @log.info "Registered successfully! [#{binary_path_list.join(",")}]"
+ if snapshot.empty? then
+ @log.error "Failed to generate snapshot"
+ end
+
+ return snapshot
+ end
+
+ private
+ # verify package before uploading
+ def verify_upload(pkg_name, pkg_path)
+
+ manifest_file = "pkginfo.manifest"
+ uniq_name = Utils.create_uniq_name
+ path = Utils::HOME + "/tmp/#{uniq_name}"
+ if not File.exist? path then FileUtils.mkdir_p "#{path}" end
+ begin
+ if not FileInstaller.extract_a_file(pkg_path, manifest_file, path) then
+ @log.error "The \"pkginfo.manifest\" file does not exist in \"#{pkg_path}\""
+ return false
+ end
+ manifest_path = File.join(path, manifest_file)
+ pkg = Parser.read_single_pkginfo_from manifest_path
+ FileUtils.rm_f(manifest_path)
+ FileUtils.remove_dir(path, true)
+ rescue Interrupt
+ @log.error "Client: Interrupted.."
+ FileUtils.rm_f(manifest_path)
+ FileUtils.remove_dir(path, true)
+ @log.info "Removed #{manifest_path}"
+ @log.info "Removed #{path}"
+ raise Interrupt
+ end
+ new_pkg_ver = pkg.version
+ new_pkg_install_dep_list = pkg.install_dep_list
+ os = pkg.os
+
+ list = get_all_reverse_install_dependent_packages_remote(pkg_name, os, true)
+
+ if not list.nil? then
+ list.each do |p|
+ ilist = get_attr_from_pkg(p, os, "install_dep_list")
+ if ilist.nil? then next end
+ ilist.each do |l|
+ if l.package_name.eql? pkg_name then
+ if not l.match? new_pkg_ver then
+ @log.error "\"#{p}\" package has following install dependency : #{l.package_name} (#{l.comp} #{l.base_version})"
+ return false
+ end
+ end
+ end
+ end
+ end
+
+ if not new_pkg_install_dep_list.nil? then
+ new_pkg_install_dep_list.each do |l|
+ if not check_remote_pkg(l.package_name, os) then
+ @log.error "\"#{pkg_name}\" package has following install dependency : #{l.package_name} (#{l.comp} #{l.base_version}), but \"#{l.package_name}\" is not exist on server"
+ return false
+ end
+ rver = get_attr_from_pkg(l.package_name, os, "version")
+ if not l.match? rver then
+ @log.error "\"#{pkg_name}\" package has following install dependency : #{l.package_name} (#{l.comp} #{l.base_version})"
+ return false
+ end
+ end
+ end
+
+ @log.info "Passed to verify packages for uploading.. OK"
+ return true
+ end
+
+ private
+ # get distribution
+ def get_distribution()
+ server = @server_addr
+ if server.nil? or server.empty? then
+ @log.error "Server addr is nil"
+ return nil
+ end
+
+ dist = ""
+ server_arr = server.split("/")
+ if server_arr.include? "snapshots" then
+ i = server_arr.index("snapshots")
+ dist = server_arr[i-1]
+ else dist = File.basename(server) end
+
+ return dist
+ end
+
+ public
+ # install package
+ # install all install dependency packages
+ def install(pkg_name, os, trace, force)
+
+ if trace.nil? then trace = true end
+ if force.nil? then force = false end
+
+ # check meta package
+ is_meta_pkg = check_meta_pkg(pkg_name, os)
+ if is_meta_pkg then trace = true end
+
+ # compare package version with installed package's
+ pkg_ver = get_attr_from_pkg(pkg_name, os, "version")
+ if pkg_ver.nil? or pkg_ver.empty? then
+ @log.error "#{pkg_name} package does not exist in remote package list"
+ return false
+ end
+
+ compare_result = compare_version_with_installed_pkg(pkg_name, pkg_ver)
+ if not force then
+ case compare_result
+ when -1 then
+ @log.warn "\"#{pkg_name}\" package version is bigger then remote package version"
+ return true
+ when 0 then
+ @log.warn "\"#{pkg_name}\" package version is same with remote package version"
+ return true
+ when 1, 2 then
+ end
+ end
+
+ # if enable trace, create all dependent package list
+ if trace then
+ dependent_pkg_list = get_install_dependent_packages(pkg_name, os, true, force)
+ if dependent_pkg_list.nil? then
+ @log.error "Failed to get dependency for \"#{pkg_name}\" package"
+ return false
+ end
+ else
+ dependent_pkg_list = [pkg_name]
+ end
+
+ # TODO: need to compare dependent package version
+ # install packages including dependent packages
+ dependent_pkg_list.each do |pkg|
+ if not install_pkg(pkg, os, force) then
+ @log.error "#{pkg} does not exist"
+ return false
+ end
+ add_pkg_info(pkg, os)
+ end
+
+ # write installed package information to file
+ write_pkg_hash_to_file(nil)
+
+ if trace then
+ @log.info "Installed \"#{pkg_name} [#{pkg_ver}]\" package with all dependent packages.. OK"
+ @log.info " [#{dependent_pkg_list.join(" -> ")}]"
+ else
+ @log.info "Install only \"#{pkg_name} [#{pkg_ver}]\" package.. OK"
+ end
+ return true
+ end
+
+ public
+ # install local package (ignore dependent packages)
+ def install_local_pkg(pkg_path, force)
+
+ file_name = File.basename(pkg_path)
+ pkg_name = file_name.split('_')[0]
+
+ if not File.exist? pkg_path then
+ @log.error "\"#{pkg_path}\" file does not exist"
+ return false
+ end
+ filename = File.basename(pkg_path)
+ ext = File.extname(filename)
+ if not ext.eql? ".zip" then
+ @log.error "\"#{file_name}\" is not zip file. binary package file should have .zip ext"
+ return false
+ end
+ pkg_name = filename.split("_")[0]
+ type = "binary"
+ manifest_file = "pkginfo.manifest"
+ pkg_config_path = File.join(@location, PACKAGE_INFO_DIR, pkg_name)
+
+ uniq_name = Utils.create_uniq_name
+ path = Utils::HOME + "/tmp/#{uniq_name}"
+ if not File.exist? path then FileUtils.mkdir_p "#{path}" end
+ begin
+ if not FileInstaller.extract_a_file(pkg_path, manifest_file, path) then
+ @log.error "pkginfo.manifest file does not exist in #{pkg_path}"
+ return false
+ end
+ manifest_path = File.join(path, manifest_file)
+ pkg = Parser.read_single_pkginfo_from manifest_path
+ new_pkg_ver = pkg.version
+ FileUtils.rm_f(manifest_path)
+ FileUtils.remove_dir(path, true)
+ rescue Interrupt
+ @log.error "Client: Interrupted.."
+ FileUtils.rm_f(manifest_path)
+ FileUtils.remove_dir(path, true)
+ @log.info "Removed #{mainfest_path}"
+ @log.info "Removed #{path}"
+ raise Interrupt
+ end
+
+ compare_result = compare_version_with_installed_pkg(pkg_name, new_pkg_ver)
+ if not force then
+ case compare_result
+ when -1 then
+ @log.warn "\"#{pkg_name}\" package version is bigger then remote package version.."
+ return true
+ when 0 then
+ @log.warn "\"#{pkg_name}\" package version is same with remote package version.."
+ return true
+ when 1, 2 then
+ end
+ end
+
+ if check_installed_pkg(pkg_name) then
+ uninstall(pkg_name, false)
+ end
+
+ # install package
+ ret = FileInstaller.install(pkg_name, pkg_path, "binary", @location)
+
+ add_local_pkg_info(pkg_name)
+ write_pkg_hash_to_file(nil)
+
+ @log.info "Installed \"#{pkg_path} [#{new_pkg_ver}]\" file.. OK"
+ return true
+ end
+
+ public
+ # upgrade package
+ def upgrade(os, trace)
+
+ if trace.nil? then trace = true end
+ list = check_upgrade(os)
+
+ if list.empty? or list.nil? then
+ @log.info "There is no packages for upgrading.."
+ return false
+ end
+
+ list.each do |p|
+ if check_installed_pkg(p) then
+ if not uninstall(p, trace) then
+ @log.error "Failed to uninstall \"#{p}\" package.."
+ return false
+ end
+ end
+
+ if not install(p, os, trace, false) then
+ @log.error "Failed to install \"#{p}\" package.."
+ return false
+ end
+ end
+
+ @log.info "Upgraded packages from #{@server_addr}.. OK"
+ return true
+ end
+
+ public
+ # check package which will be upgraded
+ def check_upgrade(os)
+
+ update_pkgs = []
+ installed_pkg_hash_key = get_installed_pkg_list_file_path()
+ installed_pkg_hash = installed_pkg_hash_loc[installed_pkg_hash_key]
+ remote_pkg_hash = pkg_hash_os[os]
+
+ if remote_pkg_hash.nil? then
+ @log.error "There is no remote package list for #{os}. please pkg-cli update"
+ return nil
+ end
+
+ if installed_pkg_hash.nil? then
+ @log.warn "There is no any installed package in \"#{@location}\""
+ return remote_pkg_hash.keys
+ end
+
+ arr_keys = installed_pkg_hash.keys
+ arr_keys.each do |k|
+ installed_ver = get_attr_from_installed_pkg(k, "version")
+ if not check_remote_pkg(k, os) then next end
+ remote_ver = get_attr_from_pkg(k, os, "version")
+ compare_result = compare_version_with_installed_pkg(k, remote_ver)
+ case compare_result
+ when -1 then next
+ when 0 then next
+ when 1 then
+ @log.output "\"#{k}\" package : #{installed_ver} -> #{remote_ver}"
+ update_pkgs.push(k)
+ end
+ end
+
+ @log.info "Checked packages for upgrading.. OK"
+ return update_pkgs
+ end
+
+ public
+ def get_default_server_addr()
+ filepath = "#{CONFIG_PATH}/config"
+ server_addr = nil
+
+ if not File.exist? filepath then create_default_config(nil) end
+ if not File.exist? filepath then
+ @log.error "There is no default server address in #{filepath}"
+ return nil
+ end
+
+ File.open filepath, "r" do |f|
+ f.each_line do |l|
+ if l.strip.start_with? "DEFAULT_SERVER_ADDR :" then
+ server_addr = l.split("DEFAULT_SERVER_ADDR :")[1].strip
+ break
+ else next end
+ end
+ end
+
+ if server_addr.nil? then create_default_config(DEFAULT_SERVER_ADDR) end
+ return server_addr
+ end
+
+ public
+ # get default path for installing
+ def get_default_inst_dir()
+ return Dir.pwd
+ end
+
+ private
+ # create default config file (Utils::HOME/.build_tools/client/config)
+ def create_default_config(server_addr)
+ filepath = "#{CONFIG_PATH}/config"
+ if server_addr.nil? then server_addr = DEFAULT_SERVER_ADDR end
+
+ if File.exist? filepath then
+ FileUtils.rm_f(filepath)
+ end
+
+ if server_addr.strip.end_with? "/" then server_addr = server_addr.chop end
+
+ File.open(filepath, "a+") do |file|
+ file.puts "DEFAULT_SERVER_ADDR : #{server_addr}"
+ end
+ end
+
+ public
+ # uninstall package
+ # trace : if true, uninstall all dependent packages
+ def uninstall(pkg_name, trace)
+
+ type = "binary"
+ pkg_list = []
+ pkg_hash = nil
+
+ if not check_installed_pkg(pkg_name) then
+ @log.error "\"#{pkg_name}\" package is not installed."
+ return false
+ end
+
+ pkg_ver = get_attr_from_installed_pkg(pkg_name, "version")
+
+ if trace then
+ pkg_list = get_all_reverse_install_dependent_packages(pkg_name, true)
+ if pkg_list.nil? then
+ @log.error "Failed to get \"#{pkg_name}\" package dependency information."
+ return false
+ end
+ else
+ pkg_list.push(pkg_name)
+ end
+
+ pkg_list.each do |p|
+ if not check_installed_pkg(p) then next end
+ if not FileInstaller.uninstall(p, type, @location) then
+ @log.error "Failed uninstall \"#{pkg_name}\" package"
+ return false
+ end
+ pkg_hash = remove_pkg_info(p)
+ end
+
+ if trace then
+ @log.info "Uninstalled \"#{pkg_name} [#{pkg_ver}]\" package with all dependent packages.. OK"
+ @log.info " [#{pkg_list.join(" -> ")}]"
+ else
+ @log.info "Uninstalled only \"#{pkg_name} [#{pkg_ver}]\" package.. OK"
+ end
+
+ write_pkg_hash_to_file(nil)
+ return true
+ end
+
+ public
+ # clean
+ def clean(force)
+ if not force then
+ puts "Do you really want to remove \"#{@location}\" path? [yes]"
+ input = $stdin.gets.strip
+ if input.upcase.eql? "YES" then
+ @log.info "Removed \"#{@location}\""
+ else
+ @log.info "Canceled"
+ return
+ end
+ end
+ if File.exist? @location then FileUtils.rm_rf(@location) end
+ FileUtils.mkdir_p(@location)
+ @pkg_hash_os.clear
+ @installed_pkg_hash_loc.clear
+ @archive_pkg_list.clear
+ @log.info "Cleaned \"#{@location}\" path.. OK"
+ end
+
+ public
+ # get reverse build dependent packages (just 1 depth)
+ def get_reverse_build_dependent_packages(pkg_name, os)
+
+ result = []
+ pkg_hash = @pkg_hash_os[os]
+ pkg_list = pkg_hash.values
+ pkg_list.each do |pkg|
+ pkg.build_dep_list.each do |dep|
+ if dep.package_name.eql? pkg_name and
+ not dep.target_os_list.nil? and
+ dep.target_os_list.include? os then
+ result.push(pkg)
+ end
+ end
+ end
+
+ return result
+ end
+
+ public
+ # get reverse source dependent packages (just 1 depth)
+ def get_reverse_source_dependent_packages(pkg_name)
+
+ result = []
+ for os in SUPPORTED_OS
+ pkg_hash = @pkg_hash_os[os]
+ pkg_list = pkg_hash.values
+ pkg_list.each do |pkg|
+ pkg.source_dep_list.each do |p|
+ if p.package_name.eql? pkg_name then
+ result.push(pkg)
+ end
+ end
+ end
+ end
+
+ return result
+ end
+
+ public
+ # get reverse install dependent packages (jush 1 depth)
+ def get_reverse_install_dependent_packages(pkg_name, os)
+
+ result = []
+ pkg_hash = @pkg_hash_os[os]
+ pkg_list = pkg_hash.values
+ pkg_list.each do |pkg|
+ pkg.install_dep_list.each do |p|
+ if p.package_name.eql? pkg_name then
+ result.push(pkg.package_name)
+ end
+ end
+ end
+
+ return result
+ end
+
+ public
+ # get all build dependent packages (considered build priority, and reverse)
+ def get_build_dependent_packages(pkg_name, os, reverse)
+
+ if not check_remote_pkg(pkg_name, os) then return nil end
+ if reverse.nil? then reverse = true end
+
+ @all_dep_list.clear
+ begin
+ get_build_dependency_arr(pkg_name, os, 0)
+ # in case of cross build dependency
+ rescue SystemStackError
+ @log.error "Failed to get dependency relation because #{pkg_name} package has cross install dependency."
+ return nil
+ end
+
+ max = 0
+ @all_dep_list.each do |p|
+ if p[0].to_i > max then
+ max = p[0].to_i
+ else next end
+ end
+
+ result = []
+ i = 0
+ while i <= max
+ @all_dep_list.each do |p|
+ if p[0].to_i.eql? i then
+ d = p[1]
+ remote_os = get_attr_from_pkg(d.package_name, os, "os")
+ remote_ver = get_attr_from_pkg(d.package_name, os, "version")
+ if not d.target_os_list.include? remote_os then
+ @log.error "\"#{pkg_name}\" package needs \"#{d.package_name}\" #{d.target_os_list.to_s}, but \"#{d.package_name}\" (#{remote_os}) package is in server"
+ return nil
+ end
+ if not d.match? remote_ver then
+ @log.error "\"#{pkg_name}\" package needs \"#{d.package_name}\" #{d.comp} #{d.base_version}, but \"#{d.package_name}\" (#{remote_ver}) package is in server"
+ return nil
+ else result.push(d.package_name) end
+ end
+ end
+ i = i + 1
+ end
+
+ @log.info "Get build dependent packages for #{pkg_name} package.. OK"
+ if reverse then return result.reverse.uniq.push(pkg_name)
+ else return result.uniq.insert(0, pkg_name) end
+ end
+
+ public
+ # get all install dependent packages (considered install priority, reverse, and force)
+ # reverse : return reverse result
+ # force : install package force
+ def get_install_dependent_packages(pkg_name, os, reverse, force)
+
+ if not check_remote_pkg(pkg_name, os) then return nil end
+ if reverse.nil? then reverse = true end
+
+ @all_dep_list.clear
+ begin
+ get_install_dependency_arr(pkg_name, os, force, 0)
+ # in case of cross build dependency
+ rescue SystemStackError
+ @log.error "Failed to get dependency relation because #{pkg_name} package has cross install dependency."
+ return nil
+ end
+
+ max = 0
+ @all_dep_list.each do |p|
+ if p[0].to_i > max then
+ max = p[0].to_i
+ else next end
+ end
+
+ result = []
+ i = 0
+ while i <= max
+ @all_dep_list.each do |p|
+ if p[0].to_i.eql? i then
+ d = p[1]
+ remote_ver = get_attr_from_pkg(d.package_name, os, "version")
+ if not d.match? remote_ver then
+ @log.error "\"#{pkg_name}\" package needs \"#{d.package_name}\" #{d.comp} #{d.base_version}, but \"#{d.package_name}\" (#{remote_ver}) package is in server"
+ return nil
+ else result.push(d.package_name) end
+ end
+ end
+ i = i + 1
+ end
+
+ @log.info "Get install dependent packages for #{pkg_name} package.. OK"
+ if reverse then return result.reverse.uniq.push(pkg_name)
+ else return result.uniq.insert(0, pkg_name) end
+ end
+
+ public
+ # get all reverse install dependent packages (considered reverse install priority for tracing uninstall)
+ def get_all_reverse_install_dependent_packages(pkg_name, reverse)
+
+ if not check_installed_pkg(pkg_name) then return nil end
+ if reverse.nil? then reverse = true end
+
+ begin
+ res = get_all_reverse_install_dependency_arr(pkg_name, 0)
+ rescue SystemStackError
+ @log.error "Failed to get dependency relation because #{pkg_name} package has cross install dependency."
+ return nil
+ end
+ res2 = res.split("::")
+ result = []
+ res2.each do |r|
+ result.push(r.split(':')[1])
+ end
+
+ @log.info "Get all reverse install dependent packages for #{pkg_name} package.. OK"
+ if reverse then return result.reverse.uniq
+ else return result end
+ end
+
+ public
+ # get all reverse remote dependent packages (considered reverse install priority for tracing uninstall)
+ def get_all_reverse_install_dependent_packages_remote(pkg_name, os, reverse)
+ #if not check_remote_pkg(pkg_name, os) then return nil end
+ if reverse.nil? then reverse = true end
+
+ begin
+ res = get_all_reverse_install_dependency_arr_remote(pkg_name, os, 0)
+ rescue SystemStackError
+ @log.error "Failed to get dependency relation because #{pkg_name} package has cross install dependency."
+ return nil
+ end
+ res2 = res.split("::")
+ result = []
+ res2.each do |r|
+ result.push(r.split(':')[1])
+ end
+
+ @log.info "Get all reverse install dependent packages for #{pkg_name} package.. OK"
+ if reverse then return result.reverse
+ else return result end
+ end
+
+ public
+ # check package whether to exist in remote server
+ def check_remote_pkg(pkg_name, os)
+
+ pkg_hash = @pkg_hash_os[os]
+ if pkg_hash.nil? then return false end
+ pkg = pkg_hash[pkg_name]
+ if pkg.nil? then
+ @log.warn "There is no \"#{pkg_name}\" remote package information in list"
+ return false
+ end
+
+ return true
+ end
+
+ public
+ # check package whether to exist in installed packages
+ def check_installed_pkg(pkg_name)
+
+ installed_pkg_hash_key = get_installed_pkg_list_file_path()
+ pkg_hash = @installed_pkg_hash_loc[installed_pkg_hash_key]
+ if pkg_hash.nil? then return false end
+ pkg = pkg_hash[pkg_name]
+
+ if pkg.nil? then return false end
+ return true
+ end
+
+ public
+ # get attribute from installed package
+ def get_attr_from_installed_pkg(pkg_name, attr)
+
+ if not check_installed_pkg(pkg_name) then return nil end
+ pkg = get_installed_pkg_from_list(pkg_name)
+
+ if pkg.nil? then return nil end
+
+ case attr
+ when "version" then return pkg.version
+ when "source" then return pkg.source
+ when "src_path" then return pkg.src_path
+ when "os" then return pkg.os
+ when "build_dep_list" then return pkg.build_dep_list
+ when "install_dep_list" then return pkg.install_dep_list
+ when "attribute" then return pkg.attribute
+ end
+ end
+
+ public
+ # get attribute from remote package
+ def get_attr_from_pkg(pkg_name, os, attr)
+
+ if not check_remote_pkg(pkg_name, os) then return nil end
+ pkg = get_pkg_from_list(pkg_name, os)
+
+ if pkg.nil? then return nil end
+
+ case attr
+ when "path" then return pkg.path
+ when "source" then return pkg.source
+ when "version" then return pkg.version
+ when "src_path" then return pkg.src_path
+ when "os" then return pkg.os
+ when "build_dep_list" then return pkg.build_dep_list
+ when "install_dep_list" then return pkg.install_dep_list
+ when "attribute" then return pkg.attribute
+ end
+ end
+
+ public
+ # show a package information
+ def show_pkg_info(pkg_name, os)
+ if not check_remote_pkg(pkg_name, os) then
+ @log.error "\"#{pkg_name}\" package does not exist"
+ return ""
+ end
+
+ pkg = get_pkg_from_list(pkg_name, os)
+ return pkg.to_s
+ end
+
+ public
+ # show all packages information
+ def show_pkg_list(os)
+ pkg_hash = @pkg_hash_os[os]
+ if pkg_hash.nil? then
+ @log.error "\"#{os}\" package list does not exist"
+ return ""
+ end
+
+ pkg_all_list = []
+ pkg_list = pkg_hash.values
+ pkg_list.each do |p|
+ pkg_all_list.push([p.package_name, p.version, p.description])
+ end
+ return pkg_all_list.sort
+ end
+
+ public
+ # show installed package information
+ def show_installed_pkg_info(pkg_name)
+
+ if not check_installed_pkg(pkg_name) then
+ @log.error "\"#{pkg_name}\" package does not exist"
+ return ""
+ end
+
+ pkg = get_installed_pkg_from_list(pkg_name)
+ return pkg.to_s
+ end
+
+ public
+ # show all installed packages information
+ def show_installed_pkg_list()
+
+ file_path = get_installed_pkg_list_file_path()
+ pkg_hash = @installed_pkg_hash_loc[file_path]
+ if pkg_hash.nil? then
+ @log.error "Installed package list does not exist"
+ return nil
+ end
+ pkg_all_list = []
+ pkg_list = pkg_hash.values
+ pkg_list.each do |p|
+ pkg_all_list.push([p.package_name, p.version, p.description])
+ end
+ return pkg_all_list.sort
+ end
+
+ private
+ def get_build_dependency_arr(pkg_name, os, n)
+ pkg_hash = @pkg_hash_os[os]
+ pkg = pkg_hash[pkg_name]
+
+ if pkg.nil? then
+ @log.error "\"#{pkg_name}\" package does not exist in server. please check it"
+ return
+ end
+
+ # if package is already installed, skip tracing dependency
+ if check_installed_pkg(pkg_name) then
+ # compare version with installed package version
+ new_pkg_ver = get_attr_from_pkg(pkg_name, os, "version")
+ compare_result = compare_version_with_installed_pkg(pkg_name, new_pkg_ver)
+ if compare_result == -1 or compare_result == 0 then return end
+ end
+
+ pkg.build_dep_list.each do |l|
+ @all_dep_list.push([n, l])
+ get_build_dependency_arr(l.package_name, os, n+1)
+ end
+
+ return
+ end
+
+ private
+ def get_install_dependency_arr(pkg_name, os, force, n)
+
+ pkg_hash = @pkg_hash_os[os]
+ pkg = pkg_hash[pkg_name]
+
+ if pkg.nil? then
+ @log.error "\"#{pkg_name}\" package does not exist in server. please check it"
+ return
+ end
+
+ # if package is already installed, skip tracing dependency
+ if check_installed_pkg(pkg_name) then
+ # compare version with installed package version
+ new_pkg_ver = get_attr_from_pkg(pkg_name, os, "version")
+ compare_result = compare_version_with_installed_pkg(pkg_name, new_pkg_ver)
+ if not force then
+ if compare_result == -1 or compare_result == 0 then return end
+ end
+ end
+
+ pkg.install_dep_list.each do |l|
+ @all_dep_list.push([n, l])
+ get_install_dependency_arr(l.package_name, os, force, n+1)
+ end
+
+ return
+ end
+
+ private
+ def get_all_reverse_install_dependency_arr(pkg_name, n)
+
+ s = "#{n}:#{pkg_name}"
+ installed_pkg_hash_key = get_installed_pkg_list_file_path()
+ pkg_hash = @installed_pkg_hash_loc[installed_pkg_hash_key]
+ pkg_list = pkg_hash.values
+ pkg_list.each do |pkg|
+ pkg.install_dep_list.each do |l|
+ if l.package_name.eql? pkg_name then
+ s = s + "::" + get_all_reverse_install_dependency_arr(pkg.package_name, n+1)
+ end
+ end
+ end
+
+ return s
+ end
+
+ private
+ def get_all_reverse_install_dependency_arr_remote(pkg_name, os, n)
+
+ s = "#{n}:#{pkg_name}"
+ pkg_hash = @pkg_hash_os[os]
+ pkg_list = pkg_hash.values
+ pkg_list.each do |pkg|
+ pkg.install_dep_list.each do |l|
+ if l.package_name.eql? pkg_name then
+ s = s + "::" + get_all_reverse_install_dependency_arr_remote(pkg.package_name, os, n+1)
+ end
+ end
+ end
+
+ return s
+ end
+
+ public
+ def get_pkg_from_list(pkg_name, os)
+
+ pkg_hash = @pkg_hash_os[os]
+ if pkg_hash.nil? then return nil end
+
+ pkg = pkg_hash[pkg_name]
+
+ return pkg
+ end
+
+ private
+ def get_installed_pkg_from_list(pkg_name)
+
+ installed_pkg_hash_key = get_installed_pkg_list_file_path()
+ pkg_hash = @installed_pkg_hash_loc[installed_pkg_hash_key]
+ pkg = pkg_hash[pkg_name]
+ if pkg.nil? then return nil end
+
+ return pkg
+ end
+
+ private
+ # install a package to @location after uninstalling and downloading
+ def install_pkg(pkg_name, os, force)
+
+ new_pkg_ver = ""
+
+ # install remote server package file
+ if not check_remote_pkg(pkg_name, os) then
+ @log.error "\"#{pkg_name}\" package does not exist in remote server"
+ return false
+ end
+ path = get_attr_from_pkg(pkg_name, os, "path")
+ # type should be binary. type = "binary"
+ # below code should be changed
+ type = path.split('/')[-2]
+ new_pkg_ver = get_attr_from_pkg(pkg_name, os, "version")
+
+ # compare version with installed package versiona
+ compare_result = compare_version_with_installed_pkg(pkg_name, new_pkg_ver)
+ if not force then
+ case compare_result
+ when -1 then
+ @log.warn "\"#{pkg_name}\" package version is bigger then remote package version"
+ return true
+ when 0 then
+ @log.warn "\"#{pkg_name}\" package version is same with remote package version"
+ return true
+ end
+ end
+
+ # if package is already installed, then uninstall it
+ if check_installed_pkg(pkg_name) then
+ if not uninstall(pkg_name, false) then
+ @log.error "Failed to uninstall \"#{pkg_name}\""
+ return false
+ end
+ end
+
+ # download package file
+ # change download location temporary (back to the origin path after downloading)
+ loc_back = @location
+ uniq_name = Utils.create_uniq_name
+ tmppath = Utils::HOME + "/tmp/#{uniq_name}"
+ FileUtils.mkdir_p "#{tmppath}"
+ begin
+ @location = tmppath
+ _file_local_path = download(pkg_name, os, false)
+ if _file_local_path.nil? then
+ FileUtils.remove_dir(tmppath, true)
+ return false
+ end
+ file_local_path = _file_local_path[0]
+ @location = loc_back
+ if file_local_path.nil? then
+ FileUtils.remove_dir(tmppath, true)
+ return false
+ end
+
+ # install package
+ ret = FileInstaller.install(pkg_name, file_local_path, type, @location)
+ FileUtils.rm_f(file_local_path)
+ FileUtils.remove_dir(tmppath, true)
+ rescue Interrupt
+ @log.error "Client: Interrupted.."
+ FileUtils.rm_f(file_local_path)
+ FileUtils.remove_dir(tmppath, true)
+ @log.info "Removed #{file_local_path}"
+ @log.info "Removed #{tmppath}"
+ raise Interrupt
+ end
+ return ret
+ end
+
+ private
+ def compare_version_with_installed_pkg(pkg_name, new_pkg_ver)
+
+ if check_installed_pkg_list_file() then
+ create_installed_pkg_hash()
+ if check_installed_pkg(pkg_name) then
+ installed_pkg_ver = get_attr_from_installed_pkg(pkg_name, "version")
+ compare_result = Utils.compare_version(installed_pkg_ver, new_pkg_ver)
+ return compare_result
+ end
+ end
+
+ return 2
+ end
+
+ private
+ def remove_pkg_info(pkg_name)
+
+ pkg_hash = {}
+ installed_pkg_hash_key = get_installed_pkg_list_file_path()
+ if @installed_pkg_hash_loc.has_key? installed_pkg_hash_key then
+ pkg_hash = @installed_pkg_hash_loc[installed_pkg_hash_key]
+ if pkg_hash.include? pkg_name then
+ pkg_hash.delete(pkg_name)
+ end
+ @installed_pkg_hash_loc[installed_pkg_hash_key] = pkg_hash
+ else return nil end
+
+ @log.info "Removed information for \"#{pkg_name}\" package.. OK"
+ return pkg_hash
+ end
+
+ private
+ def add_pkg_info(pkg_name, os)
+
+ pkg_hash = {}
+ installed_pkg_hash_key = get_installed_pkg_list_file_path()
+ if @installed_pkg_hash_loc.has_key? installed_pkg_hash_key then
+ pkg_hash = @installed_pkg_hash_loc[installed_pkg_hash_key]
+ pkg_hash[pkg_name] = get_pkg_from_list(pkg_name, os)
+ else pkg_hash[pkg_name] = get_pkg_from_list(pkg_name, os) end
+ @installed_pkg_hash_loc[installed_pkg_hash_key] = pkg_hash
+
+ @log.info "Added information for \"#{pkg_name}\" package.. OK"
+ return pkg_hash
+ end
+
+ private
+ # add package manifest info
+ def add_local_pkg_info(pkg_name)
+
+ config_path = File.join(@location, PACKAGE_INFO_DIR, "#{pkg_name}")
+ pkg = read_pkginfo_file(pkg_name, config_path)
+
+ if pkg.nil? then
+ @log.error "Failed to read pkginfo.manifest file"
+ return nil
+ end
+
+ pkg_hash = {}
+ installed_pkg_hash_key = get_installed_pkg_list_file_path()
+ if @installed_pkg_hash_loc.has_key? installed_pkg_hash_key then
+ pkg_hash = @installed_pkg_hash_loc[installed_pkg_hash_key]
+ pkg_hash[pkg_name] = pkg
+ else pkg_hash[pkg_name] = pkg end
+ @installed_pkg_hash_loc[installed_pkg_hash_key] = pkg_hash
+
+ @log.info "Added information for \"#{pkg_name}\" package.. OK"
+ return pkg_hash
+ end
+
+ private
+ # read package manifet info
+ def read_pkginfo_file(pkg_name, path)
+
+ file_path = File.join(path, "pkginfo.manifest")
+ pkg = Parser.read_single_pkginfo_from file_path
+
+ if pkg.nil? then
+ @log.error "Failed to read manifest file : #{file_path}"
+ return nil
+ end
+
+ @log.info "Added information for \"#{pkg_name}\" package.. OK"
+ return pkg
+ end
+
+ private
+ # from_server : if true, update from server
+ def create_remote_pkg_hash(from_server)
+
+ for os in SUPPORTED_OS
+ filename = PKG_LIST_FILE_PREFIX + os
+ file_url = @server_addr + "/" + filename
+ local_file_path = File.join(CONFIG_PATH, filename)
+ if from_server then
+ if not FileDownLoader.download(file_url, CONFIG_PATH) then
+ return false
+ end
+ end
+ local_file_path = File.join(CONFIG_PATH, filename)
+ if File.exist? local_file_path then
+ pkg_hash = Parser.read_repo_pkg_list_from local_file_path
+ @pkg_hash_os[os] = pkg_hash
+ else
+ @pkg_hash_os[os] = {}
+ end
+ end
+
+ filename = "archive_pkg_list"
+ file_url = @server_addr + "/" + filename
+ if from_server then
+ if not FileDownLoader.download(file_url, CONFIG_PATH) then
+ @log.warn "Server does not have \"#{filename}\" file. This error can be ignored."
+ end
+ end
+ local_file_path = File.join(CONFIG_PATH, filename)
+ if File.exist? local_file_path then
+ File.open(local_file_path, "r") do |f|
+ f.each_line do |l|
+ @archive_pkg_list.push(l.strip)
+ end
+ end
+ end
+
+ return true
+ end
+
+ private
+ # create installed package hash
+ def create_installed_pkg_hash()
+
+ config_path = File.join(@location, PACKAGE_INFO_DIR)
+ if not File.directory? config_path then return end
+
+ installed_pkg_hash_key = get_installed_pkg_list_file_path()
+ if @installed_pkg_hash_loc.has_key? installed_pkg_hash_key then return
+ else
+ file_path = installed_pkg_hash_key
+ if not File.exist? file_path then
+ #raise RuntimeError, "#{file_path} file does not exist"
+ return
+ end
+ pkg_hash = Parser.read_repo_pkg_list_from file_path
+ @installed_pkg_hash_loc[installed_pkg_hash_key] = pkg_hash
+ end
+ end
+
+ private
+ # check to exist installed package list file
+ def check_installed_pkg_list_file()
+
+ if @location.nil? then raise RuntimeError, "#{@location} path does not exist" end
+ file_path = get_installed_pkg_list_file_path()
+ if File.exist? file_path then return true
+ else return false end
+ end
+
+ private
+ # get installed package list file path
+ def get_installed_pkg_list_file_path()
+
+ file_full_path = File.join(@location, PACKAGE_INFO_DIR, INSTALLED_PKG_LIST_FILE)
+ return file_full_path
+ end
+
+ private
+ # write package hash to file
+ def write_pkg_hash_to_file(pkg_hash)
+
+ file_path = get_installed_pkg_list_file_path()
+ if pkg_hash.nil? then
+ pkg_hash = @installed_pkg_hash_loc[file_path]
+ end
+ if not pkg_hash.nil? then
+ config_path = File.join(@location, PACKAGE_INFO_DIR)
+ if not File.exist? config_path then FileUtils.mkdir_p "#{config_path}" end
+ if File.exist? file_path then File.delete(file_path) end
+ File.open(file_path, "a+") do |file|
+ file.puts "ORIGIN : #{@server_addr}"
+ file.puts "\n"
+ pkg_list = pkg_hash.values
+ pkg_list.each do |pkg|
+ pkg.print_to_file(file)
+ file.puts "\n"
+ end
+ end
+ end
+ @log.info "Write package informations to \"#{file_path}\".. OK"
+ end
+
+ private
+ def check_meta_pkg(pkg_name, os)
+ if not check_remote_pkg(pkg_name, os) then return false end
+
+ attr = get_attr_from_pkg(pkg_name, os, "attribute")
+ if attr.nil? or attr.empty? then return false end
+ if attr[0].strip.upcase.eql? "META" then return true
+ else return false end
+ end
+end
--- /dev/null
+=begin
+
+ clientOptParser.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require 'optparse'
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+require "utils"
+
+def set_default( options )
+ if options[:t].nil? then options[:t] = false end
+ if options[:f].nil? then options[:f] = false end
+ if options[:v].nil? then options[:v] = false end
+end
+
+def option_error_check( options )
+
+ case options[:cmd]
+
+ when "update" then
+
+ when "clean" then
+
+ when "upgrade" then
+
+ when "check-upgrade" then
+
+ when "download" then
+ if options[:pkg].nil? or options[:pkg].empty? then
+ raise ArgumentError, "Usage: pkg-cli download -P <package name> [-o <os>] [-l <location>] [-u <package server url>] [--trace]"
+ end
+
+ when "install" then
+ if options[:pkg].nil? or options[:pkg].empty? then
+ raise ArgumentError, "Usage: pkg-cli install -P <package name> [-o <os>] [-l <location>] [-u <package server url>] [--trace] [--force]"
+ end
+
+ when "install-file" then
+ if options[:pkg].nil? or options[:pkg].empty? then
+ raise ArgumentError, "Usage: pkg-cli install-lpkg -P <package file> [-l <location>] [--force]"
+ end
+
+ when "uninstall" then
+ if options[:pkg].nil? or options[:pkg].empty? then
+ raise ArgumentError, "Usage: pkg-cli uninstall -P <package name> [-l <location>] [--trace]"
+ end
+
+ when "show-rpkg" then
+ if options[:pkg].nil? or options[:pkg].empty? then
+ raise ArgumentError, "Usage: pkg-cli show-rpkg -P <package name> [-o <os>] [-u <package server url>]"
+ end
+
+ when "list-rpkg" then
+
+ when "show-lpkg" then
+ if options[:pkg].nil? or options[:pkg].empty? then
+ raise ArgumentError, "Usage: pkg-cli show-lpkg -P <package name> [-l <location>]"
+ end
+
+ when "list-lpkg" then
+
+ when "build-dep" then
+ if options[:pkg].nil? or options[:pkg].empty? then
+ raise ArgumentError, "Usage: pkg-cli build-dep -P <package name> [-o <os>]"
+ end
+
+ when "install-dep" then
+ if options[:pkg].nil? or options[:pkg].empty? then
+ raise ArgumentError, "Usage: pkg-cli install-dep -P <package name> [-o <os>]"
+ end
+
+ else
+ raise ArgumentError, "Input is incorrect : #{options[:cmd]}"
+ end
+end
+
+def option_parse
+ options = {}
+ banner = "Requiest service to package-server and control packages service command-line tool." + "\n" \
+ + "\n" + "Usage: pkg-cli <SUBCOMMAND> [OPTS] or pkg-cli -h" + "\n" \
+ + "\n" + "Subcommands:" + "\n" \
+ + "\t" + "update Update to the latest package in your SDK environment." + "\n" \
+ + "\t" + "clean Delete the package in your SDK environment." + "\n" \
+ + "\t" + "download Download the package in your SDK environment." + "\n" \
+ + "\t" + "install Download the package from package-server and install the package in your SDK environment." + "\n" \
+ + "\t" + "install-file Install the package in your SDK environment." + "\n" \
+ + "\t" + "uninstall Uninstall the package in your SDK environment." + "\n" \
+ + "\t" + "upgrade Upgrade your SDK environment." + "\n" \
+ + "\t" + "check-upgrade Check packages to upgrade." + "\n" \
+ + "\t" + "show-rpkg Show the package in the package-server." + "\n" \
+ + "\t" + "list-rpkg Show the all packages in the package-server." + "\n" \
+ + "\t" + "show-lpkg Show the package in your SDK environment." + "\n" \
+ + "\t" + "list-lpkg Show the all packages in your SDK environment." + "\n" \
+ + "\n" + "Subcommand usage:" + "\n" \
+ + "\t" + "pkg-cli update [-u <remote server url>]" + "\n" \
+ + "\t" + "pkg-cli clean [-l <location>] [--force]" + "\n" \
+ + "\t" + "pkg-cli download -P <package name> [-o <os>] [-l <location>] [-u <package server url>] [--trace]" + "\n" \
+ + "\t" + "pkg-cli install -P <package name> [-o <os>] [-l <location>] [-u <package server url>] [--trace] [--force]" + "\n" \
+ + "\t" + "pkg-cli install-file -P <package file> [-l <location>] [--force]" + "\n" \
+ + "\t" + "pkg-cli uninstall -P <package name> [-l <location>] [--trace]" + "\n" \
+ + "\t" + "pkg-cli upgrade [-l <location>] [-o <os>] [-u <package server url>] [--trace]" + "\n" \
+ + "\t" + "pkg-cli check-upgrade [-l <location>] [-o <os>] [-u <package server url>]" + "\n" \
+ + "\t" + "pkg-cli show-rpkg -P <package name> [-o <os>] [-u <package server url>]" + "\n" \
+ + "\t" + "pkg-cli list-rpkg [-o <os>] [-u <package server url>]" + "\n" \
+ + "\t" + "pkg-cli show-lpkg -P <package name> [-l <location>]" + "\n" \
+ + "\t" + "pkg-cli list-lpkg [-l <location>]" + "\n" \
+ + "\n" + "Options:" + "\n"
+
+ optparse = OptionParser.new(nil, 32, ' '*8) do|opts|
+ # Set a banner, displayed at the top
+ # of the help screen.
+
+ opts.banner = banner
+
+ opts.on( '-P', '--pkg <package name/file>', 'package name or package file name' ) do |name|
+ options[:pkg] = name
+ end
+
+ opts.on( '-o', '--os <operating system>', 'target operating system: linux/windows/darwin' ) do |os|
+ options[:os] = os
+ end
+
+ opts.on( '-u', '--url <server url>', 'package server url: http://127.0.0.1/dibs/unstable' ) do |url|
+ options[:url] = url
+ end
+
+ opts.on( '-l', '--loc <location>', 'install/download location' ) do |loc|
+ options[:loc] = loc
+ end
+
+ opts.on( '--trace', 'enable trace dependent packages' ) do
+ options[:t] = true
+ end
+
+ opts.on( '--force', 'enable force' ) do
+ options[:f] = true
+ end
+
+ opts.on( '-h', '--help', 'display manual' ) do
+ puts opts
+ exit
+ end
+
+ opts.on( '-v', '--version', 'display version' ) do
+ puts "DIBS(Distributed Intelligent Build System) version 1.2.0"
+ exit
+ end
+ end
+
+ cmd = ARGV[0]
+ if cmd.eql? "update" or cmd.eql? "download" or
+ cmd.eql? "install" or cmd.eql? "show-rpkg" or
+ cmd.eql? "list-rpkg" or
+ cmd.eql? "uninstall" or cmd.eql? "show-lpkg" or
+ cmd.eql? "list-lpkg" or
+ cmd.eql? "install-file" or cmd.eql? "clean" or
+ cmd.eql? "upgrade" or cmd.eql? "check-upgrade" or
+ cmd.eql? "build-dep" or cmd.eql? "install-dep" or
+ cmd =~ /(-v)|(--version)/ or
+ cmd =~ /(help)|(-h)|(--help)/ then
+
+ if cmd.eql? "help" then
+ V[0] = "-h"
+ end
+ options[:cmd] = ARGV[0]
+ else
+ raise ArgumentError, "Usage: pkg-cli <SUBCOMMAND> [OPTS] or pkg-cli -h"
+ end
+
+ optparse.parse!
+
+ set_default options
+
+ # option error check
+ option_error_check options
+
+ return options
+end
+
--- /dev/null
+=begin
+
+ distribution.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require 'fileutils'
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+require "parser"
+require "installer"
+
+class Distribution
+ attr_accessor :name, :location, :server_url, :lock_file_name
+
+ # constant
+ SUPPORTED_OS = ["linux", "windows", "darwin"]
+ PKG_LIST_FILE_PREFIX = "pkg_list_"
+ ARCHIVE_PKG_FILE = "archive_pkg_list"
+
+ def initialize( name, location, server_url, pkg_server )
+
+ @name = name
+ @location = location
+ @server_url = server_url
+ @log = pkg_server.log
+ @integrity = pkg_server.integrity
+ @lock_file_name = "#{location}/.lock_file"
+ @snapshot_info_file = "#{location}/snapshot.info"
+ @pkg_hash_os = {}
+ @archive_pkg_list = []
+ @snapshot_hash = []
+
+ @log.info "Distribution class[#{name}] initialize "
+
+ initialize_pkg_list()
+ end
+
+ def register (file_path, pkg)
+ if pkg.nil? then
+ raise RuntimeError, "package file does not contain pkginfo.manifest: [#{file_path}]"
+ end
+
+ exist_pkg = @pkg_hash_os[pkg.os][pkg.package_name]
+
+ # version check and if existing version is higher then upload version?
+ if not exist_pkg.nil?
+ if not ( Utils.compare_version( exist_pkg.version, pkg.version ).eql? 1 ) then
+ raise RuntimeError, "existing package's version is higher than register package : [#{pkg.package_name}] in [#{pkg.os}]"
+ end
+ end
+
+ # modified pkg class
+ pkg.origin = "local"
+ pkg.source = ""
+ pkg.path = "/binary/" + File.basename( file_path )
+ # TODO: windows and mac : sha256sum
+ if Utils::HOST_OS.eql? "linux" then
+ pkg.checksum = `sha256sum #{file_path}`.split(" ")[0]
+ end
+ pkg.size = `du -b #{file_path}`.split[0].strip
+
+ @pkg_hash_os[pkg.os][pkg.package_name] = pkg
+
+ return pkg
+ end
+
+ def register_for_test (file_path, pkg)
+ if pkg.nil? then
+ raise RuntimeError, "package file does not contain pkginfo.manifest: [#{file_path}]"
+ end
+
+ # modified pkg class
+ pkg.origin = "local"
+ pkg.source = ""
+ pkg.path = "/temp/" + File.basename( file_path )
+ # TODO: windows and mac : sha256sum
+ if Utils::HOST_OS.eql? "linux" then
+ pkg.checksum = `sha256sum #{file_path}`.split(" ")[0]
+ end
+ pkg.size = `du -b #{file_path}`.split[0].strip
+
+ return pkg
+ end
+
+ def register_archive_pkg( archive_pkg )
+ if not @archive_pkg_list.include? archive_pkg then
+ @archive_pkg_list.push archive_pkg
+ else
+ @log.error("archive package already exist : [#{archive_pkg}]", Log::LV_USER)
+ end
+ end
+
+ def generate_snapshot(name, base_snapshot, from_cmd)
+ # if name is nil or empty then create uniq name
+ if name.nil? or name.empty? then
+ name = Utils.create_uniq_name
+ end
+
+ # check base snapshot exist
+ if File.exist? "#{@location}/snapshots/#{name}" then
+ raise "Snapshot is already exist: #{name}"
+ end
+
+ FileUtils.mkdir "#{@location}/snapshots/#{name}"
+
+ # base_snapshot_path
+ if base_snapshot.empty? then
+ snapshot_path = @location
+ else
+ snapshot_path = "#{@location}/snapshots/#{base_snapshot.strip}"
+ end
+
+ # copy package list
+ for os in SUPPORTED_OS
+ FileUtils.copy( "#{snapshot_path}/#{PKG_LIST_FILE_PREFIX}#{os}", \
+ "#{@location}/snapshots/#{name}/#{PKG_LIST_FILE_PREFIX}#{os}" )
+ end
+
+ # copy archive package list
+ FileUtils.copy( "#{snapshot_path}/#{ARCHIVE_PKG_FILE}", \
+ "#{@location}/snapshots/#{name}/#{ARCHIVE_PKG_FILE}" )
+
+ File.open(@snapshot_info_file, "a") do |f|
+ f.puts "name : #{name}"
+ f.puts "time : #{Time.now.strftime("%Y%m%d%H%M%S")}"
+ if from_cmd then
+ f.puts "type : manual"
+ else
+ f.puts "type : auto"
+ end
+ f.puts "path : /snapshots/#{name}"
+ f.puts
+ end
+
+ @log.output( "snapshot is generated : #{@location}/snapshots/#{name}", Log::LV_USER)
+ return name
+ end
+
+ def sync( force, os )
+ # check distribution's server_url
+ if @server_url.empty? then
+ @log.error("This distribution has not remote server", Log::LV_USER)
+ return
+ end
+
+ # generate client class
+ client = Client.new( @server_url, "#{@location}/binary", @log )
+ client.update
+
+ # error check
+ if client.pkg_hash_os[os].nil? then
+ raise "Package list can't generated. url is #{@server_url}. os is #{os}"
+ end
+
+ server_pkg_name_list = client.pkg_hash_os[os].keys
+ local_pkg_name_list = @pkg_hash_os[os].keys
+ full_pkg_name_list = server_pkg_name_list + local_pkg_name_list
+
+ full_pkg_name_list.each do |pkg_name|
+ sync_package( pkg_name, client, os, force )
+ end
+
+ write_pkg_list(os)
+ end
+
+ def sync_archive_pkg
+ client = Client.new( @server_url, "#{@location}/source", @log )
+ client.update
+
+ download_list = client.archive_pkg_list - @archive_pkg_list
+ download_list.each do |pkg|
+ file = client.download_dep_source(pkg)
+ if file.nil?
+ @log.error("Can't download archive package [#{pkg}]", Log::LV_USER)
+ else
+ @archive_pkg_list.push pkg
+ end
+ end
+
+ write_archive_pkg_list()
+ end
+
+ def clean( snapshot_list )
+ file_list = []
+ used_archive_list = []
+
+ # collect remaining file's name from current package server version
+ for os in SUPPORTED_OS
+ @pkg_hash_os[os].each_value{ |pkg|
+ file_list.push(pkg.path.sub("/binary/",""))
+
+ pkg.source_dep_list.each do |source_dep|
+ if @archive_pkg_list.include? source_dep.package_name then
+ used_archive_list.push source_dep.package_name
+ else
+ @log.error("Can't find dependency source package : #{source_dep.package_name}")
+ end
+ end
+ }
+ end
+
+ # remain only used archive package
+ @archive_pkg_list = used_archive_list.uniq
+ write_archive_pkg_list
+
+ # collect remaning file's name from snapshot list
+ for snapshot in snapshot_list
+ for os in SUPPORTED_OS
+ pkg_list = Parser.read_repo_pkg_list_from "#{@location}/snapshots/#{snapshot}/#{PKG_LIST_FILE_PREFIX}#{os}"
+
+ pkg_list.each_value{ |pkg|
+ file_list.push(pkg.path.sub("/binary/",""))
+ }
+ end
+
+ used_archive_list = used_archive_list + read_archive_pkg_list( snapshot )
+ end
+
+ file_list.uniq!
+ used_archive_list.uniq!
+
+ # remove unused binary file
+ Dir.new( @location + "/binary" ).each do |file|
+ if file.start_with? "." then next end
+
+ if not file_list.include? file then
+ FileUtils.rm "#{@location}/binary/#{file}"
+ end
+ end
+
+ # remove unused archive file
+ Dir.new( @location + "/source" ).each do |file|
+ if file.start_with? "." then next end
+
+ if not used_archive_list.include? file then
+ FileUtils.rm "#{@location}/source/#{file}"
+ end
+ end
+
+ # remove unused snapshot
+ Dir.new( @location + "/snapshots" ).each do |snapshot|
+ if snapshot.start_with? "." then next end
+
+ if not snapshot_list.include? snapshot then
+ FileUtils.rm_rf "#{@location}/snapshots/#{snapshot}"
+ end
+ end
+ clean_snapshot_info_file(snapshot_list)
+ end
+
+ def write_pkg_list( os )
+
+ File.open( "#{@location}/#{PKG_LIST_FILE_PREFIX}#{os}", "w" ) do |f|
+ @pkg_hash_os[os].each_value do |pkg|
+ # insert package information to file
+ pkg.print_to_file(f)
+ # insert empty line to file
+ f.puts
+ end
+ end
+ end
+
+ # input: package file path(zip file)
+ # return: pkg
+ def get_package_from_file(file_path)
+ tmp_dir = @location + "/" + Utils.create_uniq_name
+
+ FileInstaller.set_logger(@log)
+
+ #if file extension is .zip then check pkginfo.manifest
+ if File.extname(file_path).eql? ".zip" then
+ FileUtils.mkdir tmp_dir
+
+ ret = FileInstaller.extract_a_file(file_path, "pkginfo.manifest", tmp_dir)
+ else
+ return nil
+ end
+
+ # if pkginfo.manifest file exist
+ if not ret.nil? then
+ pkg = Parser.read_single_pkginfo_from "#{tmp_dir}/pkginfo.manifest"
+
+ FileUtils.rm_rf tmp_dir
+ return pkg
+ # if pkginfo.manifest file does not exist
+ else
+ FileUtils.rm_rf tmp_dir
+ return nil
+ end
+ end
+
+ def remove_pkg( pkg_name_list, os, recursive )
+ if os.eql? "all" then os_list = SUPPORTED_OS
+ else os_list = [ os ]
+ end
+
+ for package_name in pkg_name_list
+ removed_flag = false
+
+ for os in os_list
+ if @pkg_hash_os[os].key?(package_name) then
+ @log.info( "remove package [#{package_name}] in #{os}", Log::LV_USER)
+ @pkg_hash_os[os].delete(package_name)
+ removed_flag = true
+ end
+ end
+
+ if not removed_flag then
+ if @archive_pkg_list.include? package_name then
+ @archive_pkg_list.delete package_name
+ else
+ @log.error( "Can't find package: [#{package_name}]", Log::LV_USER)
+ end
+ end
+ end
+
+ # check install dependency integrity
+ if @integrity.eql? "YES" then
+ @log.info "integrity check"
+ check_integrity
+ else
+ @log.info "skip integrity check"
+ end
+
+
+ # update pkg_list file
+ for os in SUPPORTED_OS
+ write_pkg_list(os)
+ end
+ write_archive_pkg_list
+ end
+
+ def remove_snapshot( snapshot_list )
+ remain_snapshot = []
+ removed_snapshot = []
+
+ # remove unused snapshot
+ Dir.new( @location + "/snapshots" ).each do |snapshot|
+ if snapshot.start_with? "." then next end
+
+ if snapshot_list.include? snapshot then
+ FileUtils.rm_rf "#{@location}/snapshots/#{snapshot}"
+ snapshot_list.delete snapshot
+ removed_snapshot.push snapshot
+ else
+ remain_snapshot.push snapshot
+ end
+ end
+
+ if not snapshot_list.empty? then
+ @log.output( "snapshot not exist : #{snapshot_list.join(",")}", Log::LV_USER )
+ end
+
+ if not removed_snapshot.empty? then
+ @log.output( "snapshot removed: #{removed_snapshot.join(",")}", Log::LV_USER )
+ end
+
+ clean_snapshot_info_file(remain_snapshot)
+ end
+
+ def check_integrity
+ @log.info "check server pkg's install dependency integrity"
+
+ for os in SUPPORTED_OS
+ for pkg in @pkg_hash_os[os].each_value
+ check_package_integrity(pkg)
+ end
+ end
+ end
+
+ def check_package_integrity(pkg)
+ error_msg = "[#{pkg.package_name}]'s install dependency not matched in "
+ os = pkg.os
+
+ for dep in pkg.install_dep_list
+ if @pkg_hash_os[os].has_key? dep.package_name then
+ target_pkg = @pkg_hash_os[os][dep.package_name]
+ else
+ raise RuntimeError,(error_msg + dep.to_s)
+ end
+
+ # check package's version
+ if not dep.match? target_pkg.version then
+ raise RuntimeError,(error_msg + dep.to_s)
+ end
+
+ end
+
+ error_msg = "[#{pkg.package_name}]'s build dependency not matched in "
+ for dep in pkg.build_dep_list
+ if dep.target_os_list.length == 0 then
+ build_dep_os = os
+ else
+ build_dep_os = dep.target_os_list[0]
+ end
+
+ if @pkg_hash_os[build_dep_os].has_key? dep.package_name then
+ target_pkg = @pkg_hash_os[build_dep_os][dep.package_name]
+ else
+ raise RuntimeError,(error_msg + dep.to_s)
+ end
+
+ # check package's version
+ if not dep.match? target_pkg.version then
+ raise RuntimeError,(error_msg + dep.to_s)
+ end
+ end
+
+ error_msg = "[#{pkg.package_name}]'s source dependency not matched in "
+ for dep in pkg.source_dep_list
+ if not @archive_pkg_list.include? dep.package_name then
+ raise RuntimeError,(error_msg + dep.to_s)
+ end
+ end
+ end
+
+ def read_archive_pkg_list( snapshot_name )
+ pkg_list = []
+
+ if snapshot_name.empty?
+ file_name = @location + "/" + ARCHIVE_PKG_FILE
+ else
+ file_name = @location + "/snapshots/" + snapshot_name + "/" + ARCHIVE_PKG_FILE
+ end
+
+ if File.exist? file_name
+ File.open(file_name, "r") do |f|
+ f.each_line do |l|
+ pkg_list.push(l.strip)
+ end
+ end
+ end
+
+ return pkg_list
+ end
+
+ def write_archive_pkg_list()
+ File.open( "#{@location}/#{ARCHIVE_PKG_FILE}", "w" ) do |f|
+ @archive_pkg_list.each do |pkg|
+ f.puts(pkg)
+ end
+ end
+ end
+
+ def initialize_pkg_list
+ # read package_list file
+ for os in SUPPORTED_OS
+ @pkg_hash_os[os] = {}
+ pkg_list_file = "#{@location}/#{PKG_LIST_FILE_PREFIX}#{os}"
+
+ if File.exist? pkg_list_file then
+ @pkg_hash_os[os] = Parser.read_repo_pkg_list_from( pkg_list_file )
+ end
+ end
+
+ # read archive package_list file
+ @archive_pkg_list = read_archive_pkg_list("")
+ end
+
+ # PRIVATE METHODS/VARIABLES
+ private
+
+ def sync_package( pkg_name, client, os, force )
+ server_pkg = client.pkg_hash_os[os][pkg_name]
+ local_pkg = @pkg_hash_os[os][pkg_name]
+
+ # if server and local has package
+ if ( not server_pkg.nil? ) and ( not local_pkg.nil? ) then
+ version_cmp = Utils.compare_version( local_pkg.version, server_pkg.version )
+ if ( version_cmp.eql? 0 ) then
+ # version is same then skip update
+ return
+ end
+ if ( local_pkg.origin.eql? "local" ) then
+ if not force then
+ # local_pkg is generated from local and not force mode then skip update
+ return
+ end
+ end
+
+ sync_package2( server_pkg, client, os, force )
+ # if package exist only server
+ elsif ( not server_pkg.nil? ) then
+ sync_package2( server_pkg, client, os, force )
+ # if package exist only local
+ elsif ( not local_pkg.nil? ) then
+ # if local pkg is generated from local then skip
+ if local_pkg.origin.eql? "local" then
+ next
+ end
+
+ # package remove
+ @pkg_hash_os[os].delete(pkg_name)
+ else
+ raise RuntimeError,"hash merge error!"
+ end
+ end
+
+ def sync_package2( pkg, client, os, force )
+ pkg_name = pkg.package_name
+
+ # package update
+ file_path_list = client.download( pkg_name, os, false )
+
+ # file download error check
+ if file_path_list.nil? or file_path_list.empty? then
+ @log.error("Can't download package file [#{pkg_name}]", Log::LV_USER)
+ return
+ else
+ file_path = file_path_list[0]
+ end
+
+ # update pkg class
+ pkg.path = "/binary/#{File.basename(file_path)}"
+ pkg.origin = client.server_addr
+ @pkg_hash_os[os][pkg_name] = pkg
+
+ end
+
+ def clean_snapshot_info_file(snapshot_list)
+ if not File.exist?(@snapshot_info_file)
+ @log.error "Can not find snapshot info file"
+ return
+ end
+
+ # modify snapshot info File
+ f = File.open(@snapshot_info_file, "r")
+ info_lines = []
+ save_flag = false
+ f.each_line do |l|
+ if l.start_with? "name :" then
+ if snapshot_list.include? l.split(":")[1].strip then
+ save_flag = true
+ else
+ save_flag = false
+ end
+ end
+
+ if save_flag then
+ info_lines.push l
+ end
+ end
+ f.close
+
+ f = File.open(@snapshot_info_file, "w")
+ info_lines.each do |i|
+ f.puts i
+ end
+ f.close
+ end
+
+ def get_all_reverse_depends_pkgs(pkg, checked_list)
+ depends_list = []
+
+ for os in SUPPORTED_OS
+ @pkg_hash_os[os].each_value{ |dpkg|
+ if dpkg.install_dep_list.include? pkg or \
+ dpkg.build_dep_list.include? pkg then
+ depends_list.push opkg
+ end
+
+ }
+ end
+
+ depends_list.each do |dpkg|
+ checked_list.push dpkg
+ rdepends_list = get_all_reverse_depends_pkgs( dpkg, checked_list )
+ end
+
+ return rdepends_list
+ end
+end
--- /dev/null
+=begin
+
+ downloader.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+require "utils"
+
+class FileDownLoader
+
+ @@log = nil
+
+ def FileDownLoader.set_logger(logger)
+ @@log = logger
+ end
+
+ def FileDownLoader.download(url, path)
+ ret = false
+
+ if not File.directory? path then
+ @@log.error "\"#{path}\" does not exist"
+ return ret
+ end
+
+ is_remote = Utils.is_url_remote(url)
+ filename = url.split('/')[-1]
+
+ fullpath = File.join(path, filename)
+
+ if is_remote then
+ ret = Utils.execute_shell_with_log( "wget #{url} -O #{fullpath} -nv", @@log )
+ else
+ if not File.exist? url then
+ @@log.error "\"#{url}\" file does not exist"
+ return false
+ else
+ ret = system "cp #{url} #{fullpath}"
+ end
+ end
+
+ # need verify
+ return ret
+ end
+end
+
--- /dev/null
+=begin
+
+ installer.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+$LOAD_PATH.unshift File.dirname(__FILE__)
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+require "packageServerConfig"
+require "log"
+require "utils"
+if Utils::HOST_OS.eql? "windows" then
+ require "rubygems"
+ require "zip/zip"
+end
+
+class FileInstaller
+
+ CONFIG_PATH = "#{PackageServerConfig::CONFIG_ROOT}/client"
+ PACKAGE_INFO_DIR = ".info"
+
+ @@log = nil
+
+ def FileInstaller.set_logger(logger)
+ @@log = logger
+ end
+
+ def FileInstaller.install(package_name, package_file_path, type, target_path)
+
+ if not File.exist? package_file_path then
+ @@log.error "\"#{package_file_path}\" file does not exist."
+ return false
+ end
+
+ case type
+ # install script when binary package
+ when "binary" then
+ uniq_name = Utils.create_uniq_name
+ path = Utils::HOME + "/tmp/#{uniq_name}"
+ # windows has limitation for file path length
+ if Utils::HOST_OS.eql? "windows" then
+ drive = Utils::HOME.split("/")[0]
+ path = "#{drive}/#{uniq_name}"
+ end
+ if not File.exist? path then FileUtils.mkdir_p "#{path}" end
+
+ if File.directory? path then
+ log = "##### create temporary dir : #{path} #####\n"
+ else
+ log = "##### [Failed] create temporary dir : #{path} #####\n"
+ return false
+ end
+
+ begin
+ log = log + "##### extract file : #{package_file_path} #####\n"
+ log = log + extract_file(package_name, package_file_path, path, target_path)
+ move_dir(package_name, path, target_path)
+
+ log = log + "##### execute install script #####\n"
+ log = log + execute_install_script(package_name, path, target_path)
+
+ log = log + "##### move remove script #####\n"
+ move_remove_script(package_name, path, target_path)
+
+ log = log + "##### remove temporary dir : #{path} #####\n"
+ Utils.execute_shell("rm -rf #{path}")
+ rescue Interrupt
+ @@log.error "FileInstaller: Interrupted.."
+ Utils.execute_shell("rm -rf #{path}")
+ @@log.info "Removed #{path}"
+ raise Interrupt
+ end
+
+ target_config_path = target_path + "/#{PACKAGE_INFO_DIR}/#{package_name}"
+ if not File.exist? target_config_path then FileUtils.mkdir_p(target_config_path) end
+ pkg_inst_log = "#{package_name}_inst.log"
+ pkg_inst_log_path = File.join(target_config_path, pkg_inst_log)
+
+ File.open(pkg_inst_log_path, "a+") do |f|
+ f.puts log
+ end
+
+ when "source" then
+ end
+
+ # need verify
+ return true;
+ end
+
+ def FileInstaller.move_remove_script(package_name, path, target_path)
+ target_path = target_path + "/#{PACKAGE_INFO_DIR}/#{package_name}"
+ if not File.exist? target_path then FileUtils.mkdir_p(target_path) end
+ script_file_prefix = "#{path}/remove.*"
+ script_file = Dir.glob(script_file_prefix)[0]
+
+ if not script_file.nil? then
+ FileUtils.mv(script_file, target_path)
+ end
+ end
+
+
+ def FileInstaller.execute_install_script(package_name, path, target_path)
+ script_file_prefix = "#{path}/install.*"
+ script_file = Dir.glob(script_file_prefix)[0]
+ log = ""
+
+ if not script_file.nil? then
+ @@log.info "Execute \"#{script_file}\" file"
+ if Utils::HOST_OS.eql? "windows" then
+ cmd = "set INSTALLED_PATH=\"#{target_path}\"& #{script_file}"
+ else
+ cmd = "INSTALLED_PATH=\"#{target_path}\" #{script_file}"
+ end
+ log = `#{cmd}`
+ end
+ return log
+ end
+
+ def FileInstaller.execute_remove_script(package_name, target_path)
+ info_path = target_path + "/#{PACKAGE_INFO_DIR}/#{package_name}"
+ if not File.directory? info_path then
+ return false
+ end
+
+ script_file_prefix = "#{info_path}/remove.*"
+ script_file = Dir.glob(script_file_prefix)[0]
+ log = ""
+
+ if not script_file.nil? then
+ @@log.info "Execute \"#{script_file}\" file"
+ if Utils::HOST_OS.eql? "windows" then
+ cmd = "set INSTALLED_PATH=\"#{target_path}\"& #{script_file}"
+ else
+ cmd = "INSTALLED_PATH=\"#{target_path}\" #{script_file}"
+ end
+ log = `#{cmd}`
+ end
+ end
+
+ def FileInstaller.remove_pkg_files(package_name, target_path)
+ list_path = target_path + "/#{PACKAGE_INFO_DIR}/#{package_name}"
+
+ if not File.directory? list_path then
+ return false
+ end
+
+ list_file_name = "#{list_path}/#{package_name}.list"
+ list_file = Dir.glob(list_file_name)[0]
+ directories = []
+
+ if not list_file.nil? then
+ File.open(list_file, "r") do |file|
+ file.each_line do |f|
+ f = f.strip
+ if f.nil? or f.empty? then next end
+ file_path = File.join(target_path, f)
+ if File.directory? file_path then
+ if File.symlink? file_path then
+ File.unlink file_path
+ next
+ end
+ entries = Dir.entries(file_path)
+ if entries.include? "." then entries.delete(".") end
+ if entries.include? ".." then entries.delete("..") end
+ if entries.empty? or entries.nil? then
+ begin
+ Dir.rmdir(file_path)
+ rescue SystemCallError
+ @@log.warn "\"#{file_path}\" directory is not empty"
+ end
+ else directories.push(file_path) end
+ elsif File.file? file_path then FileUtils.rm_f(file_path)
+ elsif File.symlink? file_path then File.unlink file_path
+ # if files are already removed by remove script,
+ else @@log.warn "\"#{file_path}\" does not exist" end
+ end
+ end
+
+ directories.reverse.each do |path|
+ entries = Dir.entries(path)
+ if entries.include? "." then entries.delete(".") end
+ if entries.include? ".." then entries.delete("..") end
+ if entries.empty? or entries.nil? then
+ begin
+ Dir.rmdir(path)
+ rescue SystemCallError
+ @@log.warn "\"#{file_path}\" directory is not empty"
+ end
+ else next end
+ end
+ end
+ Utils.execute_shell("rm -rf #{list_path}")
+ return true
+ end
+
+ def FileInstaller.uninstall(package_name, type, target_path)
+ case type
+ when "binary" then
+ execute_remove_script(package_name, target_path)
+ remove_pkg_files(package_name, target_path)
+ when "source" then
+ end
+
+ return true
+ end
+
+ def FileInstaller.move_dir(package_name, source_path, target_path)
+ config_path = File.join(target_path, PACKAGE_INFO_DIR, package_name)
+ Utils.execute_shell_return("cp -r #{source_path}/data/* #{target_path}")
+ FileUtils.cp "#{source_path}/pkginfo.manifest", config_path
+ end
+
+ def FileInstaller.extract_file(package_name, package_file_path, path, target_path)
+ dirname = File.dirname(package_file_path)
+ filename = File.basename(package_file_path)
+ ext = File.extname(filename)
+
+ target_config_path = target_path + "/#{PACKAGE_INFO_DIR}/#{package_name}"
+ if not File.exist? target_config_path then FileUtils.mkdir_p(target_config_path) end
+ pkg_file_list = "#{package_name}.list"
+ pkg_file_list_path = File.join(target_config_path, pkg_file_list)
+ temp_pkg_file_list = "temp_file_list"
+ temp_pkg_file_list_path = File.join(target_config_path, "temp_file_list")
+
+ show_file_list_command = nil
+ extrach_file_list_command = nil
+
+ case ext
+ when ".zip" then
+ show_file_list_command = "zip -sf #{package_file_path}"
+ extract_file_list_command = "unzip -o \"#{package_file_path}\" -d \"#{path}\""
+ when ".tar" then
+ # path should be unix path if it is used in tar command
+ _package_file_path = Utils.get_unix_path(package_file_path)
+ _path = Utils.get_unix_path(path)
+ show_file_list_command = "tar -tf #{_package_file_path}"
+ extract_file_list_command = "tar xf \"#{_package_file_path}\" -C \"#{_path}\""
+ else
+ @@log.error "\"#{filename}\" is not supported."
+ return nil
+ end
+
+ system "#{show_file_list_command} > #{temp_pkg_file_list_path}"
+ File.open(pkg_file_list_path, "a+") do |targetfile|
+ File.open(temp_pkg_file_list_path, "r") do |sourcefile|
+ sourcefile.each_line do |l|
+ if l.strip.start_with? "data/" then
+ ml = l.strip[5..-1]
+ targetfile.puts ml
+ else next end
+ end
+ end
+ end
+ File.delete(temp_pkg_file_list_path)
+
+ case ext
+ when ".zip" then
+ if Utils::HOST_OS.eql? "windows" then
+ log = unzip_file(package_file_path, path)
+ else
+ log = `#{extract_file_list_command}`
+ end
+ when ".tar" then
+ log = `#{extract_file_list_command}`
+ end
+
+ @@log.info "Extracted \"#{filename}\" file.. OK"
+ if log.nil? then log = "" end
+ return log
+ end
+
+ def FileInstaller.extract_a_file(package_file_path, target_file, path)
+ dirname = File.dirname(package_file_path)
+ filename = File.basename(package_file_path)
+ ext = File.extname(filename)
+
+ case ext
+ when ".zip" then
+ if not path.nil? then
+ extract_file_command = "unzip -x #{package_file_path} #{target_file} -d #{path}"
+ else
+ extract_file_command = "unzip -x #{package_file_path} #{target_file}"
+ end
+ when ".tar" then
+ # path should be unix path if it is used in tar command
+ _package_file_path = Utils.get_unix_path(package_file_path)
+ _path = Utils.get_unix_path(path)
+ if not path.nil? then
+ extract_file_command = "tar xf #{_package_file_path} -C #{_path} #{target_file}"
+ else
+ extract_file_command = "tar xf #{_package_file_path} #{target_file}"
+ end
+ end
+
+ system "#{extract_file_command}"
+
+ if not path.nil? then
+ target_file_path = File.join(path, target_file)
+ else
+ target_file_path = target_file
+ end
+
+ if File.exist? target_file_path then
+ @@log.info "Extracted \"#{target_file}\" file.."
+ return true
+ else
+ @@log.warn "Failed to extracted \"#{target_file}\" file.."
+ return false
+ end
+ end
+
+ def FileInstaller.unzip_file(zipfile, dest)
+ log = ""
+ Zip::ZipFile.open(zipfile) do |zip_file|
+ zip_file.each do |f|
+ f_path = File.join(dest, f.name)
+ FileUtils.mkdir_p(File.dirname(f_path))
+ if File.exist?(f_path) then
+ log = log + "[Warn] Exist file : #{f_path}\n" unless f_path.end_with? "/"
+ else
+ zip_file.extract(f, f_path)
+ if not f_path.end_with? "/" then
+ log = log + "[info] Extracted file : #{f_path}\n"
+ end
+ end
+ end
+ end
+ return log
+ end
+
+ def FileInstaller.unzip_a_file(zipfile, file, dest)
+ Zip::ZipFile.open(zipfile) do |zip_file|
+ zip_file.each do |f|
+ if f.name.strip == file then
+ f_path = File.join(dest, f.name)
+ FileUtils.mkdir_p(File.dirname(f_path))
+ zip_file.extract(f, f_path) unless File.exist?(f_path)
+ break
+ end
+ end
+ end
+ end
+end
--- /dev/null
+=begin
+
+ packageServer.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require 'fileutils'
+$LOAD_PATH.unshift File.dirname(__FILE__)
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/build_server"
+require "BuildComm"
+require "packageServerLog"
+require "packageServerConfig"
+require "distribution"
+require "SocketRegisterListener"
+require "client"
+require "utils"
+require "mail"
+
+class PackageServer
+ attr_accessor :id, :location, :log, :integrity
+ attr_accessor :finish, :port
+ attr_accessor :incoming_path
+
+ # constant
+ SUPPORTED_OS = ["linux", "windows", "darwin"]
+
+ # initialize
+ def initialize (id)
+ @location = ""
+ @distribution_list = []
+ # distribution name -> server_url hash
+ @dist_to_server_url = {}
+ @integrity = "YES"
+ @finish = false
+ @port = 3333
+ @test_time=0 #test time in mili-seconds
+ @lock_file=nil
+
+ update_config_information(id)
+
+ if not File.exist?( PackageServerConfig::SERVER_ROOT )
+ FileUtils.mkdir_p( PackageServerConfig::SERVER_ROOT )
+ end
+ @log = PackageServerLog.new( @log_file_path )
+
+ server_information_initialize()
+ end
+
+ # create
+ def create (id, dist_name, server_url, loc = nil )
+ update_config_information(id)
+
+ if loc.nil? or loc.empty? then
+ @location = Dir.pwd + "/" + @id
+ else
+ @location = File.join(loc, @id)
+ end
+
+ # error check : check for already exist in server @id
+ if File.exist? @config_dir
+ raise RuntimeError, "Server create fail. server id [#{@id}] is already exist"
+ end
+
+ # name check
+ if dist_name.strip.eql? "distribution.info" then
+ raise RuntimeError, "id \"distribution.info\" is not available"
+ end
+
+ # create locking file
+ @lock_file = Utils.file_lock(PackageServerConfig::LOCK_FILE)
+
+ # create server config directory
+ FileUtils.mkdir_p @config_dir
+ FileUtils.mkdir_p @incoming_path
+
+ if (not server_url.empty?) and \
+ (not Utils.is_url_remote(server_url)) and \
+ (not Utils.is_absolute_path(server_url)) then
+ # if server_url is local server address then generate absoulte path
+ server_url = File.join(Utils::WORKING_DIR, server_url)
+ end
+
+ # create server configure file
+ File.open( @config_file_path, "w" ) do |f|
+ f.puts "location : #{@location}"
+ f.puts "integrity check : YES"
+ f.puts "server_url : #{dist_name} -> #{server_url}"
+ end
+
+ # create location's directory
+ FileUtils.mkdir_p "#{@location}"
+
+ create_distribution_struct( dist_name, server_url )
+ Utils.file_unlock(@lock_file)
+
+ @log.output( "package server [#{@id}] created successfully", Log::LV_USER )
+ end
+
+ def register( file_path_list, dist_name, snapshot, test_flag )
+ @log.info "package register in server"
+ distribution = get_distribution( dist_name )
+
+ # distribution lock
+ @lock_file = Utils.file_lock(distribution.lock_file_name)
+
+ updated_os_list = []
+ registed_package_list = []
+ binary_pkg_file_path_list = []
+ archive_pkg_file_path_list = []
+ snapshot_name = ""
+
+ file_path_list.each do |f|
+ # error check for file exist
+ if not File.exist? f
+ raise RuntimeError, "package file does not exist [#{f}]"
+ end
+
+ pkg = distribution.get_package_from_file(f)
+
+ # binary package
+ if not pkg.nil? then
+ updated_pkg = register_package(distribution, pkg, f, test_flag)
+
+ updated_os_list.push updated_pkg.os
+ registed_package_list.push updated_pkg
+ binary_pkg_file_path_list.push f
+ # archive package
+ else
+ if test_flag then
+ @log.error("archive package does not using test mode", Log::LV_USER)
+ return
+ end
+
+ file_name = File.basename(f)
+ distribution.register_archive_pkg(file_name)
+ archive_pkg_file_path_list.push f
+ end
+ end
+
+ # check install dependency integrity
+ if not test_flag and @integrity.eql? "YES" then
+ registed_package_list.each do |pkg|
+ distribution.check_package_integrity(pkg)
+ end
+ end
+
+ # move file to package server
+ binary_pkg_file_path_list.each do |l|
+ if test_flag then
+ FileUtils.cp( l, "#{distribution.location}/temp/" )
+ else
+ FileUtils.cp( l, "#{distribution.location}/binary/" )
+ end
+ end
+
+ archive_pkg_file_path_list.each do |l|
+ FileUtils.mv( l, "#{distribution.location}/source/" )
+ end
+
+ # write package list for updated os
+ updated_os_list.uniq!
+ updated_os_list.each do |os|
+ distribution.write_pkg_list( os )
+ end
+
+ # register archive pakcage list.
+ distribution.write_archive_pkg_list()
+
+ # send email
+ if test_flag then
+ msg_list = []
+
+ registed_package_list.each { |p|
+ msg_list.push("%-30s: %08s" % [ p.package_name.strip, p.version.strip ] )
+ }
+ # email just remote package server
+ # Mail.send_package_registe_mail( msg_list, @id )
+ end
+
+ # if snapshot mode is true then generate snapshot
+ if snapshot or test_flag then
+ @log.info "generaging snapshot"
+ snapshot_name = distribution.generate_snapshot("", "", false)
+ end
+
+ Utils.file_unlock(@lock_file)
+ @log.output( "package registed successfully", Log::LV_USER)
+
+ return snapshot_name
+ end
+
+ def generate_snapshot( snpashot_name, dist_name, base_snapshot )
+ @log.info "generating snapshot"
+ distribution = get_distribution( dist_name )
+
+ @lock_file = Utils.file_lock(distribution.lock_file_name)
+
+ snapshot_name = distribution.generate_snapshot( snpashot_name, base_snapshot, true)
+
+ Utils.file_unlock(@lock_file)
+
+ return snapshot_name
+ end
+
+ def sync( dist_name, mode )
+ @log.info "sync from server"
+ distribution = get_distribution( dist_name )
+
+ if distribution.server_url.empty? then
+ @log.error( "This distribution has not remote server", Log::LV_USER)
+ return
+ end
+
+ @lock_file = Utils.file_lock(distribution.lock_file_name)
+ distribution.sync( mode, "linux" )
+ distribution.sync( mode, "windows" )
+ distribution.sync( mode, "darwin" )
+ distribution.sync_archive_pkg
+ Utils.file_unlock(@lock_file)
+
+ @log.output( "package server [#{@id}]'s distribution [#{dist_name}] has been synchronized.", Log::LV_USER )
+ end
+
+ def add_distribution( dist_name, server_url, clone )
+ @lock_file = Utils.file_lock(PackageServerConfig::LOCK_FILE)
+
+ # error check : check for already exist in server directory
+ if @dist_to_server_url.keys.include? dist_name.strip then
+ Utils.file_unlock(@lock_file)
+ raise RuntimeError, "distribution already exist : #{dist_name}"
+ end
+
+ # name check
+ if dist_name.strip.eql? "distribution.info" then
+ Utils.file_unlock(@lock_file)
+ raise RuntimeError, "id \"distribution.info\" is not available"
+ end
+
+ # modify server url
+ if (not server_url.empty?) and (not Utils.is_url_remote(server_url))
+ # if server_url is local server address then generate absoulte path
+ if not Utils.is_absolute_path( server_url ) then
+ if server_url.end_with?("/") then
+ server_url = Utils::WORKING_DIR + server_url
+ else
+ server_url = Utils::WORKING_DIR + "/" + server_url
+ end
+ end
+ end
+
+ add_dist_for_config_file(dist_name, server_url, clone)
+ create_distribution_struct( dist_name, server_url )
+
+ Utils.file_unlock(@lock_file)
+ @log.output( "distribution [#{dist_name}] added successfully", Log::LV_USER )
+ end
+
+ def remove_server()
+ @log.info( "Package server [#{@id}] will be removed and all server information delete", Log::LV_USER)
+
+ @lock_file = Utils.file_lock(PackageServerConfig::LOCK_FILE)
+ if File.exist? @config_file_path then
+ File.open @config_file_path do |f|
+ f.each_line do |l|
+ if l.start_with?( "location : ") then
+ location= l.split(" : ")[1]
+ FileUtils.rm_rf l.split(" : ")[1].strip
+ @log.info( "server location removed : #{location}", Log::LV_USER)
+ end
+ end
+ end
+ else
+ @log.error( "Can't find server information : #{@id}", Log::LV_USER)
+ end
+
+ FileUtils.rm_rf @config_dir
+ FileUtils.rm_rf @log_file_path
+
+ Utils.file_unlock(@lock_file)
+ @log.output( "package server [#{@id}] removed successfully", Log::LV_USER )
+ end
+
+ def remove_dist( dist_name )
+ @log.info "remove distribution in server"
+ distribution = get_distribution( dist_name )
+
+ @lock_file = Utils.file_lock(PackageServerConfig::LOCK_FILE)
+
+ # modify config file
+ config_file = File.readlines(@config_file_path)
+ File.open(@config_file_path, 'w') do |f|
+ config_file.each { |line|
+ f.puts(line) if not line =~ /server_url : #{dist_name} ->/
+ }
+ end
+
+ # modify info file
+ config_file = File.readlines("#{@location}/distribution.info")
+ File.open("#{@location}/distribution.info", 'w') do |f|
+ remove_flag = false
+ config_file.each { |line|
+ if line.start_with? "name :" then
+ if line.split(':')[1].strip.eql? dist_name then
+ remove_flag = true
+ else
+ remove_flag = false
+ end
+
+ end
+
+ # rewrite information for not remove distribution
+ if not remove_flag then
+ f.puts line
+ end
+ }
+ end
+
+ # remove distribution directory
+ FileUtils.rm_rf distribution.location
+
+ # remove distribution struct
+ @distribution_list.delete distribution
+
+ Utils.file_unlock(@lock_file)
+ end
+
+ def remove_pkg( dist_name, pkg_name_list, os, recursive )
+ @log.info "package remove in server"
+ distribution = get_distribution( dist_name )
+
+ @lock_file = Utils.file_lock(PackageServerConfig::LOCK_FILE)
+
+ distribution.remove_pkg(pkg_name_list, os, recursive)
+
+ Utils.file_unlock(@lock_file)
+ @log.output( "package removed successfully", Log::LV_USER )
+ end
+
+ def remove_snapshot( dist_name, snapshot_list )
+ @log.info "remove snapshot in server"
+ distribution = get_distribution( dist_name )
+
+ @lock_file = Utils.file_lock(PackageServerConfig::LOCK_FILE)
+
+ distribution.remove_snapshot(snapshot_list)
+
+ Utils.file_unlock(@lock_file)
+ end
+
+ def clean( dist_name, snapshot_list )
+ @log.info "pakcage server clean"
+ distribution = get_distribution( dist_name )
+
+ @lock_file = Utils.file_lock(PackageServerConfig::LOCK_FILE)
+
+ distribution.clean( snapshot_list )
+
+ # remove incoming dir
+ FileUtils.rm_rf incoming_path
+ FileUtils.mkdir incoming_path
+
+ Utils.file_unlock(@lock_file)
+ end
+
+ # start server daemon
+ def start( port )
+ # set job request listener
+ @log.info "Setting listener..."
+
+ # set port number. default port is 3333
+ @port = port
+
+ listener = SocketRegisterListener.new(self)
+ listener.start
+
+ # main loop
+ @log.info "Entering main loop..."
+ if @test_time > 0 then start_time = Time.now end
+ while( not @finish )
+ # sleep
+ if @test_time > 0 then
+ curr_time = Time.now
+ if (curr_time - start_time).to_i > @test_time then
+ puts "Test time is elapsed!"
+ break
+ end
+ else
+ sleep 1
+ end
+ end
+ end
+
+ # stop server daemon
+ def stop( port )
+ # set port number. default port is 3333
+ @port = port
+ @finish = false
+
+ client = BuildCommClient.create("127.0.0.1", @port)
+ if client.nil? then
+ raise RuntimeError, "Server does not listen in #{@port} port"
+ end
+ client.send("STOP")
+ ret = client.receive_data
+ if ret[0].strip.eql? "SUCC" then
+ @log.output( "Package server is stopped", Log::LV_USER)
+ else
+ @log.output( "Package server return error message", Log::LV_USER)
+ end
+ client.terminate
+
+ end
+
+ def self.list_id
+ @@log = PackageServerLog.new( "#{PackageServerConfig::SERVER_ROOT}/.log" )
+
+ d = Dir.new( PackageServerConfig::SERVER_ROOT )
+ s = d.select {|f| not f.start_with?(".") }
+ s.sort!
+
+ @@log.output( "=== server ID list ===", Log::LV_USER)
+ s.each do |id|
+ @@log.output( id, Log::LV_USER)
+ end
+ end
+
+ def self.list_dist( id )
+ @@log = PackageServerLog.new( "#{PackageServerConfig::SERVER_ROOT}/.log" )
+
+ @@log.output( "=== ID [#{id}]'s distribution list ===", Log::LV_USER)
+
+ # read package id information
+ config_file_path = "#{PackageServerConfig::SERVER_ROOT}/#{id}/config"
+ if not File.exist? config_file_path
+ raise RuntimeError, "[#{id}] is not server ID"
+ end
+
+ File.open config_file_path do |f|
+ f.each_line do |l|
+ if l.start_with?( "server_url : ") and l.include?( "->" ) then
+ @@log.output( l.split(" : ")[1].split("->")[0], Log::LV_USER)
+ end
+ end
+ end
+ end
+
+ def get_default_dist_name()
+ if @distribution_list.empty? then
+ raise RuntimeError,"Server [#{@id}] does not have distribution"
+ end
+ return @distribution_list[0].name
+ end
+
+ def reload_dist_package()
+ # create locking file
+ @lock_file = Utils.file_lock(PackageServerConfig::LOCK_FILE)
+ @distribution_list.each do |dist|
+ dist.initialize_pkg_list
+ end
+ Utils.file_unlock(@lock_file)
+ end
+
+ def release_lock_file
+ if not @lock_file.nil? then
+ Utils.file_unlock(@lock_file)
+ end
+ end
+
+ # PRIVATE METHODS/VARIABLES
+ private
+
+ def server_information_initialize
+ # if id is nil or empty then find default id
+ if @id.nil? or @id.empty?
+ d = Dir.new( PackageServerConfig::SERVER_ROOT )
+ s = d.select {|f| not f.start_with?(".") }
+ if s.length.eql? 1 then
+ @log.info "using default server ID [#{s[0]}]"
+ @id = s[0]
+ else
+ raise RuntimeError, "package server ID is invalid. input server ID using -i option"
+ end
+ end
+
+ # read package id information
+ if File.exist? @config_file_path
+ File.open @config_file_path do |f|
+ f.each_line do |l|
+ if l.start_with?( "location :") then
+ @location = l.split(" :")[1].strip
+ elsif l.start_with?( "integrity check :") then
+ @integrity = l.split(" :")[1].strip.upcase
+ elsif l.start_with?( "server_url :" ) then
+ info = l.split(" :")[1].split("->")
+ @dist_to_server_url[info[0].strip] = info[1].strip
+ else
+ @log.error "server config file has invalid information [#{l}]"
+ end
+ end
+ end
+ end
+
+ @dist_to_server_url.each do |dist_name, server_url|
+ @distribution_list.push Distribution.new( dist_name, "#{@location}/#{dist_name}", server_url, self )
+ end
+ end
+
+ def get_distribution( dist_name )
+ if dist_name.nil? or dist_name.empty? then
+ dist_name = get_default_dist_name()
+ end
+ if dist_name.empty? then
+ raise RuntimeError,"Can't find distribution information"
+ end
+
+ @distribution_list.each do |dist|
+ if dist.name.eql? dist_name.strip
+ return dist
+ end
+ end
+
+ raise RuntimeError, "Can't find distribution [ #{dist_name} ]"
+ end
+
+ def create_distribution_struct( dist_name, server_url )
+ if File.exist? "#{@location}/#{dist_name}"
+ raise RuntimeError, "distribution directory already exist [#{@location}/#{dist_name}]"
+ end
+
+ FileUtils.mkdir "#{@location}/#{dist_name}"
+ FileUtils.mkdir "#{@location}/#{dist_name}/binary"
+ FileUtils.mkdir "#{@location}/#{dist_name}/source"
+ FileUtils.mkdir "#{@location}/#{dist_name}/temp"
+ FileUtils.mkdir "#{@location}/#{dist_name}/snapshots"
+ File.open("#{@location}/#{dist_name}/snapshot.info", "w") do |f| end
+
+ # generate distribution
+ distribution = Distribution.new( dist_name, "#{@location}/#{dist_name}", server_url, self )
+
+ # add dist
+ @distribution_list.push distribution
+
+ if not server_url.empty? then
+ @log.info "generate package server using remote package server [#{server_url}]"
+
+ if Utils.is_url_remote(server_url) then
+ @log.info "[#{dist_name}] distribution creation. using remote server [#{server_url}]"
+ else
+ @log.info "[#{dist_name}] distribution creation. using local server [#{server_url}]"
+ end
+
+ distribution.sync( false, "linux" )
+ distribution.sync( false, "windows" )
+ distribution.sync( false, "darwin" )
+ distribution.sync_archive_pkg
+ else
+ @log.info "generate package server do not using remote package server"
+
+ # write_pkg_list for empty file
+ distribution.write_pkg_list( "linux" )
+ distribution.write_pkg_list( "windows" )
+ distribution.write_pkg_list( "darwin" )
+ distribution.write_archive_pkg_list()
+ end
+
+ # add dist information to .info file
+ File.open("#{@location}/distribution.info", "a") do |f|
+ f.puts "name : #{dist_name}"
+ f.puts "time : #{Time.now.strftime("%Y%m%d%H%M%S")}"
+ f.puts
+ end
+
+ end
+
+ def register_package(distribution, pkg, file_path, test_flag)
+ # get package class using bianry file
+ if pkg.nil? or pkg.package_name.empty? then
+ raise "[#{file_path}]'s pkginfo.manifest file is incomplete."
+ end
+
+ if not test_flag then
+ # error check
+ if pkg.package_name.empty? or pkg.version.empty? \
+ or pkg.os.empty? or pkg.maintainer.empty? then
+ raise "[#{file_path}]'s pkginfo.manifest file is incomplete."
+ end
+
+ updated_pkg = distribution.register(file_path, pkg )
+ else
+ updated_pkg = distribution.register_for_test(file_path, pkg )
+ end
+
+ return updated_pkg
+ end
+
+ def add_dist_for_config_file(dist_name, server_url, clone)
+ File.open( @config_file_path, "a" ) do |f|
+ if clone then
+ @log.info "add distribution using [#{server_url}] in clone mode"
+ f.puts "server_url : #{dist_name} -> "
+ else
+ @log.info "add distribution using [#{server_url}]"
+ f.puts "server_url : #{dist_name} -> #{server_url}"
+ end
+ end
+ end
+
+ def update_config_information(id)
+ @id = id
+ @config_dir = "#{PackageServerConfig::SERVER_ROOT}/#{@id}"
+ @config_file_path = "#{@config_dir}/config"
+ @incoming_path = "#{@config_dir}/incoming"
+ @log_file_path = "#{PackageServerConfig::SERVER_ROOT}/.#{@id}.log"
+ end
+end
--- /dev/null
+=begin
+
+ serverConfig.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+require "utils"
+
+class PackageServerConfig
+ CONFIG_ROOT = "#{Utils::HOME}/.build_tools"
+ SERVER_ROOT = "#{PackageServerConfig::CONFIG_ROOT}/pkg_server"
+ LOCK_FILE = "#{PackageServerConfig::SERVER_ROOT}/.server_loc"
+end
--- /dev/null
+=begin
+
+ packageServerLog.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__)) + "/common"
+require "log"
+require "logger"
+
+class PackageServerLog < Log
+
+ def initialize(path)
+ super(path)
+ @second_out = $stdout
+ end
+
+ protected
+ def output_extra(msg)
+ @second_out.puts msg
+ end
+
+
+end
--- /dev/null
+=begin
+
+ serverOptParser.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require 'optparse'
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+require "utils"
+
+def set_default( options )
+ options[:id] = ""
+ options[:dist] = ""
+ options[:url] = ""
+ options[:os] = "all"
+ options[:pkgs] = []
+ options[:snaps] = []
+ options[:bsnap] = ""
+ options[:port] = "3333"
+ options[:gensnap] = false
+ options[:force] = false
+ options[:test] = false
+ options[:clone] = false
+ options[:recursive] = false
+end
+
+def option_error_check( options )
+
+ case options[:cmd]
+ when "create"
+ if options[:id].empty? or options[:dist].empty? then
+ raise ArgumentError, "Usage: pkg-svr create -n <server name> -d <distribution> [-u <remote server url>] [-l <location>] "
+ end
+ when "remove"
+ if options[:id].empty? then
+ raise ArgumentError, "Usage: pkg-svr remove -n <server name> "
+ end
+ when "remove-pkg"
+ if options[:pkgs].empty? then
+ raise ArgumentError, "Usage: pkg-svr remove-pkg -n <server name> -d <distribution> -P <package file list> [-o <os>]" + "\n" \
+ end
+ when "remove-snapshot"
+ if options[:snaps].empty? then
+ raise ArgumentError, "Usage: pkg-svr remove-snapshot -n <server name> -d <distribution> -s <snapshot list>"
+ end
+ when "add-dist"
+ if options[:id].empty? or options[:dist].empty? then
+ raise ArgumentError, "Usage: pkg-svr add-dist -n <server name> -d <distribution> [-u <remote_server_url>] [--clone] "
+ end
+ when "remove-dist"
+ if options[:id].empty? or options[:dist].empty? then
+ raise ArgumentError, "Usage: pkg-svr remove-dist -n <server name> -d <distribution> "
+ end
+ when "register"
+ if options[:pkgs].empty? then
+ raise ArgumentError, "Usage: pkg-svr register -n <server name> -d <distribution> -P <package file list> [--gen] [--test] "
+ end
+ when "gen-snapshot"
+ if options[:snaps].empty? then
+ raise ArgumentError, "Usage: pkg-svr gen-snapshot -n <server name> -d <distribution> -s <snapshot name> [-b <base snapshot name>]"
+ end
+ when "start"
+ if options[:port].empty? then
+ raise ArgumentError, "Usage: pkg-svr start -n <server name> -p <port>"
+ end
+ when "stop"
+ if options[:port].empty? then
+ raise ArgumentError, "Usage: pkg-svr stop -n <server name> -p <port>"
+ end
+ when "sync"
+ when "list"
+ when "clean"
+ else
+ raise ArgumentError, "Input is incorrect : #{options[:cmd]}"
+ end
+end
+
+def option_parse
+ options = {}
+ banner = "Package-server administer service command-line tool." + "\n" \
+ + "\n" + "Usage: pkg-svr <SUBCOMMAND> [OPTS] or pkg-svr -h" + "\n" \
+ + "\n" + "Subcommands:" + "\n" \
+ + "\t" + "create Create a package-server." + "\n" \
+ + "\t" + "add-dist Add a distribution to package-server." + "\n" \
+ + "\t" + "register Register a package in package-server." + "\n" \
+ + "\t" + "remove Remove a package-server." + "\n" \
+ + "\t" + "remove-dist Remove a distribution to package-server." + "\n" \
+ + "\t" + "remove-snapshot Remove a snapshot in package-server." + "\n" \
+ + "\t" + "gen-snapshot Generate a snapshot in package-server." + "\n" \
+ + "\t" + "sync Synchronize the package-server from parent package server." + "\n" \
+ + "\t" + "start Start the package-server." + "\n" \
+ + "\t" + "stop Stop the package-server." + "\n" \
+ + "\t" + "clean Delete unneeded package files in package-server." + "\n" \
+ + "\t" + "list Show all pack" + "\n" \
+ + "\n" + "Subcommand usage:" + "\n" \
+ + "\t" + "pkg-svr create -n <server name> -d <distribution> [-u <remote server url>] [-l <location>] " + "\n" \
+ + "\t" + "pkg-svr add-dist -n <server name> -d <distribution> [-u <remote_server_url>] [--clone] " + "\n" \
+ + "\t" + "pkg-svr register -n <server name> -d <distribution> -P <package file list> [--gen] [--test] " + "\n" \
+ + "\t" + "pkg-svr remove -n <server name> " + "\n" \
+ + "\t" + "pkg-svr remove-dist -n <server name> -d <distribution>" + "\n" \
+ + "\t" + "pkg-svr remove-pkg -n <server name> -d <distribution> -P <package name list> [-o <os>] " + "\n" \
+ + "\t" + "pkg-svr remove-snapshot -n <server name> -d <distribution> -s <snapshot list>" + "\n" \
+ + "\t" + "pkg-svr gen-snapshot -n <server name> -d <distribution> -s <snapshot name> [-b <base snapshot name>] " + "\n" \
+ + "\t" + "pkg-svr sync -n <server name> -d <distribution> [--force] " + "\n" \
+ + "\t" + "pkg-svr clean -n <server name> -d <distribution> [-s <snapshot list>] " + "\n" \
+ + "\t" + "pkg-svr start -n <server name> -p <port>" + "\n" \
+ + "\t" + "pkg-svr stop -n <server name> -p <port>" + "\n" \
+ + "\t" + "pkg-svr list [-n <server name>] " + "\n" \
+ + "\n" + "Options:" + "\n"
+
+ optparse = OptionParser.new(nil, 32, ' '*8) do|opts|
+ # Set a banner, displayed at the top
+ # of the help screen.
+
+ opts.banner = banner
+
+ opts.on( '-n', '--name <server name>', 'package server name' ) do|name|
+ options[:id] = name
+ end
+
+ opts.on( '-d', '--dist <distribution>', 'package server distribution' ) do|dist|
+ options[:dist] = dist
+ end
+
+ opts.on( '-u', '--url <server url>', 'remote server url: http://127.0.0.1/dibs/unstable' ) do|url|
+ options[:url] = url
+ end
+
+ opts.on( '-o', '--os <operating system>', 'target operating system: linux/windows/darwin' ) do|os|
+ options[:os] = os
+ end
+
+ opts.on( '-P', '--pkgs <package file list>', 'package file path list' ) do|pkgs|
+ list = pkgs.tr(" \t","").split(",")
+ list.each do |l|
+ if l.start_with? "~" then l = Utils::HOME + l.delete("~") end
+ options[:pkgs].push l
+ end
+ end
+
+ opts.on( '-s', '--snapshot <snapshot>', 'a snapshot name or snapshot list' ) do|snaplist|
+ options[:snaps] = snaplist.split(",")
+ end
+
+ opts.on( '-b', '--base <base snapshot>', 'base snapshot name' ) do|bsnap|
+ options[:bsnap] = bsnap
+ end
+
+ opts.on( '-l', '--loc <location>', 'server location' ) do|loc|
+ options[:loc] = loc
+ end
+
+ opts.on( '-p', '--port <port>', 'port number' ) do|port|
+ options[:port] = port
+ end
+
+ opts.on( '--recursive', 'remove all depends packages' ) do
+ options[:recursive] = true
+ end
+
+ opts.on( '--clone', 'clone mode' ) do
+ options[:clone] = true
+ end
+
+ opts.on( '--force', 'force update pkg file' ) do
+ options[:force] = true
+ end
+
+ opts.on( '--test', 'upload for test' ) do
+ options[:test] = true
+ end
+
+ opts.on( '--gen', 'generate snapshot' ) do
+ options[:gensnap] = true
+ end
+
+ opts.on( '-h', '--help', 'display manual' ) do
+ puts opts
+ exit
+ end
+
+ opts.on( '-v', '--version', 'display version' ) do
+ puts "DIBS(Distributed Intelligent Build System) version 1.2.0"
+ exit
+ end
+ end
+
+ cmd = ARGV[0]
+
+ if cmd.eql? "create" or cmd.eql? "register" or cmd.eql? "sync" \
+ or cmd.eql? "gen-snapshot" or cmd.eql? "add-dist" \
+ or cmd.eql? "remove" or cmd.eql? "remove-dist" \
+ or cmd.eql? "remove-pkg" or cmd.eql? "remove-snapshot" \
+ or cmd.eql? "start" or cmd.eql? "stop" or cmd.eql? "clean" \
+ or cmd.eql? "list" \
+ or cmd =~ /(-v)|(--version)/ \
+ or cmd =~ /(help)|(-h)|(--help)/ then
+ if cmd.eql? "help" then ARGV[0] = "-h" end
+ options[:cmd] = ARGV[0]
+ else
+ raise ArgumentError, "Usage: pkg-svr <SUBCOMMAND> [OPTS] or pkg-svr -h"
+ end
+
+ # default value setting
+ set_default options
+
+ optparse.parse!
+
+ # option error check
+ option_error_check options
+
+ return options
+end
+
--- /dev/null
+#!/bin/bash -e
+
+clean ()
+{
+ rm -rf $SRCDIR/*.zip
+ rm -rf $SRCDIR/*.tar.gz
+}
+
+build()
+{
+ if [ "`cat $ROOTDIR/c`" = "ca" ]
+ then
+ echo "B: `cat $ROOTDIR/c` == ca ... ok"
+ else
+ echo "B: `cat $ROOTDIR/c` != ca ... fail"
+ exit 1
+ fi
+}
+
+install()
+{
+ mkdir -p $SRCDIR/package/b.package.linux/data
+ cp $SRCDIR/b $SRCDIR/package/b.package.linux/data
+}
+
+$1
+echo "$1 success"
--- /dev/null
+Package: b
+Version: 11
+OS: linux
+Maintainer: xxx
+Build-host-os: linux
+Build-dependency: c [linux]
+Source: b
--- /dev/null
+#PRE-EXEC
+#EXEC
+../build-cli -h
+#POST-EXEC
+#EXPECT
+Usage: build-cli {build|resolve|query|cancel} ...
+ build-cli build -N <project name> -d <server address> [-o <os>] [-w <password>] [--async]
+ build-cli resolve -N <project name> -d <server address> [-o <os>] [-w <password>] [--async]
+ build-cli query -d <server address>
+ build-cli cancel -j <job number> -d <server address> [-w <password>]
+ build-cli register -P <file name> -d <server address> -t <ftp server url> [-w <password>]
+ -N, --project <project name> project name
+ -d, --address <server address> build server address: 127.0.0.1:2224
+ -o, --os <operating system> target operating system: linux/windows/darwin
+ --async asynchronous job
+ -j, --job <job number> job number
+ -w, --passwd <password> password for managing project
+ -P, --pkg <package file> package file path
+ -t, --ftp <ftp server url> ftp server url: ftp://dibsftp:dibsftp@127.0.0.1
+ -h, --help display manual
+ -v, --version display version
--- /dev/null
+#PRE-EXEC
+#EXEC
+../build-cli query -d 127.0.0.1:2223
+#POST-EXEC
+#EXPECT
+HOST-OS:
+MAX_WORKING_JOBS:
+
+* FTP *
+FTP_ADDR:
+FTP_USERNAME:
+
+* PROJECT(S) *
+
+* JOB(S) *
--- /dev/null
+#PRE-EXEC
+#EXEC
+../build-cli build -N testa -d 127.0.0.1:2223
+#POST-EXEC
+#EXPECT
+Info: Added new job
+Info: Initializing job...
+Info: Checking package version ...
+Info: Checking build dependency ...
+Info: Invoking a thread for building Job
+Info: New Job
+Info: Started to build this job...
+Info: JobBuilder
+Info: Downloding client is initializing...
+Info: Installing dependent packages...
+Info: Downloading dependent source packages...
+Info: Make clean...
+Info: Make build...
+Warn: Failed on build script: "save_cache"
+Warn: Saving cache failed...
+Info: Make install...
+Info: Generatiing pkginfo.manifest...
+Info: Zipping...
+Info: Creating package file ... a_0.0.3_linux.zip
+Info: Checking reverse build dependency ...
+Info: Uploading ...
+Info: Upload succeeded. Sync local pkg-server again...
+Info: Snapshot:
+Info: Job is completed!
--- /dev/null
+#PRE-EXEC
+#EXEC
+../build-cli build -N non_exist_project -d 127.0.0.1:2223
+#POST-EXEC
+#EXPECT
+Error: Requested project does not exist!
+Info: Check project name using "query" command option !
--- /dev/null
+#PRE-EXEC
+#EXEC
+../build-cli build -N testa -d 172.21.111.217:1111
+#POST-EXEC
+#EXPECT
+Connection to server failed!
--- /dev/null
+#PRE-EXEC
+#EXEC
+../build-cli build -N testa -d 111.11q.111.111:1111
+#POST-EXEC
+#EXPECT
+Connection to server failed!
--- /dev/null
+#PRE-EXEC
+echo "testa project is already built and uploaded in previeous testcase"
+#EXEC
+../build-cli build -N testa -d 127.0.0.1:2223
+#POST-EXEC
+#EXPECT
+Info: Added new job
+Info: Initializing job...
+Info: Checking package version ...
+Error: Version must be increased :
+Error: Job is stopped by ERROR
--- /dev/null
+#PRE-EXEC
+echo "Assume testa project is already built and uploaded in previeous testcase"
+#EXEC
+../build-cli build -N testb -d 127.0.0.1:2223
+#POST-EXEC
+#EXPECT
+Info: Added new job
+Info: Initializing job...
+Info: Checking package version ...
+Info: Checking build dependency ...
+Info: Invoking a thread for building Job
+Info: New Job
+Info: Started to build this job...
+Info: JobBuilder
+Info: Downloding client is initializing...
+Info: Installing dependent packages...
+Info: * a
+Info: Downloading dependent source packages...
+Info: Make clean...
+Info: Make build...
+Warn: Failed on build script: "save_cache"
+Warn: Saving cache failed...
+Info: Make install...
+Info: Generatiing pkginfo.manifest...
+Info: Zipping...
+Info: Creating package file
+Info: Checking reverse build dependency ...
+Info: Uploading ...
+Info: Upload succeeded. Sync local pkg-server again...
+Info: Snapshot:
+Info: Job is completed!
--- /dev/null
+#PRE-EXEC
+echo "Assume testa/testb project is already built and uploaded in previeous testcase"
+../pkg-svr remove-pkg -n pkgsvr01 -d unstable -P b
+../pkg-svr remove-pkg -n pkgsvr01 -d unstable -P a
+#EXEC
+../build-cli build -N testb -d 127.0.0.1:2223
+#POST-EXEC
+#EXPECT
+Info: Added new job
+Info: Initializing job...
+Info: Checking package version ...
+Info: Checking build dependency ...
+Error: The package "a" for build-dependency is not found
+Error: Job is stopped by ERROR
--- /dev/null
+#PRE-EXEC
+#EXEC
+../build-cli build -N testa -d 127.0.0.1:2223 -o linux
+#POST-EXEC
+#EXPECT
+Info: Added new job
+Info: Initializing job...
+Info: Checking package version ...
+Info: Checking build dependency ...
+Info: Invoking a thread for building Job
+Info: New Job
+Info: Started to build this job...
+Info: JobBuilder
+Info: Downloding client is initializing...
+Info: Installing dependent packages...
+Info: Downloading dependent source packages...
+Info: Make clean...
+Info: Make build...
+Warn: Failed on build script: "save_cache"
+Warn: Saving cache failed...
+Info: Make install...
+Info: Generatiing pkginfo.manifest...
+Info: Zipping...
+Info: Creating package file ... a_0.0.3_linux.zip
+Info: Checking reverse build dependency ...
+Info: Uploading ...
+Info: Upload succeeded. Sync local pkg-server again...
+Info: Snapshot:
+Info: Job is completed!
--- /dev/null
+#PRE-EXEC
+#EXEC
+../build-cli build -N testa -d 127.0.0.1:2223 -o windows
+#POST-EXEC
+#EXPECT
+Info: Added new job
+Info: Initializing job...
+Info: Checking package version ...
+Error: No servers that are able to build your packages.
+Error: Job is stopped by ERROR
--- /dev/null
+#PRE-EXEC
+#EXEC
+../build-cli build -N testa -d 127.0.0.1:2223 -o unknown_os
+#POST-EXEC
+#EXPECT
+We have no plan to Buld OS "unknown_os"
+ please check your option OS
--- /dev/null
+#PRE-EXEC
+echo "Assume that testc project has the password (1111)"
+echo "Assume that testa,testb which are depended by testc are built and uploaded"
+../build-cli build -N testa -d 127.0.0.1:2223
+../build-cli build -N testb -d 127.0.0.1:2223
+#EXEC
+../build-cli build -N testc -d 127.0.0.1:2223 -w 1111
+#POST-EXEC
+#EXPECT
+Info: Added new job
+Info: Initializing job...
+Info: Checking package version ...
+Info: Checking build dependency ...
+Info: Invoking a thread for building Job
+Info: New Job
+Info: Started to build this job...
+Info: JobBuilder
+Info: Downloding client is initializing...
+Info: Installing dependent packages...
+Info: * a
+Info: Downloading dependent source packages...
+Info: Make clean...
+Info: Make build...
+Warn: Failed on build script: "save_cache"
+Warn: Saving cache failed...
+Info: Make install...
+Info: Generatiing pkginfo.manifest...
+Info: Zipping...
+Info: Creating package file ... c_0.0.3_linux.zip
+Info: Checking reverse build dependency ...
+Info: Uploading ...
+Info: Upload succeeded. Sync local pkg-server again...
+Info: Snapshot:
+Info: Job is completed!
--- /dev/null
+#PRE-EXEC
+echo "Assume that testc project has the password (1111)"
+echo "Assume that testa,testb which are depended by testc are built and uploaded"
+#EXEC
+../build-cli build -N testc -d 127.0.0.1:2223
+#POST-EXEC
+#EXPECT
+Error: Project's password is not matched!
+Error: Use -w option to input your project password
--- /dev/null
+#PRE-EXEC
+echo "Assume that testc project has the password (1111)"
+echo "Assume that testa,testb which are depended by testc are built and uploaded"
+#EXEC
+../build-cli build -N testc -d 127.0.0.1:2223 -w 2222
+#POST-EXEC
+#EXPECT
+Error: Project's password is not matched!
+Error: Use -w option to input your project password
--- /dev/null
+#PRE-EXEC
+../pkg-svr remove-pkg -n pkgsvr01 -d unstable -P c
+#EXEC
+../build-cli build -N testc -d 127.0.0.1:2223 -w 1111 --async
+#POST-EXEC
+#EXPECT
+Info: Added new job
+Info: Above job(s) will be processed asynchronously!
--- /dev/null
+#PRE-EXEC
+../pkg-svr remove-pkg -n pkgsvr01 -d unstable -P c
+../pkg-svr remove-pkg -n pkgsvr01 -d unstable -P b
+../pkg-svr remove-pkg -n pkgsvr01 -d unstable -P a
+#EXEC
+../build-cli build -N testa -d 127.0.0.1:2223 --async
+sleep 1
+../build-cli build -N testb -d 127.0.0.1:2223
+#POST-EXEC
+#EXPECT
+Info: Added new job
+Info: Above job(s) will be processed asynchronously!
+Info: Added new job
+Info: Initializing job...
+Info: Checking package version ...
+Info: Waiting for finishing following jobs:
+Info: *
+Info: Invoking a thread for building Job
+Info: New Job
+Info: Checking build dependency ...
+Info: Started to build this job...
+Info: JobBuilder
+Info: Downloding client is initializing...
+Info: Installing dependent packages...
+Info: * a
+Info: Downloading dependent source packages...
+Info: Make clean...
+Info: Make build...
+Warn: Failed on build script: "save_cache"
+Warn: Saving cache failed...
+Info: Make install...
+Info: Generatiing pkginfo.manifest...
+Info: Zipping...
+Info: Creating package file ...
+Info: Checking reverse build dependency ...
+Info: Uploading ...
+Info: Upload succeeded. Sync local pkg-server again...
+Info: Snapshot:
+Info: Job is completed!
+
--- /dev/null
+#PRE-EXEC
+../build-cli build -N testa -d 127.0.0.1:2223
+../build-cli build -N testb -d 127.0.0.1:2223
+../build-cli build -N testc -d 127.0.0.1:2223 -w 1111
+#EXEC
+rm -rf git01/a
+cd git01;tar xvf a_new.tar.gz
+../build-cli build -N testa -d 127.0.0.1:2223
+#POST-EXEC
+#EXPECT
+Info: Added new job
+Info: Initializing job...
+Info: Checking package version ...
+Info: Invoking a thread for building Job
+Info: New Job
+Info: Checking build dependency ...
+Info: Started to build this job...
+Info: JobBuilder
+Info: Downloding client is initializing...
+Info: Installing dependent packages...
+Info: Downloading dependent source packages...
+Info: Make clean...
+Info: Make build...
+Warn: Failed on build script: "save_cache"
+Warn: Saving cache failed...
+Info: Make install...
+Info: Generatiing pkginfo.manifest...
+Info: Zipping...
+Info: Creating package file ... a_0.0.4_linux.zip
+Info: Checking reverse build dependency ...
+Info: * Checking reverse-build ... testc
+Error: Job is stopped by ERROR
--- /dev/null
+#PRE-EXEC
+rm -rf ~/.build_tools/build_server/testserver3
+rm -rf buildsvr01
+mkdir buildsvr01
+#EXEC
+cd buildsvr01; ../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 -t ftp://dibsftp:coreps2@172.21.111.132
+#POST-EXEC
+../build-svr remove -n testserver3
+rm -rf buildsvr01
+#EXPECT
+Created new build server: "testserver3"
--- /dev/null
+#PRE-EXEC
+#EXEC
+../build-svr -h
+#POST-EXEC
+#EXPECT
+Usage: build-svr {create|remove|start|stop|add-svr|add-prj|fullbuild|help} ...
+ build-svr create -n <server name> -u <package server url> -d <package server address> -t <ftp server url>
+ build-svr remove -n <server name>
+ build-svr start -n <server name> -p <port>
+ build-svr stop -n <server name>
+ build-svr add-svr -n <server name> -d <friend server address>
+ build-svr add-prj -n <server name> -N <project name> [-g <git repository>] [-b <git branch>] [-P <package name>] [-w <password>] [-o <os list>]
+ build-svr register -n <server name> -P <package file>
+ build-svr fullbuild -n <server name>
+ -n, --name <server name> build server name
+ -u, --url <package server url> package server url: http://127.0.0.1/dibs/unstable
+ -d, --address <server address> server address: 127.0.0.1:2224
+ -p, --port <port> server port number: 2224
+ -P, --pkg <package name/file> package file path or name
+ -o, --os <target os list> ex) linux,windows
+ -N, --pname <project name> project name
+ -g, --git <git repository> git repository
+ -b, --branch <git branch> git branch
+ -w, --passwd <password> password for managing project
+ -t, --ftp <ftp server url> ftp server url: ftp://dibsftp:dibsftp@127.0.0.1
+ -h, --help display this information
+ -v, --version display version
--- /dev/null
+#PRE-EXEC
+rm -rf buildsvr01
+mkdir buildsvr01
+cd buildsvr01; ../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 -t ftp://dibsftp:coreps2@172.21.111.132
+#EXEC
+../build-svr add-svr -n testserver3 -d 127.0.0.1:2223
+cat ~/.build_tools/build_server/testserver3/friends
+#POST-EXEC
+../build-svr remove -n testserver3
+rm -rf buildsvr01
+#EXPECT
+Friend server is added successfully!
+127.0.0.1,2223
--- /dev/null
+#PRE-EXEC
+rm -rf ~/.build_tools/build_server/testserver3
+rm -rf buildsvr01
+mkdir buildsvr01
+cd buildsvr01; ../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 -t ftp://dibsftp:coreps2@172.21.111.132
+#EXEC
+echo "TEST_TIME=3" >> ~/.build_tools/build_server/testserver3/server.cfg
+../build-svr start -n testserver3 -p 2223
+#POST-EXEC
+../build-svr remove -n testserver3
+rm -rf buildsvr01
+#EXPECT
+Test time is elapsed!
--- /dev/null
+#PRE-EXEC
+mkdir buildsvr01
+rm -rf ~/.build_tools/build_server/testserver3
+cd buildsvr01; ../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 -t ftp://dibsftp:coreps2@172.21.111.132
+../build-svr start -n testserver3 -p 2223 &
+#EXEC
+sleep 1
+../build-svr stop -n testserver3
+sleep 1
+#POST-EXEC
+../build-svr remove -n testserver3
+rm -rf buildsvr01
+#EXPECT
+Server will be down!
--- /dev/null
+#PRE-EXEC
+mkdir buildsvr01
+cd buildsvr01; ../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 -t ftp://dibsftp:coreps2@172.21.111.132
+#EXEC
+../build-svr stop -n testserver3
+#POST-EXEC
+../build-svr remove -n testserver3
+rm -rf buildsvr01
+#EXPECT
+Server is not running!
--- /dev/null
+#PRE-EXEC
+mkdir buildsvr01
+cd buildsvr01; ../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 -t ftp://dibsftp:coreps2@172.21.111.132
+#EXEC
+../build-svr remove -n testserver3
+#POST-EXEC
+rm -rf buildsvr01
+#EXPECT
+Removed the server
--- /dev/null
+#PRE-EXEC
+rm -rf ~/.build_tools/build_server/testserver3
+rm -rf buildsvr01
+mkdir buildsvr01
+cd buildsvr01; ../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 -t ftp://dibsftp:coreps2@172.21.111.132
+#EXEC
+cd buildsvr01; ../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 -t ftp://dibsftp:coreps2@172.21.111.132
+#POST-EXEC
+../build-svr remove -n testserver3
+rm -rf buildsvr01
+#EXPECT
+Creating server failed. The server id is already exist
--- /dev/null
+#PRE-EXEC
+#EXEC
+../build-svr remove -n testserverxx
+#POST-EXEC
+#EXPECT
+does not exist!
--- /dev/null
+#PRE-EXEC
+#EXEC
+../build-svr start -n testserverxx
+#POST-EXEC
+#EXPECT
+does not exist!
--- /dev/null
+#PRE-EXEC
+rm -rf buildsvr01
+mkdir buildsvr01
+cd buildsvr01; ../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 -t ftp://dibsftp:coreps2@172.21.111.132
+#EXEC
+../build-svr add-prj -n testserver3 -N testa -g test_git -b test_branch
+#POST-EXEC
+../build-svr remove -n testserver3
+rm -rf buildsvr01
+#EXPECT
+Adding project succeeded!
--- /dev/null
+#PRE-EXEC
+#EXEC
+../build-svr add-prj -n testserverxxx -N testa -g test_git -b test_branch
+#POST-EXEC
+#EXPECT
+does not exist!
--- /dev/null
+#PRE-EXEC
+rm -rf buildsvr01
+mkdir buildsvr01
+cd buildsvr01; ../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 -t ftp://dibsftp:coreps2@172.21.111.132
+#EXEC
+../build-svr add-prj -n testserver3 -N testa -g test_git -b test_branch -w 1111
+cat buildsvr01/projects/testa/build | grep PASSWD
+#POST-EXEC
+#EXPECT
+Adding project succeeded!
+PASSWD=1111
--- /dev/null
+#PRE-EXEC
+rm -rf buildsvr01
+mkdir buildsvr01
+cd buildsvr01; ../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 -t ftp://dibsftp:coreps2@172.21.111.132
+#EXEC
+../build-svr add-prj -n testserver3 -N testx -g test_git -b test_branch -o linux
+#POST-EXEC
+../build-svr remove -n testserver3
+rm -rf buildsvr01
+#EXPECT
+Adding project succeeded!
--- /dev/null
+#PRE-EXEC
+rm -rf buildsvr01
+mkdir buildsvr01
+cd buildsvr01; ../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 -t ftp://dibsftp:coreps2@172.21.111.132
+#EXEC
+../build-svr register -n testserver3 -P bin/bin_0.0.0_linux.zip
+#POST-EXEC
+../build-svr remove -n testserver3
+rm -rf buildsvr01
+#EXPECT
+Info: Initializing job...
+Info: Checking package version ...
+Info: Invoking a thread for REGISTER Job
+Info: New Job
+Info: Checking reverse build dependency ...
+Info: Uploading ...
+Info: Upload succeeded. Sync local pkg-server again...
+Info: Snapshot:
+Info: Job is completed!
--- /dev/null
+#PRE-EXEC
+rm -rf buildsvr01
+mkdir buildsvr01
+cd buildsvr01; ../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 -t ftp://dibsftp:coreps2@172.21.111.132
+../build-svr register -n testserver3 -P bin/bin_0.0.0_linux.zip
+#EXEC
+../build-svr register -n testserver3 -P bin/bin_0.0.0_linux.zip
+#POST-EXEC
+../build-svr remove -n testserver3
+rm -rf buildsvr01
+#EXPECT
+Info: Initializing job...
+Info: Checking package version ...
+Error: Version must be increased :
+Error: Job is stopped by ERROR
--- /dev/null
+build-cli-01.testcase
+build-cli-02.testcase
+build-cli-03.testcase
+build-cli-04.testcase
+build-cli-05.testcase
+build-cli-06.testcase
+build-cli-07.testcase
+build-cli-08.testcase
+build-cli-09.testcase
+build-cli-10.testcase
+build-cli-11.testcase
+build-cli-12.testcase
+build-cli-13.testcase
+build-cli-14.testcase
+build-cli-15.testcase
+build-cli-16.testcase
+build-cli-17.testcase
+build-cli-18.testcase
--- /dev/null
+build-svr-01.testcase
+build-svr-02.testcase
+build-svr-03.testcase
+build-svr-04.testcase
+build-svr-05.testcase
+build-svr-06.testcase
+build-svr-07.testcase
+build-svr-08.testcase
+build-svr-09.testcase
+build-svr-10.testcase
+build-svr-11.testcase
+build-svr-12.testcase
+build-svr-13.testcase
+build-svr-14.testcase
--- /dev/null
+#!/bin/sh
+rm -rf buildsvr01
+mkdir buildsvr01
+cd buildsvr01
+../../build-svr remove -n testserver3
+../../build-svr create -n testserver3 -u `pwd`/../pkgsvr01/unstable -d 127.0.0.1:3333 -t ftp://tmax:tmax@172.21.111.217
+cd ..
+cd git01
+tar xvf a.tar.gz
+tar xvf b.tar.gz
+tar xvf c.tar.gz
+tar xvf d.tar.gz
+cd ..
+../build-svr add-prj -n testserver3 -N testa -g `pwd`/git01/a -b master
+../build-svr add-prj -n testserver3 -N testb -g `pwd`/git01/b -b master
+../build-svr add-prj -n testserver3 -N testc -g `pwd`/git01/c -b master -w 1111
+../build-svr add-prj -n testserver3 -N testd -g `pwd`/git01/d -b master
+../build-svr add-prj -n testserver3 -N teste -P bin
+../build-svr start -n testserver3 -p 2223
--- /dev/null
+#!/bin/bash -e
+
+clean ()
+{
+ rm -rf $SRCDIR/*.zip
+ rm -rf $SRCDIR/*.tar.gz
+}
+
+build ()
+{
+ echo "C: clean build (no dependency) ok"
+}
+
+install ()
+{
+ mkdir -p $SRCDIR/package/c.package.linux/data
+ cp $SRCDIR/c $SRCDIR/package/c.package.linux/data
+}
+
+$1
+echo "$1 success"
--- /dev/null
+Package: c
+Version: 11
+OS: linux
+Build-host-os: linux
+Maintainer: xx
+Source: c
--- /dev/null
+packageserver01.testcase
+packageserver02.testcase
+packageserver03.testcase
+packageserver04.testcase
+packageserver05.testcase
+packageserver06.testcase
+packageserver07.testcase
+packageserver08.testcase
+packageserver09.testcase
+packageserver10.testcase
+packageserver11.testcase
+packageserver12.testcase
+packageserver13.testcase
+packageserver14.testcase
+packageserver15.testcase
+packageserver16.testcase
+packageserver17.testcase
+packageserver18.testcase
+packageserver19.testcase
+packageserver20.testcase
+packageserver21.testcase
+packageserver22.testcase
+packageserver23.testcase
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-svr -h
+#POST-EXEC
+#EXPECT
+Usage: pkg-svr {create|register|gen-snapshot|sync|add-dist|spkg-path|remove|remove-pkg|list|help} ...
+ pkg-svr create -i <id> -d <distribution> [-u <remote_server_url>] [-l <location>]
+ pkg-svr add-dist -i<id> -d <distribution> [-u <remote_server_url>] [-c]
+ pkg-svr remove -i <id>
+ pkg-svr register -i <id> -d <distribution> -p <binary_package_file_path_list> -s <source_package_file_path_list> [-g] [-t]
+ pkg-svr remove-pkg -i <id> -d <distribution> -p <binary_package_name_list>
+ pkg-svr gen-snapshot -i<id> -d <distribution> -n <snapshot name> [-b <base_snapshot_name>]
+ pkg-svr sync -i <id> -d <distribution> [-f]
+ pkg-svr spkg-path -i <id> -d <distribution> -s <source_package_name>
+ pkg-svr list [-i <id>]
+ -i, --id <id> package server id
+ -d, --dist <distribution> package server distribution
+ -u, --url <server_address> remote server address
+ -o, --os <operating system> target operating system
+ -p <binary_pakcage_file_path_list>
+ --bpackage binary package file path list
+ -s <source_pakcage_file_path_list>
+ --spackage source package file path
+ -g, --generate snapshot is generate
+ -n, --sname <snapshot> snapshot name
+ -b <base_snapshot_name> base snapshot name
+ --bsnapshot
+ -l, --location <location> server location
+ -f, --force force update pkg file
+ -t, --test upload for test
+ -c, --clone clone mode
+ -h, --help display this information
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-svr create -i temp_local -d unstable
+#POST-EXEC
+#EXPECT
+package server [temp_local] created successfully
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-svr create -i temp_remote -d unstable -u http://172.21.111.177/tmppkgsvr/tmp
+#POST-EXEC
+#EXPECT
+package server [temp_remote] created successfully
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-svr create -i temp_remote_dup -d unstable -u temp_remote/unstable
+#POST-EXEC
+#EXPECT
+package server [temp_remote_dup] created successfully
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-svr add-dist -i temp_local -d stable
+#POST-EXEC
+#EXPECT
+distribution [stable] added successfully
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-svr sync -i temp_remote -d unstable
+#POST-EXEC
+#EXPECT
+package server [temp_remote]'s distribution [unstable] has the synchronization.
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-svr sync -i temp_remote_dup -d unstable -f
+#POST-EXEC
+#EXPECT
+package server [temp_remote_dup]'s distribution [unstable] has the synchronization.
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-svr gen-snapshot -i temp_remote
+#POST-EXEC
+#EXPECT
+snapshot is generated :
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-svr gen-snapshot -i temp_remote -d unstable
+#POST-EXEC
+#EXPECT
+snapshot is generated :
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-svr gen-snapshot -i temp_remote -d unstable -n test
+#POST-EXEC
+#EXPECT
+snapshot is generated :
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-svr gen-snapshot -i temp_remote -d unstable -n test2 -b test
+#POST-EXEC
+#EXPECT
+snapshot is generated :
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-svr gen-snapshot -i temp_remote -d unstable -o all -n test3
+#POST-EXEC
+#EXPECT
+snapshot is generated :
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-svr create -i temp_remote_snap -d unstable -u temp_remote/unstable/snapshots/test
+#POST-EXEC
+#EXPECT
+package server [temp_remote_snap] created successfully
--- /dev/null
+#PRE-EXEC
+cp test_server_pkg_file/smart-build-interface* ./
+#EXEC
+../pkg-svr register -i temp_remote -d unstable -p smart-build-interface_1.20.1_linux.zip -s smart-build-interface_1.20.1.tar.gz -g
+#POST-EXEC
+#EXPECT
+package registed successfully
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-svr register -i temp_remote -d unstable -p smart-build-interface_1.20.1_linux.zip -s smart-build-interface_1.20.1.tar.gz -g
+#POST-EXEC
+#EXPECT
+existing package's version is higher than register package
--- /dev/null
+#PRE-EXEC
+cp test_server_pkg_file/smart-build-interface* ./
+#EXEC
+../pkg-svr register -i temp_remote_dup -d unstable -p ./temp_remote/unstable/binary/smart-build-interface_1.20.1_linux.zip -s ./temp_remote/unstable/source/smart-build-interface_1.20.1.tar.gz -g -t
+#POST-EXEC
+#EXPECT
+package registed successfully
--- /dev/null
+#PRE-EXEC
+cp test_server_pkg_file/smart-build-interface* ./
+#EXEC
+../pkg-svr remove-pkg -i temp_local -d unstable -p smart-build-interface
+#POST-EXEC
+#EXPECT
+package removed successfully
--- /dev/null
+#PRE-EXEC
+cp test_server_pkg_file/smart-build-interface* ./
+#EXEC
+../pkg-svr list
+#POST-EXEC
+#EXPECT
+temp_remote_snap
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-svr list -i temp_local
+#POST-EXEC
+rm smart-build-interface_1.20.1*
+#EXPECT
+unstable
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-svr remove -i temp_local -f
+#POST-EXEC
+YES
+#EXPECT
+package server [temp_local] removed successfully
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-svr remove -i temp_remote -f
+#POST-EXEC
+YES
+#EXPECT
+package server [temp_remote] removed successfully
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-svr remove -i temp_remote_dup -f
+#POST-EXEC
+YES
+#EXPECT
+package server [temp_remote_dup] removed successfully
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-svr remove -i temp_remote_snap -f
+#POST-EXEC
+YES
+#EXPECT
+package server [temp_remote_snap] removed successfully
--- /dev/null
+#PRE-EXEC
+rm -rf pkgcli01
+mkdir pkgcli01
+#EXEC
+../pkg-cli install -p base-ide-product -u http://172.21.111.132/testserver3/unstable -l pkgcli01
+../pkg-cli check-upgrade -l pkgcli01 -u http://172.21.111.132/testserver2/unstable
+#POST-EXEC
+rm -rf pkgcli01
+#EXPECT
+"base-ide-product" package : 0.20.8 ->
+Info: Checked packages for upgrading.. OK
--- /dev/null
+#PRE-EXEC
+rm -rf pkgcli01
+mkdir pkgcli01
+#EXEC
+../pkg-cli install -p nativeapp-eplugin -u http://172.21.111.132/testserver3/unstable -t -l pkgcli01
+../pkg-cli clean -l pkgcli01 -f
+../pkg-cli list-lpkg -l pkgcli01
+#POST-EXEC
+rm -rf pkgcli01
+#EXPECT
+Info: There is no any package.
--- /dev/null
+#PRE-EXEC
+rm -rf pkgcli01
+mkdir pkgcli01
+#EXEC
+../pkg-cli download -p nativeapp-eplugin -u http://172.21.111.132/testserver3/unstable -t -l pkgcli01
+ls pkgcli01
+#POST-EXEC
+rm -rf pkgcli01
+#EXPECT
+base-ide-product_0.20.8_linux.zip
+common-eplugin_0.20.6_linux.zip
+nativeapp-eplugin_0.20.4_linux.zip
+nativecommon-eplugin_0.20.1_linux.zip
--- /dev/null
+#PRE-EXEC
+rm -rf pkgcli01
+mkdir pkgcli01
+#EXEC
+cd pkgcli01; ../../pkg-cli download -p base-ide-product -u http://172.21.111.132/testserver3/unstable
+ls pkgcli01
+#POST-EXEC
+rm -rf pkgcli01
+#EXPECT
+base-ide-product_0.20.8_linux.zip
--- /dev/null
+#PRE-EXEC
+rm -rf pkgcli01
+mkdir pkgcli01
+#EXEC
+../pkg-cli install -p base-ide-product -u http://172.21.111.132/testserver2/unstable -l pkgcli01
+../pkg-cli install -p base-ide-product -u http://172.21.111.132/testserver3/unstable -l pkgcli01 -f
+../pkg-cli list-lpkg -l pkgcli01
+#POST-EXEC
+rm -rf pkgcli01
+#EXPECT
+base-ide-product (0.20.8)
--- /dev/null
+#PRE-EXEC
+rm -rf pkgcli01
+mkdir pkgcli01
+#EXEC
+../pkg-cli install -p nativeapp-eplugin -u http://172.21.111.132/testserver3/unstable -t -l pkgcli01
+../pkg-cli list-lpkg -l pkgcli01
+#POST-EXEC
+rm -rf pkgcli01
+#EXPECT
+base-ide-product (0.20.8)
+common-eplugin (0.20.6)
+nativeapp-eplugin (0.20.4)
+nativecommon-eplugin (0.20.1)
--- /dev/null
+#PRE-EXEC
+rm -rf pkgcli01
+mkdir pkgcli01
+#EXEC
+../pkg-cli install -p base-ide-product -u http://172.21.111.132/testserver3/unstable -l pkgcli01
+../pkg-cli list-lpkg -l pkgcli01
+#POST-EXEC
+rm -rf pkgcli01
+#EXPECT
+base-ide-product (0.20.8)
--- /dev/null
+#PRE-EXEC
+rm -rf pkgcli01
+mkdir pkgcli01
+#EXEC
+../pkg-cli install -p base-ide-product -u http://172.21.111.132/testserver2/unstable -l pkgcli01
+../pkg-cli download -p base-ide-product -u http://172.21.111.132/testserver3/unstable
+../pkg-cli install-file -p base-ide-product_0.20.8_linux.zip -l pkgcli01 -f
+../pkg-cli list-lpkg -l pkgcli01
+#POST-EXEC
+rm -f base-ide-product_0.20.8_linux.zip
+rm -rf pkgcli01
+#EXPECT
+base-ide-product (0.20.8)
--- /dev/null
+#PRE-EXEC
+rm -rf pkgcli01
+mkdir pkgcli01
+#EXEC
+../pkg-cli download -p base-ide-product -u http://172.21.111.132/testserver3/unstable
+../pkg-cli install-file -p base-ide-product_0.20.8_linux.zip -l pkgcli01
+../pkg-cli list-lpkg -l pkgcli01
+#POST-EXEC
+rm -f base-ide-product_0.20.8_linux.zip
+rm -rf pkgcli01
+#EXPECT
+base-ide-product (0.20.8)
--- /dev/null
+#PRE-EXEC
+rm -rf pkgcli01
+mkdir pkgcli01
+#EXEC
+../pkg-cli install -p base-ide-product -u http://172.21.111.132/testserver3/unstable -l pkgcli01
+../pkg-cli list-lpkg -l pkgcli01
+#POST-EXEC
+rm -rf pkgcli01
+#EXPECT
+base-ide-product (0.20.8)
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-cli list-rpkg -u http://172.21.111.132/testserver3/unstable
+#POST-EXEC
+#EXPECT
+base-ide-product (0.20.8)
--- /dev/null
+#PRE-EXEC
+rm -rf pkgcli01
+mkdir pkgcli01
+#EXEC
+../pkg-cli install -p base-ide-product -u http://172.21.111.132/testserver3/unstable -l pkgcli01
+../pkg-cli show-lpkg -p base-ide-product -l pkgcli01
+#POST-EXEC
+rm -rf pkgcli01
+#EXPECT
+Package : base-ide-product
+Version : 0.20.8
+OS : linux
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-cli show-rpkg -p base-ide-product -u http://172.21.111.132/testserver3/unstable
+#POST-EXEC
+#EXPECT
+Package : base-ide-product
+Version : 0.20.8
+OS : linux
--- /dev/null
+#PRE-EXEC
+rm -rf pkgcli01
+mkdir pkgcli01
+#EXEC
+cd pkgcli01; ../../pkg-cli source -p base-ide-product -u http://172.21.111.132/testserver3/unstable
+ls pkgcli01
+#POST-EXEC
+rm -rf pkgcli01
+#EXPECT
+product_0.20.8.tar.gz
--- /dev/null
+#PRE-EXEC
+rm -rf pkgcli01
+mkdir pkgcli01
+#EXEC
+../pkg-cli install -p nativeapp-eplugin -u http://172.21.111.132/testserver3/unstable -l pkgcli01 -t
+../pkg-cli uninstall -p base-ide-product -l pkgcli01 -t
+../pkg-cli list-lpkg -l pkgcli01
+#POST-EXEC
+rm -rf pkgcli01
+#EXPECT
+Info: There is no any package.
--- /dev/null
+#PRE-EXEC
+rm -rf pkgcli01
+mkdir pkgcli01
+#EXEC
+../pkg-cli install -p base-ide-product - http://172.21.111.132/testserver3/unstable -l pkgcli01
+../pkg-cli uninstall -p base-ide-product -l pkgcli01
+../pkg-cli list-lpkg -l pkgcli01
+#POST-EXEC
+rm -rf pkgcli01
+#EXPECT
+Info: There is no any package.
--- /dev/null
+#PRE-EXEC
+#EXEC
+../pkg-cli update -u http://172.21.111.132/testserver3/unstable
+#POST-EXEC
+#EXPECT
+Update package list from "http://172.21.111.132/testserver3/unstable".. OK
--- /dev/null
+#PRE-EXEC
+rm -rf pkgcli01
+mkdir pkgcli01
+#EXEC
+../pkg-cli install -p base-ide-product -u http://172.21.111.132/testserver3/unstable -l pkgcli01
+../pkg-cli upgrade -l pkgcli01 -u http://172.21.111.132/testserver2/unstable
+../pkg-cli list-lpkg -l pkgcli01
+#POST-EXEC
+rm -rf pkgcli01
+#EXPECT
+base-ide-product (0.20.14)
--- /dev/null
+pkg-cli-update.testcase
+pkg-cli-listrpkg.testcase
+pkg-cli-showrpkg.testcase
+pkg-cli-download.testcase
+pkg-cli-download-t.testcase
+pkg-cli-source.testcase
+pkg-cli-install.testcase
+pkg-cli-install-t.testcase
+pkg-cli-install-f.testcase
+pkg-cli-uninstall.testcase
+pkg-cli-uninstall-t.testcase
+pkg-cli-installfile.testcase
+pkg-cli-installfile-f.testcase
+pkg-cli-listlpkg.testcase
+pkg-cli-showlpkg.testcase
+pkg-cli-checkupgrade.testcase
+pkg-cli-upgrade.testcase
+pkg-cli-clean-f.testcase
--- /dev/null
+Package : A
+Version : 0.1.0
+OS : linux
+Build-host-os :linux | windows | darwin
+Maintainer : taejun.ha <tajun.ha@samsung.com>
+Path : binary/A_0.1.0_linux.zip
+Origin : remote
+SHA256 : 52b400554f2a29dec46144af649181cf287c000b4feb65de72055ed9f11924a9
+
+Package: B
+Version : 0.2.0
+OS : linux
+Build-host-os :linux | windows | darwin
+Maintainer : taejun.ha <tajun.ha@samsung.com>
+Install-dependency : C, D, E
+Build-dependency : F (>= 1.0.0.20101221), E (>= 1.0.0.20101221)
+Source-dependency : D, scratchbox-aquila-simulator-rootstrap [ linux |windows ](>= 1.0.0.20101221), scratchbox-core [windows|darwin](>= 1.0.17)
+Path :
+Source : Origin
+From-server? : true
+SHA256 : your_checksum
+Description : this is my first
+project
+descriotion
--- /dev/null
+Package : your_package
+Version : your_version
+OS : linux
+Build-host-os:linux | windows | darwin
+Maintainer : your_name <name@domain> name <name@domain>
+Install-dependency : codecoverage, rootstrap-slp-device-1.0, slp-ide
+Build-dependency : scratchbox-aquila-device-rootstrap (>= 1.0.0.20101221), scratchbox-aquila-simulator-rootstrap (>= 1.0.0.20101221), scratchbox-core (>= 1.0.17)
+Build-src-dependency : scratchbox-aquila-device-rootstrap (>= 1.0.0.20101221) [linux|windows], scratchbox-aquila-simulator-rootstrap [ linux |windows ](>= 1.0.0.20101221), scratchbox-core [windows|darwin](>= 1.0.17)
+Description : this is my first
+project :
+descriotion :
+Attribute :
+Install-script :
+Remove-script :
+Category :
+Conflicts :
+Source : origin
+
+Package : your_package
+Version : your_version
+OS : windows
+Build-host-os:linux | windows | darwin
+Maintainer : your_name <name@domain> name <name@domain>
+Install-dependency : codecoverage, rootstrap-slp-device-1.0, slp-ide
+Build-dependency : scratchbox-aquila-device-rootstrap (>= 1.0.0.20101221), scratchbox-aquila-simulator-rootstrap (>= 1.0.0.20101221), scratchbox-core (>= 1.0.17)
+Build-src-dependency : scratchbox-aquila-device-rootstrap (>= 1.0.0.20101221) [linux|windows], scratchbox-aquila-simulator-rootstrap [ linux |windows ](>= 1.0.0.20101221), scratchbox-core [windows|darwin](>= 1.0.17)
+Description : this is my first
+project :
+descriotion :
+Attribute :
+Install-script :
+Remove-script :
+Category :
+Conflicts :
+Source : origin
--- /dev/null
+#!/bin/sh
+rm -rf ~/.build_tools/pkg_server/pkgsvr01
+rm -rf `pwd`/pkgsvr01
+../pkg-svr create -n pkgsvr01 -d unstable
+../pkg-svr start -n pkgsvr01
--- /dev/null
+#!/usr/bin/ruby
+$success_cases=[]
+$failure_cases=[]
+$testcases=[]
+
+$total_cnt = 0
+
+testCaseName = ""
+resultCheck = ""
+resultFlag = ""
+resultCmdCount = 0
+
+
+class TestCase
+ attr_accessor :name, :pre_exec_cmds, :exec_cmds, :post_exec_cmds, :expected_results
+ def initialize(name)
+ @name = name
+ @pre_exec_cmds = []
+ @exec_cmds = []
+ @post_exec_cmds = []
+ @expected_results = []
+ end
+
+ def is_succeeded?(results)
+ @expected_results.each do |e|
+ found = false
+ results.each do |r|
+ if r.include? e then
+ found = true
+ break
+ end
+ end
+ if not found then return false end
+ end
+
+ return true
+ end
+end
+
+
+# parse
+def parse_testcase(file_name)
+ # create
+ tcase = TestCase.new( file_name )
+
+ # parse
+ File.open(file_name,"r") do |f|
+ status="START"
+ f.each_line do |l|
+ ln = l.strip
+ if ln == "#PRE-EXEC" or ln == "#EXEC" or
+ ln == "#POST-EXEC" or ln == "#EXPECT" then
+
+ status = ln
+ else
+ case status
+ when "#PRE-EXEC"
+ tcase.pre_exec_cmds.push ln
+ when "#EXEC"
+ tcase.exec_cmds.push ln
+ when "#POST-EXEC"
+ tcase.post_exec_cmds.push ln
+ when "#EXPECT"
+ tcase.expected_results.push ln
+ else
+ # ignore
+ end
+ end
+ end
+ end
+
+ return tcase
+end
+
+
+# test execution
+def execute( file_name )
+ printf("#{file_name} ... ")
+ STDOUT.flush
+
+ # parse
+ tcase = parse_testcase( file_name )
+
+ # pre-exec
+ tcase.pre_exec_cmds.each do |cmd|
+ fork_p = false
+ if cmd[-1,1] == "&" then
+ cmd = cmd[0..-2]
+ fork_p = true
+ end
+
+ # get result
+ if not fork_p then
+ IO.popen("#{cmd} 2>&1") { |io|
+ # io.each do |line|
+ # puts "---> #{line}"
+ # end
+ }
+ else
+ IO.popen("#{cmd} 2>&1 &") { |io|
+ # io.each do |line|
+ # puts "---> #{line}"
+ # end
+ }
+ end
+ #`#{cmd}`
+ end
+
+ # exec
+ results = []
+ tcase.exec_cmds.each do |cmd|
+ fork_p = false
+ hidden_p = false
+ if cmd[-1,1] == "&" then
+ cmd = cmd[0..-2]
+ fork_p = true
+ end
+ if cmd[0,1] == ">" then
+ cmd = cmd[1..-1]
+ hidden_p = true
+ end
+ # get result
+ if fork_p then
+ IO.popen("#{cmd} 2>&1 &") { |io|
+ io.each do |line|
+ if not hidden_p then
+ results.push line.strip
+ #puts "---> #{line}"
+ end
+ end
+ }
+ else
+ IO.popen("#{cmd} 2>&1") { |io|
+ io.each do |line|
+ if not hidden_p then
+ results.push line.strip
+ #puts "---> #{line}"
+ end
+ end
+ }
+ end
+ end
+
+ # check expected result
+ if tcase.is_succeeded?(results) then
+ puts "SUCCESS"
+ $success_cases.push file_name
+ else
+ puts "FAIL"
+ $failure_cases.push file_name
+ results.each do |l|
+ puts ">" + l
+ end
+ end
+
+ # post-exec
+ tcase.post_exec_cmds.each do |cmd|
+ # get result
+ IO.popen("#{cmd} 2>&1") { |io|
+ }
+ #`#{cmd}`
+ end
+end
+
+
+#test_list file open
+if (ARGV.size() == 0)
+ testsuite_name = "list.txt"
+else
+ testsuite_name = ARGV.shift
+end
+
+# execute testsuite
+puts
+puts "Regression Test Start "
+puts "=================================="
+
+File.open( testsuite_name ) do |f|
+ f.each_line do |line|
+ $testcases.push("#{line.strip}")
+ execute(line.strip)
+ end
+end
+
+# print result
+puts
+puts "Regression Test Result"
+puts "----------------------"
+puts "Total Test Case : #{$testcases.count}"
+puts "Test Success : #{$success_cases.count}"
+puts "Test Errors : #{$failure_cases.count}"
+puts
+
+if $failure_cases.count != 0 then
+ puts "Test Fail Files"
+ puts "---------------"
+ $failure_cases.each do |name|
+ puts name
+ end
+ puts
+end
+
--- /dev/null
+#!/bin/sh
+./regression.rb pkg-cli.testsuite
+./regression.rb packageserver.testsuite
+./regression.rb buildserver.testsuite
+./regression.rb buildcli.testsuite
--- /dev/null
+#!/usr/bin/ruby
+
+require File.dirname(__FILE__) + "/../src/common/utils"
+require File.dirname(__FILE__) + "/../src/build_server/BuildServerController"
+$SERVER_CONFIG_ROOT = Utils::HOME + "/.tizen_build_server"
+
+BuildServerController.remove_server("mbs_server_temp")
+BuildServerController.create_server("mbs_server_temp", Utils::WORKING_DIR, "http://172.21.111.132/pkgserver/unstable","pkgserver","pkgserver")
+BuildServerController.add_friend_server("mbs_server_temp", "172.21.111.177", 2222)
+=begin
+#case ARGV[0]
+# when "create" then
+# pkg_server.create "temp", "unstable", "http://172.21.111.132/pkgserver/", "unstable"
+# when "register" then
+# #pkg_server.register "/home/taejun/project/sdk-build/test/smart-build-interface_0.19.1_linux.zip", "unstable", "-g"
+# pkg_server.register "/home/taejun/project/sdk-build/test/smart-build-interface_0.19.1_linux.zip", "unstable", ""
+# when "snapshot" then
+ pkg_server.snapshot_generate "", "unstable", "", "", ""
+ when "sync" then
+ # pkg_server.sync "unstable", "force"
+ pkg_server.sync "unstable", ""
+ when "add_distribution" then
+ pkg_server.add_distribution "test_stable", "stable"
+ else
+ puts "First input error : #{ARGV[0]}"
+end
+=end
--- /dev/null
+#!/usr/bin/ruby
+
+require File.dirname(__FILE__) + "/../src/common/utils"
+require File.dirname(__FILE__) + "/../src/build_server/BuildServerController"
+$SERVER_CONFIG_ROOT = Utils::HOME + "/.tizen_build_server"
+
+File.open("#{$SERVER_CONFIG_ROOT}/temp/.request","w") do |f|
+ f.puts("GIT,gerrithost:/slp/sdk/public/native/toolchain/smart-build-interface,master,linux")
+ f.puts("GIT,gerrithost:/slp/sdk/public/native/toolchain/sbi-slp-public-plugin,master,linux")
+end
+=begin
+#case ARGV[0]
+# when "create" then
+# pkg_server.create "temp", "unstable", "http://172.21.111.132/pkgserver/", "unstable"
+# when "register" then
+# #pkg_server.register "/home/taejun/project/sdk-build/test/smart-build-interface_0.19.1_linux.zip", "unstable", "-g"
+# pkg_server.register "/home/taejun/project/sdk-build/test/smart-build-interface_0.19.1_linux.zip", "unstable", ""
+# when "snapshot" then
+ pkg_server.snapshot_generate "", "unstable", "", "", ""
+ when "sync" then
+ # pkg_server.sync "unstable", "force"
+ pkg_server.sync "unstable", ""
+ when "add_distribution" then
+ pkg_server.add_distribution "test_stable", "stable"
+ else
+ puts "First input error : #{ARGV[0]}"
+end
+=end
--- /dev/null
+#!/usr/bin/ruby
+
+require File.dirname(__FILE__) + "/../src/common/utils"
+require File.dirname(__FILE__) + "/../src/build_server/BuildServerController"
+$SERVER_CONFIG_ROOT = Utils::HOME + "/.build_tools/build_server"
+$BUILD_SERVER_HOST_OS = "linux"
+
+obj=BuildServerController.get_server("mbs_server_temp")
+puts obj.friend_servers[0].id
+BuildServerController.start_server("mbs_server_temp")
+=begin
+#case ARGV[0]
+# when "create" then
+# pkg_server.create "temp", "unstable", "http://172.21.111.132/pkgserver/", "unstable"
+# when "register" then
+# #pkg_server.register "/home/taejun/project/sdk-build/test/smart-build-interface_0.19.1_linux.zip", "unstable", "-g"
+# pkg_server.register "/home/taejun/project/sdk-build/test/smart-build-interface_0.19.1_linux.zip", "unstable", ""
+# when "snapshot" then
+ pkg_server.snapshot_generate "", "unstable", "", "", ""
+ when "sync" then
+ # pkg_server.sync "unstable", "force"
+ pkg_server.sync "unstable", ""
+ when "add_distribution" then
+ pkg_server.add_distribution "test_stable", "stable"
+ else
+ puts "First input error : #{ARGV[0]}"
+end
+=end
--- /dev/null
+#!/usr/bin/ruby
+
+require File.dirname(__FILE__) + "/../src/build_server/BuildServerController"
+
+BuildServerController.build_git("mbs_server","gerrithost:/slp/sdk/public/native/toolchain/smart-build-interface","origin/unstable","linux", nil)
+
+#BuildServerController.build_local("temp","/home/bluleo78/git/sbi-slp-public-plugin/toolchains/public/gdb_build","linux")
+=begin
+#case ARGV[0]
+# when "create" then
+# pkg_server.create "temp", "unstable", "http://172.21.111.132/pkgserver/", "unstable"
+# when "register" then
+# #pkg_server.register "/home/taejun/project/sdk-build/test/smart-build-interface_0.19.1_linux.zip", "unstable", "-g"
+# pkg_server.register "/home/taejun/project/sdk-build/test/smart-build-interface_0.19.1_linux.zip", "unstable", ""
+# when "snapshot" then
+ pkg_server.snapshot_generate "", "unstable", "", "", ""
+ when "sync" then
+ # pkg_server.sync "unstable", "force"
+ pkg_server.sync "unstable", ""
+ when "add_distribution" then
+ pkg_server.add_distribution "test_stable", "stable"
+ else
+ puts "First input error : #{ARGV[0]}"
+end
+=end
--- /dev/null
+#!/usr/bin/ruby
+
+require File.dirname(__FILE__) + "/../src/common/utils"
+require File.dirname(__FILE__) + "/../src/build_server/BuildServerController"
+$SERVER_CONFIG_ROOT = Utils::HOME + "/.tizen_build_server"
+$BUILD_SERVER_HOST_OS = "linux"
+
+obj=BuildServerController.get_server("temp")
+File.open("#{$SERVER_CONFIG_ROOT}/temp/.request","w") do |f|
+# f.puts("LOCAL,/home/bluleo78/git/sbi-slp-public-plugin/toolchains/public/gdb_build,linux,/home/bluleo78/test/test/unstable")
+end
+BuildServerController.start_server("temp")
--- /dev/null
+#!/usr/bin/ruby
+
+require File.dirname(__FILE__) + "/../src/common/utils"
+require File.dirname(__FILE__) + "/../src/build_server/BuildServerController"
+$SERVER_CONFIG_ROOT = Utils::HOME + "/.tizen_build_server"
+
+#BuildServerController.build_git("temp","gerrithost:/slp/sdk/public/native/toolchain/smart-build-interface","origin/unstable","linux")
+sleep 5
+
+BuildServerController.build_local("temp","/home/bluleo78/git/sbi-slp-public-plugin/toolchains/public/gdb_build","linux","/home/bluleo78/test/test/unstable")
+=begin
+#case ARGV[0]
+# when "create" then
+# pkg_server.create "temp", "unstable", "http://172.21.111.132/pkgserver/", "unstable"
+# when "register" then
+# #pkg_server.register "/home/taejun/project/sdk-build/test/smart-build-interface_0.19.1_linux.zip", "unstable", "-g"
+# pkg_server.register "/home/taejun/project/sdk-build/test/smart-build-interface_0.19.1_linux.zip", "unstable", ""
+# when "snapshot" then
+ pkg_server.snapshot_generate "", "unstable", "", "", ""
+ when "sync" then
+ # pkg_server.sync "unstable", "force"
+ pkg_server.sync "unstable", ""
+ when "add_distribution" then
+ pkg_server.add_distribution "test_stable", "stable"
+ else
+ puts "First input error : #{ARGV[0]}"
+end
+=end
--- /dev/null
+#!/usr/bin/ruby
+
+require File.dirname(__FILE__) + "/../src/pkg_server/client"
+require File.dirname(__FILE__) + "/../src/pkg_server/serverConfig"
+
+### Client.new("server","dist","snapshot","location")
+
+# local server
+#cl = Client.new("/home/yangttak/test-packageserver")
+
+# remote server
+cl = Client.new("http://172.21.111.132/pkgserver/unstable", "/home/yangttak/build_root")
+#cl.update()
+result = cl.get_install_dependent_packages("cross-arm-gcc-4.5", "linux", true)
+puts "----"
+puts result
+
+result = cl.get_install_dependent_packages("cross-arm-gcc-4.5", "linux", false)
+puts "----"
+puts result
+
+result = cl.get_build_dependent_packages("tizen-image-creator", "linux", true)
+puts "----"
+puts result
+#cl.upload("pkgserver", "first", "unstable", nil, "/home/yangttak/test0208/sdk-build/test/test_downloader.rb")
+#cl.install_local_pkg("/home/yangttak/test0208/sdk-build/smart-build-interface_0.20.0_linux.zip", "linux")
+#cl.show_pkg_info("tizen-ide", "linux")
+
+#cl = Client.new("http://172.21.111.132/pkgserver/unstable/snapshot/snapshot3-linux", "/tmp/client-test")
+#cl.update()
+#result = cl.get_install_dependent_packages("smart-build-interface", "linux")
+#puts result
+
+# if location is nil
+#cl = Client.new("http://172.21.111.132/pkgserver/unstable", nil)
+
+# if server addr is nil
+#cl = Client.new(nil, "/tmp/client-test")
+
+# install package list
+#cl.download("base-toolchain", "windows")
+
+# test install different veriosn package
+#cl = Client.new("http://172.21.111.132/pkgserver/unstable/snapshot/snapshot2-linux", "/tmp/client-test")
+#cl.install("tizen-ide", "linux")
+#cl.install("smart-build-interface", "linux")
+
+
+#cl = Client.new("http://172.21.111.132/pkgserver/unstable", "/tmp/client-test")
+#result = cl.get_build_dependent_packages("mpfr", "linux")
+#puts result
+#result = cl.get_install_dependent_packages("arm-linux-gnueabi-gdb-7.2", "linux")
+#puts result
+#result = cl.get_install_dependent_packages("smart-build-interface", "linux")
+#puts result
+
+
--- /dev/null
+#!/usr/bin/ruby
+
+require File.dirname(__FILE__) + "/../src/pkg_server/downloader"
+require File.dirname(__FILE__) + "/../src/pkg_server/serverConfig"
+
+### FileDownLoader.download(source url, target path)
+
+# download local package
+# FileDownLoader.download("/home/yangttak/gmp-5.0.1.tar.gz", ".")
+
+# download remote package
+FileDownLoader.download("http://172.21.111.132/pkgserver/unstable/source/gmp-5.0.1.tar.gz", $download_temp)
--- /dev/null
+#!/usr/bin/ruby
+
+require File.dirname(__FILE__) + "/../src/pkg_server/downloader"
+require File.dirname(__FILE__) + "/../src/pkg_server/installer"
+require File.dirname(__FILE__) + "/../src/pkg_server/serverConfig"
+
+FileDownLoader.download("http://172.21.111.132/pkgserver/unstable/source/gmp-5.0.1.tar.gz", $download_temp)
+
+### FileInstaller.install(package_name, source_file_path, package_type, target_path)
+FileInstaller.install("gmp","#{$download_temp}/gmp-5.0.1.tar.gz", "binary", $build_root)
--- /dev/null
+#!/usr/bin/ruby
+require '../src/common/parser'
+require '../src/common/package'
+
+alist = Parser.read_pkg_list "pkg-list"
+a_list = alist.values
+a_list.each do |l|
+ l.print
+end
--- /dev/null
+#!/bin/sh
+
+echo "============ remove 1 =============="
+../pkg-svr remove -n temp_local
+echo "============ remove 2 =============="
+../pkg-svr remove -n temp_remote
+echo "============ remove 3 =============="
+../pkg-svr remove -n temp_remote_dup
+echo "============ remove 4 =============="
+../pkg-svr remove -n temp_remote_snap
+echo "============ create 1 =============="
+../pkg-svr create -n temp_local -d unstable
+echo "============ create 2 =============="
+../pkg-svr create -n temp_remote -d unstable
+echo "============ create 3 =============="
+../pkg-svr create -n temp_remote_dup -d unstable -u temp_remote/unstable
+echo "============ add dist 1 =============="
+../pkg-svr add-dist -n temp_local -d stable
+echo "============ sync 1 =============="
+../pkg-svr sync -n temp_remote -d unstable
+echo "============ sync 2 =============="
+../pkg-svr sync -n temp_remote_dup -d unstable --force
+echo "============ gen snapshot 1 =============="
+../pkg-svr gen-snapshot -n temp_remote
+echo "============ gen snapshot 2 =============="
+../pkg-svr gen-snapshot -n temp_remote -d unstable
+echo "============ gen snapshot 3 =============="
+../pkg-svr gen-snapshot -n temp_remote -d unstable -s test
+echo "============ gen snapshot 4 =============="
+../pkg-svr gen-snapshot -n temp_remote -d unstable -s test2 -b test
+echo "============ gen snapshot 5 =============="
+../pkg-svr gen-snapshot -n temp_remote -d unstable -o linux
+echo "============ gen snapshot 6 =============="
+../pkg-svr gen-snapshot -n temp_remote -d unstable -o windows
+echo "============ gen snapshot 7 =============="
+../pkg-svr gen-snapshot -n temp_remote -d unstable -o darwin
+echo "============ gen snapshot 8 =============="
+../pkg-svr gen-snapshot -n temp_remote -d unstable -o all
+echo "============ gen snapshot 9 =============="
+../pkg-svr gen-snapshot -n temp_remote -d unstable -o all -P test_server_pkg_file/smart-build-interface_1.20.1_linux.zip -s test3
+echo "============ create 4 =============="
+../pkg-svr create -n temp_remote_snap -d unstable -u temp_remote/unstable/snapshots/test
+echo "============ register 1 =============="
+cp test_server_pkg_file/smart-build-interface_*_linux.zip ./
+../pkg-svr register -n temp_local -d unstable -P smart-build-interface_1.20.1_linux.zip
+echo "============ register 2 =============="
+cp test_server_pkg_file/smart-build-interface_*_linux.zip ./
+../pkg-svr register -n temp_remote -d unstable -P smart-build-interface_1.20.1_linux.zip --gen
+echo "============ register 3 =============="
+cp test_server_pkg_file/smart-build-interface_*_linux.zip ./
+../pkg-svr register -n temp_remote_dup -d unstable -P smart-build-interface_1.20.1_linux.zip --gen --test
+echo "============ register 4 =============="
+cp test_server_pkg_file/archive.zip ./
+../pkg-svr register -n temp_local -d unstable -A archive.zip
+echo "============ remove 3 =============="
+../pkg-svr remove-pkg -n temp_local -d unstable -P smart-build-interface
+echo "============ clean 1 =============="
+../pkg-svr clean -n temp_local -d unstable
+echo "============ clean 2 =============="
+../pkg-svr clean -n temp_remote -d unstable -s test,test2,test3
+echo "============ list 1 =============="
+../pkg-svr list
+echo "============ list 2 =============="
+../pkg-svr list -n temp_local
+#../pkg-svr remove -n temp
+
--- /dev/null
+#!/usr/bin/ruby
+
+require File.dirname(__FILE__) + "/../src/common/utils"
+require File.dirname(__FILE__) + "/../src/pkg_server/packageServer"
+
+pkg_server = PackageServer.new "temp"
+
+case ARGV[0]
+ when "create" then
+ pkg_server.create "temp", "unstable", "http://172.21.111.132/pkgserver/", "unstable"
+ when "register" then
+ #pkg_server.register "/home/taejun/project/sdk-build/test/smart-build-interface_0.19.1_linux.zip", "unstable", "-g"
+ pkg_server.register "/home/taejun/project/sdk-build/test/smart-build-interface_0.19.1_linux.zip", "unstable", ""
+ when "snapshot" then
+ pkg_server.snapshot_generate "", "unstable", "", "", ""
+ when "sync" then
+ # pkg_server.sync "unstable", "force"
+ pkg_server.sync "unstable", ""
+ when "add_distribution" then
+ pkg_server.add_distribution "test_stable", "stable"
+ else
+ puts "First input error : #{ARGV[0]}"
+end
+
--- /dev/null
+#!/usr/bin/ruby
+
+require File.dirname(__FILE__) + "/../src/common/utils"
+
+result = Utils.compare_version("5.2", "5.0.1")
+puts result
+
--- /dev/null
+# Logfile created on Tue Feb 07 04:41:32 +0900 2012 by logger.rb/22285
+I, [2012-02-07T04:41:32.501856 #8938] INFO -- : option parsing start
+I, [2012-02-07T04:41:32.502027 #8938] INFO -- : option is :
+I, [2012-02-07T04:41:32.502149 #8938] INFO -- : option parsing end
+I, [2012-02-07T04:41:58.085604 #8964] INFO -- : option parsing start
+I, [2012-02-07T04:41:58.085807 #8964] INFO -- : option is : -u,http://172.21.111.132/testserver/unstable
+I, [2012-02-07T04:41:58.085997 #8964] INFO -- : option parsing end
+I, [2012-02-07T04:42:23.693462 #9000] INFO -- : option parsing start
+I, [2012-02-07T04:42:23.693562 #9000] INFO -- : option is : -u,http://172.21.111.132/testserver/unstable
+I, [2012-02-07T04:42:23.693652 #9000] INFO -- : option parsing end
+I, [2012-02-07T04:56:31.754070 #10355] INFO -- : option parsing start
+I, [2012-02-07T04:56:31.754269 #10355] INFO -- : option is : -u,http://172.21.111.132/testserver/unstable
+I, [2012-02-07T04:56:31.754475 #10355] INFO -- : option parsing end
+I, [2012-02-07T05:00:28.494119 #10628] INFO -- : option parsing start
+I, [2012-02-07T05:00:28.494318 #10628] INFO -- : option is : -u,http://172.21.111.132/testserver/unstable
+I, [2012-02-07T05:00:28.494519 #10628] INFO -- : option parsing end
+I, [2012-02-07T05:05:54.803965 #11007] INFO -- : option parsing start
+I, [2012-02-07T05:05:54.804057 #11007] INFO -- : option is : -u,http://172.21.111.132/testserver/unstable
+I, [2012-02-07T05:05:54.804147 #11007] INFO -- : option parsing end
+I, [2012-02-07T05:11:20.088453 #11415] INFO -- : option parsing start
+I, [2012-02-07T05:11:20.088549 #11415] INFO -- : option is : -u,http://172.21.111.132/testserver/unstable
+I, [2012-02-07T05:11:20.088641 #11415] INFO -- : option parsing end
+I, [2012-02-07T05:12:13.094058 #11504] INFO -- : option parsing start
+I, [2012-02-07T05:12:13.094152 #11504] INFO -- : option is : -u,http://172.21.111.132/testserver/unstable
+I, [2012-02-07T05:12:13.094241 #11504] INFO -- : option parsing end
+I, [2012-02-07T05:32:29.151717 #12638] INFO -- : option parsing start
+I, [2012-02-07T05:32:29.151917 #12638] INFO -- : option is : -u,http://172.21.111.132/testserver/unstable
+I, [2012-02-07T05:32:29.152123 #12638] INFO -- : option parsing end
+I, [2012-02-07T05:43:03.812225 #12775] INFO -- : option parsing start
+I, [2012-02-07T05:43:03.813711 #12775] INFO -- : option is : -u,http://172.21.111.132/testserver/unstable
+I, [2012-02-07T05:43:03.816670 #12775] INFO -- : option parsing end
--- /dev/null
+#!/bin/sh -x
+# clean
+clean()
+{
+ rm -rf $SRCDIR/*.zip
+ rm -rf $SRCDIR/*.tar.gz
+ rm -rf $SRCDIR/*.package.linux
+}
+
+# build
+build()
+{
+ touch own
+ touch two
+ touch three
+ touch four
+}
+
+# install
+install()
+{
+ build
+
+ BIN_DIR=$SRCDIR/package
+ mkdir -p $BIN_DIR/pkgone.package.linux
+ mkdir -p $BIN_DIR/pkgtwo.package.linux
+ mkdir -p $BIN_DIR/pkgthree.package.linux
+ mkdir -p $BIN_DIR/pkgfour.package.linux
+ mv own $BIN_DIR/pkgone.package.linux
+ mv two $BIN_DIR/pkgtwo.package.linux
+ mv three $BIN_DIR/pkgthree.package.linux
+ mv four $BIN_DIR/pkgfour.package.linux
+}
+
+
+
+[ "$1" = "clean" ] && clean
+[ "$1" = "build" ] && build
+[ "$1" = "install" ] && install
+exit 0
--- /dev/null
+Package : pkgone
+Version : 0.1.0
+OS : linux | windows
+Mintainer : pkgone owner <owner@pkgone>
+Install-dependency : pkgtwo (>= 0.2.0) [linux | windows], pkgthree (<= 0.3.0 ) [linux]
+Build-dependency : pkgtwo (>= 0.2.0) [linux | windows], pkgthree (<= 0.3.0 ) [linux]
+Source-dependency : tpkg
+# this is commant
+Attribute : hi
+Category : my Category
+Conflict : pkgfour
+Install-script : pkgone.install
+Remove-script : pkgone.remove
+Source : tpkg
+Description : first test package
+--
+it will increase
+
+Package : pkgtwo
+Version : 0.2.0
+OS : linux | windows
+Mintainer : pkgone owner <owner@pkgone>
+Install-dependency : pkgone (>= 0.1.0) [linux | windows], pkgthree (<= 0.3.0 ) [linux]
+Build-dependency : pkgone (>= 0.1.0) [linux | windows], pkgthree (<= 0.3.0 ) [linux]
+Source-dependency : tpkg
+# this is commant
+Attribute : E
+Category : ouu Category
+Conflict : pkgfour
+Install-script : pkgtwo.install
+Remove-script : pkgtwo.remove
+Source : tpkg
+Description : second test package
+--
+it will increase
+
+Package : pkgthree
+Version : 0.3.0
+OS : linux | darwin
+Mintainer : pkgone owner <owner@pkgone>
+Install-dependency : pkgtwo (>= 0.2.0) [linux | windows]
+Build-dependency : pkgtwo (>= 0.2.0) [linux | windows], pkgone (<= 0.1.0 ) [linux]
+Source-dependency : tpkg
+# this is commant
+Attribute : sam
+Category : sam Category
+Conflict : pkgfour
+Install-script : pkgthree.install
+Remove-script : pkgthree.remove
+Source : tpkg
+Description : 3rd test package
+--
+it will increase
+
+Package : pkgfour
+Version : 0.4.0
+OS : linux | darwin
+Mintainer : pkgone owner <owner@pkgone>
+Install-dependency : pkgthree (<= 0.3.0 ) [linux]
+Build-dependency : pkgone (>= 0.1.0) [linux | windows], pkgthree (<= 0.3.0 ) [linux]
+Source-dependency : tpkg
+# this is commant
+Attribute : i for
+Category : you Category
+Conflict : pkgfour
+Install-script : pkgfour.install
+Remove-script : pkgfour.remove
+Source : tpkg
+Description : 4th test package
+--
+it will increase
--- /dev/null
+#!/bin/bash
+
+###############################################################
+## Variables
+###############################################################
+
+START_PATH=~+ ## like `pwd`
+SCRIPT_NAME=$0
+SCRIPT_OPERATION=$1
+ARG1=$2
+ARG2=$3
+ARG3=$4
+GIT_PORT=29419
+CONTINUE=n
+GIT_LIST="
+/sdk/ide/common-eplugin
+/sdk/ide/eventinjector-eplugin
+/sdk/ide/nativecommon-eplugin
+/sdk/ide/nativeappcommon-eplugin
+/sdk/ide/nativeapp-eplugin
+/sdk/ide/nativecpp-eplugin
+/sdk/ide/nativecpp-ext-eplugin
+/sdk/ide/native-sample
+/sdk/ide/nativeplatform-eplugin
+/sdk/ide/unittest-eplugin
+/sdk/ide/native-gui-builder-eplugin
+/sdk/gui-builder/native-gui-builder
+/sdk/ide/profiler-eplugin
+/sdk/ide/codecoverage-eplugin
+/sdk/ide/assignmenttracing-eplugin
+/sdk/ide/codehiding-eplugin
+/sdk/ide/telephony-eplugin
+/sdk/ide/webapp-eplugin
+/sdk/ide/product
+"
+
+
+###############################################################
+## Usage output functions
+###############################################################
+
+function usage() {
+ echo "Usage : ${SCRIPT_NAME##*/} <command> [<args>]"; echo
+ echo "The most commonly used script commands are :"
+ echo " clone Clone git sources about Tizen SDK"
+ echo " pull Pull git sources about Tizen SDK"
+ echo " checkout checkout git sources about Tizen SDK"; echo
+ exit 1
+}
+
+function usage_pull() {
+ echo "Usage : ${SCRIPT_NAME##*/} pull : Git pull in current directory";
+ echo "Usage : ${SCRIPT_NAME##*/} pull <source directory> : Git pull in source directory";
+
+ draw_line
+ echo " Ex1) \$ ${SCRIPT_NAME} pull"; echo
+ echo " Ex2) \$ ${SCRIPT_NAME} pull $(pwd)/tizen-ide-sources"; echo
+ exit 1
+}
+
+function usage_checkout() {
+ echo "Usage : ${SCRIPT_NAME##*/} checkout <branch name> : Git checkout in current directory";
+ echo "Usage : ${SCRIPT_NAME##*/} checkout <branch name> <source directory> : Git checkout in source directory";
+
+ draw_line
+ echo " Ex1) \$ ${SCRIPT_NAME} checkout develop"; echo
+ echo " Ex2) \$ ${SCRIPT_NAME} checkout develop $(pwd)/tizen-ide-sources"; echo
+ exit 1
+}
+
+function usage_clone() {
+ draw_line
+ echo "Usage : 1) ${SCRIPT_NAME##*/} clone <git branch name> <host> : Git clone in curreut directory"; echo
+ echo " 2) ${SCRIPT_NAME##*/} clone <git branch name> <host> <destination directory>: Git clone in destination directory"
+ draw_line
+ echo " Ex1) \$ ${SCRIPT_NAME} clone develop gerrithost"
+ echo " Ex2) \$ ${SCRIPT_NAME} clone release http://develop.tizen.org/git:2039 /home/usr/work/git"
+ exit 1
+}
+
+
+###############################################################
+## Processing Functions
+###############################################################
+
+function draw_line() {
+ echo; echo "==========================================================================="; echo;
+}
+
+## Error Check Function
+function isError() {
+ ERROR_CODE=$?
+
+ if [ ${ERROR_CODE} == 0 ]; then
+ echo "[ $1 : Done ]";
+ else
+ echo "[ $1 : Fail (ErrorCode : ${ERROR_CODE}) ]"
+ if [ ${CONTINUE} == "n" ]; then
+ input=0
+ while [ ${input} != "y" -a ${input} != "n" -a ${input} != "a" ]; do
+ echo "Continue? y: Yes, n: No, a: Yes to all"
+ read input
+ if [ ${input} == "n" ]; then
+ exit ${ERROR_CODE}
+ elif [ ${input} == "a" ]; then
+ CONTINUE=y
+ echo ${CONTINUE}
+ fi
+ done
+ fi
+ fi
+}
+
+## Cloning git
+function git_clone() {
+ GIT_PATH=$1
+ GIT_NAME=${GIT_PATH##*/}
+
+ ## ARG1 : <git branch name>
+ ## ARG2 : <host>
+ ## ARG3 : <destination directory>
+ git clone -b ${ARG1} ${ARG2}:${GIT_PATH} ${ARG3}/${GIT_NAME}
+ isError "Cloned ${GIT_NAME}"
+ scp -p -P ${GIT_PORT} ${ARG2}:hooks/commit-msg ${ARG3}/${GIT_NAME}/.git/hooks/
+ isError "Generate change-id ${GIT_NAME}"
+}
+
+## Cloning git all
+function git_clone_all() {
+ draw_line; echo "Git clone sources"; draw_line
+
+ for GIT_EACH in ${GIT_LIST}
+ do
+ git_clone ${GIT_EACH}
+ done
+}
+
+## Pulling git
+function git_pull() {
+ GIT_PATH=$1
+ GIT_NAME=${GIT_PATH##*/}
+
+ ## ARG1 : <source directory>
+ cd ${ARG1}/${GIT_NAME}
+ isError "Found git directory ( ${ARG1}/${GIT_NAME} )"
+ git pull
+ isError "Pulled ${GIT_NAME}"
+}
+
+## Pulling git all
+function git_pull_all() {
+ draw_line; echo "Git pull sources"; draw_line
+
+ cd ${ARG1}
+ isError "Checked source directory ( ${ARG1} )"
+
+ for GIT_EACH in ${GIT_LIST}
+ do
+ git_pull ${GIT_EACH}
+ done
+
+ cd ${START_PATH}
+}
+
+## Checking out git
+function git_checkout() {
+ GIT_PATH=$1
+ GIT_NAME=${GIT_PATH##*/}
+
+ ## ARG1 : <source directory>
+ cd ${ARG2}/${GIT_NAME}
+ isError "Found git directory ( ${ARG2}/${GIT_NAME} )"
+ git checkout ${ARG1}
+ isError "Checkout ${GIT_NAME}"
+}
+
+## Checking out git all
+function git_checkout_all() {
+ draw_line; echo "Git checkout"; draw_line
+
+ cd ${ARG2}
+ isError "Checked source directory ( ${ARG1} )"
+
+ for GIT_EACH in ${GIT_LIST}
+ do
+ git_checkout ${GIT_EACH}
+ done
+
+ cd ${START_PATH}
+}
+
+## Command git
+function git_command() {
+ GIT_PATH=$1
+ GIT_NAME=${GIT_PATH##*/}
+
+ ## ARG1 : <source directory>
+ cd ${ARG1}/${GIT_NAME}
+ isError "Found git directory ( ${ARG1}/${GIT_NAME} )"
+ git ${SCRIPT_OPERATION}
+ isError "Pulled ${GIT_NAME}"
+}
+
+## Command git all
+function git_command_all() {
+ draw_line; echo "Git ${SCRIPT_OPERATION}"; draw_line
+
+ cd ${ARG1}
+ isError "Checked source directory ( ${ARG1} )"
+
+ for GIT_EACH in ${GIT_LIST}
+ do
+ git_command ${GIT_EACH}
+ done
+
+ cd ${START_PATH}
+}
+
+###############################################################
+## Begin script
+###############################################################
+
+case ${SCRIPT_OPERATION} in
+ ## process "clone" operation
+ clone)
+ if [ "$#" == 4 ]; then
+ git_clone_all
+ elif [ "$#" == 3 ]; then
+ ARG3=$(pwd)
+ git_clone_all
+ else
+ usage_clone
+ fi
+ ;;
+
+ ## process "pull" operation
+ pull)
+ if [ "$#" == 2 ]; then
+ git_pull_all
+ elif [ "$#" == 1 ]; then
+ ARG1=$(pwd)
+ git_pull_all
+ else
+ usage_pull
+ fi
+ ;;
+
+ ## process "checkout" operation
+ checkout)
+ if [ "$#" == 3 ]; then
+ git_checkout_all
+ elif [ "$#" == 2 ]; then
+ ARG2=$(pwd)
+ git_checkout_all
+ else
+ usage_checkout
+ fi
+ ;;
+
+ ## process default
+ *)
+ if [ "$#" == 1 ]; then
+ ARG1=$(pwd)
+ git_command_all
+ else
+ usage
+ fi
+ ;;
+esac
+
+echo "[ Finished process ]"
+
+###############################################################
+## End script
+###############################################################