~xubuntu-dev/xubuntu-default-settings/trunk

« back to all changes in this revision

Viewing changes to usr/share/xubuntu/templates/xdg-xubuntu-templates

  • Committer: Sean Davis
  • Date: 2017-02-15 02:20:43 UTC
  • mto: This revision was merged to the branch mainline in revision 631.
  • Revision ID: smd.seandavis@gmail.com-20170215022043-5hnp6kmzd9yd76ns
Packaging updates for Python, use XDG_CONFIG_HOME, add copyright and fix error handling in xdg-xubuntu-templates

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python3
 
2
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
3
#   Copyright (C) 2017 Sean Davis <bluesabre@ubuntu.com>
 
4
#
 
5
#   This program is free software: you can redistribute it and/or modify it
 
6
#   under the terms of the GNU General Public License as published by
 
7
#   the Free Software Foundation, either version 2 of the License, or
 
8
#   (at your option) any later version.
 
9
#
 
10
#   This program is distributed in the hope that it will be useful, but
 
11
#   WITHOUT ANY WARRANTY; without even the implied warranties of
 
12
#   MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
13
#   PURPOSE.  See the GNU General Public License for more details.
 
14
#
 
15
#   You should have received a copy of the GNU General Public License along
 
16
#   with this program.  If not, see <http://www.gnu.org/licenses/>.
2
17
 
3
18
import os
4
19
import subprocess
6
21
 
7
22
from locale import gettext as _
8
23
 
9
 
config_dir = os.path.expanduser("~/.config/xubuntu/")
 
24
config_dir = os.path.join(
 
25
    os.getenv('XDG_CONFIG_HOME', os.path.expanduser("~/.config/")), "xubuntu")
10
26
config_file = "xdg-xubuntu-templates.cfg"
11
27
 
12
28
source_directory = "/usr/share/xubuntu/templates/"
48
64
    global config_dir
49
65
    global config_file
50
66
 
51
 
    if not os.path.exists(config_dir):
52
 
        os.makedirs(config_dir)
53
 
 
54
67
    filename = os.path.join(config_dir, config_file)
55
68
 
56
 
    with open(filename, 'w') as config:
57
 
        for template in created:
58
 
            config.write(template + "\n")
 
69
    try:
 
70
        if not os.path.exists(config_dir):
 
71
            os.makedirs(config_dir)
59
72
 
 
73
        with open(filename, 'w') as config:
 
74
            for template in created:
 
75
                config.write(template + "\n")
 
76
    except PermissionError:
 
77
        print("Unable to write config to %s" % filename)
60
78
 
61
79
previous = read_config()
62
80
created = previous