/usr/share/xubuntu/templates/xdg-xubuntu-templates is in xubuntu-default-settings 18.04.6.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | #!/usr/bin/python3
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
# Copyright (C) 2017 Sean Davis <bluesabre@ubuntu.com>
#
# 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 warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, 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 <https://www.gnu.org/licenses/>.
import os
import subprocess
import shutil
from locale import gettext as _
config_dir = os.path.join(
os.getenv('XDG_CONFIG_HOME', os.path.expanduser("~/.config/")), "xubuntu")
config_file = "xdg-xubuntu-templates.cfg"
source_directory = "/usr/share/xubuntu/templates/"
templates = {
"OpenDocument Text.odt": _("OpenDocument Text"),
"OpenDocument Spreadsheet.ods": _("OpenDocument Spreadsheet"),
"Plain Text.txt": _("Plain Text"),
}
def get_template_directory():
templates = subprocess.check_output(["xdg-user-dir", "TEMPLATES"]).strip()
templates = templates.decode("utf-8")
home = os.path.expanduser("~")
if home != templates:
return templates
if os.path.exists(templates):
return templates
return False
def read_config():
global config_dir
global config_file
filename = os.path.join(config_dir, config_file)
created = []
if os.path.exists(filename):
# LP: #1668191, force UTF-8 encoding; ignore further encoding errors
with open(filename, 'r', encoding='utf-8', errors='ignore') as config:
for line in config.readlines():
created.append(line.strip())
print("Already created: " + ", ".join(created))
return created
def write_config(created):
global config_dir
global config_file
filename = os.path.join(config_dir, config_file)
try:
if not os.path.exists(config_dir):
os.makedirs(config_dir)
with open(filename, 'w') as config:
for template in created:
config.write(template + "\n")
except PermissionError:
print("Unable to write config to %s" % filename)
previous = read_config()
created = previous
template_dir = get_template_directory()
if template_dir:
print("Found template directory: '%s'" % template_dir)
for filename in templates.keys():
if filename in previous:
print("'%s' already created" % filename)
continue
print("Copying template file: '%s'" % filename)
extension = os.path.splitext(filename)[1]
source_filename = os.path.join(source_directory, filename)
if not os.path.exists(source_filename):
print("'%s' does not exist" % source_filename)
continue
target_filename = templates[filename] + extension
target_filename = os.path.join(template_dir, target_filename)
if os.path.exists(target_filename):
print("'%s' already exists" % target_filename)
continue
print("%s => %s" % (source_filename, target_filename))
try:
shutil.copy2(source_filename, target_filename)
created.append(filename)
except FileNotFoundError as not_found:
# LP: #1694471
print("'%s' not found" % not_found.filename)
write_config(created)
|