分析reText的安装目录结构

简介

linux下的markdonw编辑器,使用python3开发

安装

sudo apt-get instal reText

查看安装文件

dpkg -L reText

结果:

/.
/usr
/usr/bin
/usr/share
/usr/share/appdata
/usr/share/appdata/me.mitya57.ReText.appdata.xml
/usr/share/applications
/usr/share/applications/me.mitya57.ReText.desktop
/usr/share/doc
/usr/share/doc/retext
/usr/share/doc/retext/changelog.Debian.gz
/usr/share/doc/retext/changelog.gz
/usr/share/doc/retext/configuration.md
/usr/share/doc/retext/copyright
/usr/share/icons
/usr/share/icons/hicolor
/usr/share/icons/hicolor/128×128
/usr/share/icons/hicolor/128×128/apps
/usr/share/icons/hicolor/128×128/apps/retext.png
/usr/share/icons/hicolor/16×16
/usr/share/icons/hicolor/16×16/apps
/usr/share/icons/hicolor/16×16/apps/retext.png
/usr/share/icons/hicolor/22×22
/usr/share/icons/hicolor/22×22/apps
/usr/share/icons/hicolor/22×22/apps/retext.png
/usr/share/icons/hicolor/24×24
/usr/share/icons/hicolor/24×24/apps
/usr/share/icons/hicolor/24×24/apps/retext.png
/usr/share/icons/hicolor/32×32
/usr/share/icons/hicolor/32×32/apps
/usr/share/icons/hicolor/32×32/apps/retext.png
/usr/share/icons/hicolor/48×48
/usr/share/icons/hicolor/48×48/apps
/usr/share/icons/hicolor/48×48/apps/retext.png
/usr/share/icons/hicolor/scalable
/usr/share/icons/hicolor/scalable/apps
/usr/share/icons/hicolor/scalable/apps/retext.svg
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/retext.1.gz
/usr/share/python3
/usr/share/python3/runtime.d
/usr/share/python3/runtime.d/retext.rtupdate
/usr/share/retext
/usr/share/retext/ReText
/usr/share/retext/ReText/__init__.py
/usr/share/retext/ReText/config.py
/usr/share/retext/ReText/converterprocess.py
/usr/share/retext/ReText/dialogs.py
/usr/share/retext/ReText/editor.py
/usr/share/retext/ReText/fakevimeditor.py
/usr/share/retext/ReText/highlighter.py
/usr/share/retext/ReText/icontheme.py
/usr/share/retext/ReText/mdx_posmap.py
/usr/share/retext/ReText/syncscroll.py
/usr/share/retext/ReText/tab.py
/usr/share/retext/ReText/tablemode.py
/usr/share/retext/ReText/webkitpreview.py
/usr/share/retext/ReText/window.py
/usr/share/retext/ReText/xsettings.py
/usr/share/retext/ReText-6.0.2.egg-info
/usr/share/retext/locale
/usr/share/retext/locale/retext_ca.qm
/usr/share/retext/locale/retext_cs.qm
/usr/share/retext/locale/retext_cy.qm
/usr/share/retext/locale/retext_da.qm
/usr/share/retext/locale/retext_de.qm
/usr/share/retext/locale/retext_es.qm
/usr/share/retext/locale/retext_es_CO.qm
/usr/share/retext/locale/retext_et.qm
/usr/share/retext/locale/retext_eu.qm
/usr/share/retext/locale/retext_fr.qm
/usr/share/retext/locale/retext_hu.qm
/usr/share/retext/locale/retext_it.qm
/usr/share/retext/locale/retext_ja.qm
/usr/share/retext/locale/retext_nl.qm
/usr/share/retext/locale/retext_pl.qm
/usr/share/retext/locale/retext_pt.qm
/usr/share/retext/locale/retext_pt_BR.qm
/usr/share/retext/locale/retext_ru.qm
/usr/share/retext/locale/retext_sk.qm
/usr/share/retext/locale/retext_sr.qm
/usr/share/retext/locale/retext_sr@latin.qm
/usr/share/retext/locale/retext_uk.qm
/usr/share/retext/locale/retext_zh_CN.qm
/usr/share/retext/locale/retext_zh_TW.qm
/usr/share/retext/retext.py
/usr/bin/retext

启动文件

#! /usr/bin/python3
# vim: ts=8:sts=8:sw=8:noexpandtab

# ReText
# Copyright 2011-2015 Dmitry Shachnev
#
# This program 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 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

import multiprocessing as mp
import sys
import signal
import markups
from os import devnull
from os.path import join
from ReText import datadirs, settings, globalSettings, app_version
from ReText.window import ReTextWindow

from PyQt5.QtCore import QFile, QFileInfo, QIODevice, QLibraryInfo, \
 QTextStream, QTranslator
from PyQt5.QtWidgets import QApplication
from PyQt5.QtNetwork import QNetworkProxyFactory

def canonicalize(option):
    if option in ('–preview', '-'):
        return option
    return QFileInfo(option).canonicalFilePath()

def main():
    if markups.__version_tuple__ < (2, ):
        sys.exit('Error: ReText needs PyMarkups 2.0 or newer to run.')

    # If we're running on Windows without a console, then discard stdout
    # and save stderr to a file to facilitate debugging in case of crashes.
    if sys.executable.endswith('pythonw.exe'):
        sys.stdout = open(devnull, 'w')
        sys.stderr = open('stderr.log', 'w')

    app = QApplication(sys.argv)
    app.setOrganizationName("ReText project")
    app.setApplicationName("ReText")
    app.setApplicationDisplayName("ReText")
    app.setApplicationVersion(app_version)
    app.setOrganizationDomain('mitya57.me')
    if hasattr(app, 'setDesktopFileName'): # available since Qt 5.7
        app.setDesktopFileName('me.mitya57.ReText.desktop')
    QNetworkProxyFactory.setUseSystemConfiguration(True)
    RtTranslator = QTranslator()
    for path in datadirs:
        if RtTranslator.load('retext_' + globalSettings.uiLanguage,
                             join(path, 'locale')):
            break
    QtTranslator = QTranslator()
    QtTranslator.load("qtbase_" + globalSettings.uiLanguage,
        QLibraryInfo.location(QLibraryInfo.TranslationsPath))
    app.installTranslator(RtTranslator)
    app.installTranslator(QtTranslator)
    print('Using configuration file:', settings.fileName())
    if globalSettings.appStyleSheet:
        sheetfile = QFile(globalSettings.appStyleSheet)
        sheetfile.open(QIODevice.ReadOnly)
        app.setStyleSheet(QTextStream(sheetfile).readAll())
        sheetfile.close()
    window = ReTextWindow()
    window.show()
    # ReText can change directory when loading files, so we
    # need to have a list of canonical names before loading
    fileNames = list(map(canonicalize, sys.argv[1:]))
    previewMode = False
    readStdIn = False
    for fileName in fileNames:
        if QFile.exists(fileName):
            window.openFileWrapper(fileName)
            if previewMode:
                window.actionPreview.setChecked(True)
                window.preview(True)
        elif fileName == '–preview':
            previewMode = True
        elif fileName == '-':
            readStdIn = True

    inputData = ''
    if readStdIn and sys.stdin is not None:
        inputData = sys.stdin.read()
    if inputData or not window.tabWidget.count():
        window.createNew(inputData)
    signal.signal(signal.SIGINT, lambda sig, frame: window.close())
    sys.exit(app.exec())

if __name__ == '__main__':
    mp.set_start_method('spawn')
    main()


启动文件的本质

ls -l /usr/bin/retext 

lrwxrwxrwx 1 root root 25 7月  10  2017 /usr/bin/retext -> ../share/retext/retext.py

桌面快捷方式

/usr/share/applications/me.mitya57.ReText.desktop
内容

[Desktop Entry]
Version=1.0
Name=ReText
Comment=Simple text editor for Markdown and reStructuredText
Comment[ca]=Editor de Markdown i reStructuredText senzill alhora que potent
Comment[cs]=Jednoduchý editor pro Markdown a reStructuredText
Comment[cy]=Golygydd testun syml ar gyfer Markdown a reStructuredText
Comment[da]=Enkel editor til Markdown og reStructuredText
Comment[de]=Einfacher Texteditor für Markdown und reStructuredText
Comment[es]=Editor básico de texto para Markdown y reStructuredText
Comment[et]=Lihtne tekstiredaktor Markdown ning reStructuredText süntaksitele
Comment[eu]=Markdown et reStructuredText-erako editore sinple
Comment[fr]=Éditeur de texte simple pour Markdown et reStructuredText
Comment[hu]=Egyszerű Markdown és reStructuredText szövegszerkesztő
Comment[it]=Semplice editor di testo per Markdown e reStructuredText
Comment[ja]=MarkdownとreStructuredTextのためのシンプルで強力なエディタ
Comment[nl]=Eenvoudige teksteditor voor Markdown en reStructuredText
Comment[pl]=Prosty edytor Markdown i reStructuredText
Comment[pt_BR]=Editor simples para Markdown e reStructuredText
Comment[ru]=Простой редактор для Markdown и reStructuredText
Comment[sr]=Једноставан уређивач за Markdown и reStructuredText
Comment[sr@latin]=Jednostavan uređivač za Markdown i reStructuredText
Comment[uk]=Простий текстовий редактор для Markdown та reStructuredText
Comment[sk]=Jednoduchý textový editor pre Markdown a reStructuredText
Comment[zh_CN]=支持 Markdown 和 reStructuredText 语法的简易文本编辑器
Comment[zh_TW]=簡單高效的 Markdown 與 reStructuredText 編輯器
Categories=Office;WordProcessor;
Exec=retext %F
Type=Application
Icon=retext
MimeType=text/x-markdown;text/x-rst;
Keywords=Text;Editor;Markdown;reStructuredText;
 


 

Author: bkdwei