웹사이트 검색

PyGObject 응용 프로그램과 프로그램을 Linux 데스크탑용 ".deb" 패키지로 패키지 – 4부


Linux 데스크탑에서 PyGObject 프로그래밍 시리즈를 계속 진행하겠습니다. 시리즈의 4번째 부분에서는 Linux 데스크톱용으로 만든 프로그램과 애플리케이션을 패키징하는 방법을 설명하겠습니다. PyGObject를 데비안 패키지로 사용하는 Linux 데스크탑.

Debian 패키지(.deb)는 Linux에서 프로그램을 설치하는 데 가장 많이 사용되는 형식이며, .deb 패키지를 다루는 "dpkg " 시스템은 다음과 같습니다. Ubuntu 및 Linux Mint와 같은 모든 Debian 기반 Linux 배포판의 기본값입니다. 그렇기 때문에 우리는 데비안용 프로그램을 패키징하는 방법만 설명할 것입니다.

PyGObject 애플리케이션에서 데비안 패키지 생성

먼저 데비안 패키지 생성에 대한 기본 지식이 있어야 합니다. 다음 가이드가 많은 도움이 될 것입니다.

  1. 데비안 패키징 소개

간단히 말해서, “myprogram”이라는 프로젝트가 있는 경우 패키징할 수 있도록 다음 파일과 폴더를 포함해야 합니다.

  1. debian (폴더): 이 폴더에는 여러 하위 파일로 나누어진 Debian 패키지에 대한 모든 정보가 포함되어 있습니다.
  2. po (폴더): po 폴더에는 프로그램의 번역 파일이 포함되어 있습니다(5부에서 설명하겠습니다).
  3. myprogram (파일): 이것은 PyGObject를 사용하여 만든 Python 파일이며 프로젝트의 기본 파일입니다.
  4. ui.glade(파일): 그래픽 사용자 인터페이스 파일입니다. Glade를 사용하여 애플리케이션의 인터페이스를 만든 경우 이 파일을
    당신의 프로젝트.
  5. bMyprogram.desktop (파일): 애플리케이션 메뉴에 애플리케이션을 표시하는 역할을 하는 파일입니다.
  6. setup.py(파일): 이 파일은 Python 프로그램을 로컬 시스템에 설치하는 역할을 하며, 모든 Python 프로그램에서 매우 중요하며, 다른 많은 사용 방법도 있습니다.

물론입니다. 프로젝트에 포함할 수 있는 다른 파일과 폴더가 많이 있지만(사실 원하는 것은 무엇이든 포함할 수 있습니다) 이것이 기본적인 것입니다.

이제 프로젝트 패키징을 시작해 보겠습니다. “myprogram”이라는 새 폴더를 만들고 “myprogram”이라는 파일을 만든 후 다음 코드를 추가합니다.

#!/usr/bin/python 
-*- coding: utf-8 -*- 

## Replace your name and email. 
My Name <[email > 

## Here you must add the license of the file, replace "MyProgram" with your program name. 
License: 
   MyProgram is free software: you can redistribute it and/or modify 
   it under the terms of the GNU General Public License as published by 
   the Free Software Foundation, either version 3 of the License, or 
   (at your option) any later version. 

   MyProgram is distributed in the hope that it will be useful, 
   but WITHOUT ANY WARRANTY; without even the implied warranty of 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
   GNU General Public License for more details. 

   You should have received a copy of the GNU General Public License 
   along with MyProgram.  If not, see <http://www.gnu.org/licenses/>. 

from gi.repository import Gtk 
import os 

class Handler: 
  
  def openterminal(self, button): 
    ## When the user clicks on the first button, the terminal will be opened. 
    os.system("x-terminal-emulator ") 
  
  def closeprogram(self, button): 
    Gtk.main_quit() 
    
Nothing new here.. We just imported the 'ui.glade' file. 
builder = Gtk.Builder() 
builder.add_from_file("/usr/lib/myprogram/ui.glade") 
builder.connect_signals(Handler()) 
window = builder.get_object("window1") 
window.connect("delete-event", Gtk.main_quit) 
window.show_all() 
Gtk.main()

ui.glade 파일을 만들고 이 코드로 채우세요.

<?xml version="1.0" encoding="UTF-8"?> 
<!-- Generated with glade 3.16.1 --> 
<interface> 
  <requires lib="gtk+" version="3.10"/> 
  <object class="GtkWindow" id="window1"> 
    <property name="can_focus">False</property> 
    <property name="title" translatable="yes">My Program</property> 
    <property name="window_position">center</property> 
    <property name="icon_name">applications-utilities</property> 
    <property name="gravity">center</property> 
    <child> 
      <object class="GtkBox" id="box1"> 
        <property name="visible">True</property> 
        <property name="can_focus">False</property> 
        <property name="margin_left">5</property> 
        <property name="margin_right">5</property> 
        <property name="margin_top">5</property> 
        <property name="margin_bottom">5</property> 
        <property name="orientation">vertical</property> 
        <property name="homogeneous">True</property> 
        <child> 
          <object class="GtkLabel" id="label1"> 
            <property name="visible">True</property> 
            <property name="can_focus">False</property> 
            <property name="label" translatable="yes">Welcome to this Test Program !</property> 
          </object> 
          <packing> 
            <property name="expand">False</property> 
            <property name="fill">True</property> 
            <property name="position">0</property> 
          </packing> 
        </child> 
        <child> 
          <object class="GtkButton" id="button2"> 
            <property name="label" translatable="yes">Click on me to open the Terminal</property> 
            <property name="visible">True</property> 
            <property name="can_focus">True</property> 
            <property name="receives_default">True</property> 
            <signal name="clicked" handler="openterminal" swapped="no"/> 
          </object> 
          <packing> 
            <property name="expand">False</property> 
            <property name="fill">True</property> 
            <property name="position">1</property> 
          </packing> 
        </child> 
        <child> 
          <object class="GtkButton" id="button3"> 
            <property name="label">gtk-preferences</property> 
            <property name="visible">True</property> 
            <property name="can_focus">True</property> 
            <property name="receives_default">True</property> 
            <property name="use_stock">True</property> 
          </object> 
          <packing> 
            <property name="expand">False</property> 
            <property name="fill">True</property> 
            <property name="position">2</property> 
          </packing> 
        </child> 
        <child> 
          <object class="GtkButton" id="button4"> 
            <property name="label">gtk-about</property> 
            <property name="visible">True</property> 
            <property name="can_focus">True</property> 
            <property name="receives_default">True</property> 
            <property name="use_stock">True</property> 
          </object> 
          <packing> 
            <property name="expand">False</property> 
            <property name="fill">True</property> 
            <property name="position">3</property> 
          </packing> 
        </child> 
        <child> 
          <object class="GtkButton" id="button1"> 
            <property name="label">gtk-close</property> 
            <property name="visible">True</property> 
            <property name="can_focus">True</property> 
            <property name="receives_default">True</property> 
            <property name="use_stock">True</property> 
            <signal name="clicked" handler="closeprogram" swapped="no"/> 
          </object> 
          <packing> 
            <property name="expand">False</property> 
            <property name="fill">True</property> 
            <property name="position">4</property> 
          </packing> 
        </child> 
      </object> 
    </child> 
  </object> 
</interface>

지금까지는 새로운 것이 없습니다.. Python 파일과 해당 인터페이스 파일을 만들었습니다. 이제 동일한 폴더에 "setup.py" 파일을 만들고 다음 코드를 추가하세요. 모든 줄은 주석에 설명되어 있습니다.

Here we imported the 'setup' module which allows us to install Python scripts to the local system beside performing some other tasks, you can find the documentation here: https://docs.python.org/2/distutils/apiref.html 
from distutils.core import setup 

setup(name = "myprogram", # Name of the program. 
      version = "1.0", # Version of the program. 
      description = "An easy-to-use web interface to create & share pastes easily", # You don't need any help here. 
      author = "TecMint", # Nor here. 
      author_email = "[email ",# Nor here :D 
      url = "http://example.com", # If you have a website for you program.. put it here. 
      license='GPLv3', # The license of the program. 
      scripts=['myprogram'], # This is the name of the main Python script file, in our case it's "myprogram", it's the file that we added under the "myprogram" folder. 

Here you can choose where do you want to install your files on the local system, the "myprogram" file will be automatically installed in its correct place later, so you have only to choose where do you want to install the optional files that you shape with the Python script 
      data_files = [ ("lib/myprogram", ["ui.glade"]), # This is going to install the "ui.glade" file under the /usr/lib/myprogram path. 
                     ("share/applications", ["myprogram.desktop"]) ] ) # And this is going to install the .desktop file under the /usr/share/applications folder, all the folder are automatically installed under the /usr folder in your root partition, you don't need to add "/usr/ to the path. 

이제 같은 폴더에 "myprogram.desktop" 파일을 만들고 다음 코드를 추가하세요. 설명에도 설명되어 있습니다.

This is the .desktop file, this file is the responsible file about showing your application in the applications menu in any desktop interface, it's important to add this file to your project, you can view more details about this file from here: https://developer.gnome.org/integration-guide/stable/desktop-files.html.en 
[Desktop Entry] 
The default name of the program. 
Name=My Program 
The name of the program in the Arabic language, this name will be used to display the application under the applications menu when the default language of the system is Arabic, use the languages codes to change the name for each language. 
Name[ar]=برنامجي 
Description of the file. 
Comment=A simple test program developed by me. 
Description of the file in Arabic. 
Comment[ar]=برنامج تجريبي بسيط تم تطويره بواسطتي. 
The command that's going to be executed when the application is launched from the applications menu, you can enter the name of the Python script or the full path if you want like /usr/bin/myprogram 
Exec=myprogram 
Do you want to run your program from the terminal? 
Terminal=false 
Leave this like that. 
Type=Application 
Enter the name of the icon you want to use for the application, you can enter a path for the icon as well like /usr/share/pixmaps/icon.png but make sure to include the icon.png file in your project folder first and in the setup.py file as well. Here we'll use the "system" icon for now. 
Icon=system 
The category of the file, you can view the available categories from the freedesktop website.
Categories=GNOME;GTK;Utility; 
StartupNotify=false 

이제 거의 끝났습니다.. "dpkg"용 패키지에 대한 정보를 제공하기 위해 "debian" 폴더 아래에 몇 가지 작은 파일을 생성하면 됩니다. 체계.

debian ” 폴더를 열고 다음 파일을 만듭니다.

control
compat
changelog
rules

control: 이 파일은 데비안 패키지에 대한 기본 정보를 제공합니다. 자세한 내용은 데비안 패키지 제어 필드를 참조하세요.

Source: myprogram
Maintainer: My Name <[email > 
Section: utils 
Priority: optional 
Standards-Version: 3.9.2 
Build-Depends: debhelper (>= 9), python2.7 

Package: myprogram 
Architecture: all 
Depends: python-gi 
Description: My Program 
Here you can add a short description about your program.

compat: 이것은 dpkg 시스템에 중요한 파일일 뿐이며 마법의 9 숫자만 포함하고 있으므로 그대로 두십시오.

9

변경 로그: 여기에서 프로그램 변경 사항을 추가할 수 있습니다. 자세한 내용은 데비안 패키지 변경 로그 소스를 방문하세요.

myprogram (1.0) trusty; urgency=medium 

  * Add the new features here. 
  * Continue adding new changes here. 
  * And here. 

 -- My Name Here <[email >  Sat, 27 Dec 2014 21:36:33 +0200

규칙: 이 파일은 패키지를 설치하기 위해 로컬 시스템에서 설치 프로세스를 실행하는 역할을 담당합니다. 자세한 정보를 볼 수 있습니다.
이 파일에 대한 정보는 데비안 패키지 기본 규칙에서 확인하세요.

Python 프로그램에는 더 이상 아무것도 필요하지 않습니다.

#!/usr/bin/make -f 
This file is responsible about running the installation process on the local machine to install the package, you can view more information about this file from here: https://www.debian.org/doc/manuals/maint-guide/dreq.en.html#defaultrules Though you won't need anything more for your Python program. 
%: 
    dh $@ 
override_dh_auto_install: 
    python setup.py install --root=debian/myprogram --install-layout=deb --install-scripts=/usr/bin/ # This is going to run the setup.py file to install the program as a Python script on the system, it's also going to install the "myprogram" script under /usr/bin/ using the --install-scripts option, DON'T FORGET TO REPLACE "myprogram" WITH YOUR PROGRAM NAME. 
override_dh_auto_build:

이제 프로그램에 필요한 모든 파일을 성공적으로 생성했으니 이제 패키징을 시작해 보겠습니다. 먼저, 시작하기 전에 빌드 프로세스에 대한 일부 종속성을 설치했는지 확인하십시오.

sudo apt-get update
sudo apt-get install devscripts

이제 “myprogram” 폴더가 홈 폴더(/home/user/myprogram)에 있다고 가정하고 데비안 패키지로 패키징하려면 다음 명령을 실행하세요.

cd /home/user/myprogram
debuild -us -uc
샘플 출력
hanny@hanny-HP-Pavilion-15-Notebook-PC:~/Projects/myprogram$
debuild -us -uc dpkg-buildpackage -rfakeroot -D -us -uc
dpkg-buildpackage: source package myprogram
dpkg-buildpackage: source version 1.0
dpkg-buildpackage: source distribution trusty
dpkg-buildpackage: source changed by My Name Here
<[email >
dpkg-source --before-build myprogram
dpkg-buildpackage: host architecture i386
fakeroot debian/rules clean
dh clean
dh_testdir
dh_auto_clean
....
.....
Finished running lintian.

그리고 그게 다야 ! Debian 패키지가 성공적으로 생성되었습니다:

Debian 기반 배포판에 설치하려면 다음을 실행하세요.

sudo dpkg -i myprogram_1.0_all.deb

위 파일을 패키지 이름으로 바꾸는 것을 잊지 마십시오. 이제 패키지를 설치한 후 응용 프로그램 메뉴에서 프로그램을 실행할 수 있습니다.

그리고 그것은 작동 할 것입니다 ..

여기에서 PyGObject에 관한 시리즈의 네 번째 부분을 마칩니다. 다음 강의에서는 PyGObject 애플리케이션을 쉽게 지역화하는 방법을 설명할 것입니다. 그때까지 계속 지켜봐 주시기 바랍니다…