Pakkett Applikazzjonijiet u Programmi PyGObject bħala Pakkett .deb għad-Desktop tal-Linux – Parti 4


Inkomplu s-serje ta' programmar PyGObject miegħek fuq id-desktop tal-Linux, fir-4 parti tas-serje aħna nispjegaw kif nippakkjaw il-programmi u l-applikazzjonijiet li ħloqna għall- Desktop Linux juża PyGObject bħala pakkett Debian.

Il-pakketti Debian (.deb) huma l-aktar format użat biex jiġu installati programmi taħt Linux, is-sistema \dpkg” li tittratta l-pakketti .deb hija d-default fid-distribuzzjonijiet kollha tal-Linux ibbażati fuq Debian bħal Ubuntu u Linux Mint. Huwa għalhekk li se nkunu qed nispjegaw biss kif nippakkjaw il-programmi tagħna għal Debian.

Oħloq Pakkett Debian mill-Applikazzjonijiet PyGObject tiegħek

L-ewwel, għandu jkollok xi għarfien bażiku dwar il-ħolqien ta 'pakketti Debian, din il-gwida li ġejja tgħinek ħafna.

  1. Introduzzjoni għall-Ippakkjar Debian

Fil-qosor, jekk għandek proġett imsejjaħ \myprogram” għandu jkun fih il-fajls u l-folders li ġejjin sabiex tkun tista’ tippakkjah.

  1. debian (Folder): Dan il-folder jinkludi l-informazzjoni kollha dwar il-pakkett Debian maqsum f'ħafna sub-fajls.
  2. po (Folder): Il-folder po jinkludi l-fajls tat-traduzzjoni għall-programm (Aħna nispjegawh fil-parti 5).
  3. myprogram (Fajl): Dan huwa l-fajl Python li ħloqna bl-użu ta' PyGObject, huwa l-fajl ewlieni tal-proġett.
  4. ui.glade (Fajl): Il-fajl tal-interface grafika tal-utent.. Jekk ħloqt l-interface tal-applikazzjoni billi tuża Glade, trid tinkludi dan il-fajl fi
    il-proġett tiegħek.
  5. bMyprogram.desktop (Fajl): Dan huwa l-fajl responsabbli biex turi l-applikazzjoni fil-menu tal-applikazzjonijiet.
  6. setup.py (Fajl): Dan il-fajl huwa responsabbli għall-installazzjoni ta' kwalunkwe programm Python fis-sistema lokali, huwa importanti ħafna fi kwalunkwe programm Python, għandu ħafna modi oħra ta' użu wkoll.

Naturalment .. Hemm ħafna fajls u folders oħra li tista 'tinkludi fil-proġett tiegħek (fil-fatt tista' tinkludi kull ħaġa li trid) iżda dawk huma dawk bażiċi.

Issa, ejja nibdew l-ippakkjar ta 'proġett. Oħloq folder ġdid imsejjaħ \myprogram, oħloq fajl imsejjaħ \myprogram” u żid il-kodiċi li ġej miegħu.

#!/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()

Oħloq fajl ui.glade u imla b'dan il-kodiċi.

<?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>

M'hemm xejn ġdid sa issa.. Aħna biss ħloqna fajl Python u l-fajl tal-interface tiegħu. Issa oħloq fajl \setup.py fl-istess folder, u żid il-kodiċi li ġej miegħu, kull linja hija spjegata fil-kummenti.

# 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. 

Issa oħloq fajl \myprogram.desktop fl-istess folder, u żid il-kodiċi li ġej, huwa spjegat ukoll fil-kummenti.

# 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 

Kważi lestejna hawnhekk issa.. Irridu noħolqu biss xi fajls żgħar taħt il-folder \debian” sabiex nipprovdu informazzjoni dwar il-pakkett tagħna għad-\dpkg> sistema.

Iftaħ il-folder \debian”, u oħloq il-fajls li ġejjin.

control
compat
changelog
rules

kontroll: Dan il-fajl jipprovdi l-informazzjoni bażika dwar il-pakkett Debian, għal aktar dettalji, jekk jogħġbok żur Debian Package Control Fields.

Source: myprogram
Maintainer: My Name <myemail[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: Dan huwa biss fajl importanti għas-sistema dpkg, jinkludi biss in-numru 9 maġiku, ħallieh hekk.

9

changelog: Hawnhekk tkun tista' żżid il-bidliet li tagħmel fil-programm tiegħek, għal aktar informazzjoni, jekk jogħġbok żur is-Sors tal-Bidla tal-Pakkett ta' Debian.

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

regoli: Dan il-fajl huwa responsabbli dwar it-tħaddim tal-proċess ta' installazzjoni fuq il-magna lokali biex tinstalla l-pakkett, tista' tara aktar informazzjoni
dwar dan il-fajl minn hawn: Debian Package Default Rules.

Għalkemm ma jkollok bżonn xejn aktar għall-programm Python tiegħek.

#!/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 [email  
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:

Issa ħloqna l-fajls kollha meħtieġa għall-programm tagħna b'suċċess, issa ejja nibdew l-ippakkjar tiegħu. L-ewwel, kun żgur li installajt xi dipendenzi għall-proċess tal-bini qabel tibda.

$ sudo apt-get update
$ sudo apt-get install devscripts

Issa immaġina li l-folder \myprogram” jinsab fil-folder tad-dar tiegħek (/home/user/myprogram) sabiex jippakkjah bħala pakkett Debian, mexxi l-kmandi li ġejjin .

$ cd /home/user/myprogram
$ debuild -us -uc
[email :~/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.

U hekk hu! Il-pakkett Debian tiegħek inħoloq b'suċċess:

Sabiex tinstallah fuq kwalunkwe distribuzzjoni bbażata fuq Debian, mexxi.

$ sudo dpkg -i myprogram_1.0_all.deb

Tinsiex li tissostitwixxi l-fajl ta 'hawn fuq bl-isem tal-pakkett.. Issa wara li tinstalla l-pakkett, tista' tħaddem il-programm mill-menu tal-applikazzjonijiet.

U se taħdem ..

Hawnhekk tintemm ir-4 parti tas-sensiela tagħna dwar PyGObject.. Fil-lezzjoni li jmiss aħna ser nispjegaw kif tiġi lokalizzata l-applikazzjoni PyGObject faċilment, sa mbagħad nibqgħu sintonizzati għaliha...