~ubuntu-branches/ubuntu/natty/quickly/natty

« back to all changes in this revision

Viewing changes to data/templates/ubuntu-project/create.py

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-07-24 18:16:30 UTC
  • Revision ID: james.westby@ubuntu.com-20090724181630-s2wo7hvahk8u0hqb
Tags: 0.1
Initial release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# Copyright 2009 Canonical Ltd.
 
3
# Author 2009 Didier Roche
 
4
#
 
5
# This file is part of Quickly ubuntu-project-template
 
6
#
 
7
#This program is free software: you can redistribute it and/or modify it 
 
8
#under the terms of the GNU General Public License version 3, as published 
 
9
#by the Free Software Foundation.
 
10
 
 
11
#This program is distributed in the hope that it will be useful, but 
 
12
#WITHOUT ANY WARRANTY; without even the implied warranties of 
 
13
#MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
 
14
#PURPOSE.  See the GNU General Public License for more details.
 
15
 
 
16
#You should have received a copy of the GNU General Public License along 
 
17
#with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
"""
 
19
Usage:
 
20
$quickly create ubuntu-project path/to/project_name
 
21
 
 
22
where "project_name" is one or more words separated by an underscore and
 
23
path/to can be any existing path.
 
24
 
 
25
This will create and run a new project, including Python code, 
 
26
Glade files, and packaging files to make the project work. After
 
27
creating the project, get started by:
 
28
 
 
29
1. Changing your working directory to the new project:
 
30
$cd path/to/project_name
 
31
 
 
32
2. Edit the UI with Glade:
 
33
$quickly glade
 
34
 
 
35
3. Edit the Python code:
 
36
$quickly edit
 
37
 
 
38
"""
 
39
 
 
40
import sys
 
41
import os
 
42
import shutil
 
43
import subprocess
 
44
 
 
45
from quickly import tools
 
46
from internal import quicklyutils
 
47
 
 
48
import gettext
 
49
from gettext import gettext as _
 
50
 
 
51
 
 
52
# set domain text
 
53
gettext.textdomain('quickly')
 
54
 
 
55
# get origin path
 
56
pathname = os.path.dirname(__file__)
 
57
abs_path = os.path.abspath(pathname) + "/"
 
58
 
 
59
 
 
60
# get the name of the project
 
61
if len(sys.argv)< 2:
 
62
    print _("""
 
63
ERROR: project name not defined. Usage is project_name""")
 
64
    sys.exit(1)
 
65
 
 
66
path_and_project = sys.argv[1].split('/')
 
67
project_name = path_and_project[-1]
 
68
 
 
69
# check that project name follow quickly rules and reformat it.
 
70
project_name = tools.quickly_name(project_name)
 
71
 
 
72
# create additional directories
 
73
data_dir = "data"
 
74
print _("Creating project directory %s") % data_dir
 
75
os.mkdir(data_dir)
 
76
print _("Directory %s created\n") % data_dir
 
77
 
 
78
python_dir = project_name
 
79
print _("Creating project directory %s") % python_dir
 
80
os.mkdir(python_dir)
 
81
print _("Directory %s created\n") % python_dir
 
82
 
 
83
bin_dir = "bin"
 
84
print _("Creating project directory %s") % bin_dir
 
85
os.mkdir(bin_dir)
 
86
print _("Directory %s created\n") % bin_dir
 
87
 
 
88
sentence_name, camel_case_name = quicklyutils.conventional_names(project_name)
 
89
 
 
90
# copy files
 
91
template_ui_dir = abs_path + "data/ui/"
 
92
target_ui_dir = "data/ui"
 
93
os.mkdir(target_ui_dir)
 
94
 
 
95
substitutions = (("project_name",project_name),
 
96
            ("camel_case_name",camel_case_name),
 
97
            ("sentence_name",sentence_name),)
 
98
 
 
99
 
 
100
# create the files for glade to use
 
101
quicklyutils.file_from_template(template_ui_dir, "camel_case_nameWindow.ui", target_ui_dir, substitutions)
 
102
quicklyutils.file_from_template(template_ui_dir, "project_name_window.xml", target_ui_dir, substitutions)
 
103
quicklyutils.file_from_template(template_ui_dir, "Aboutcamel_case_nameDialog.ui", target_ui_dir, substitutions)
 
104
quicklyutils.file_from_template(template_ui_dir, "about_project_name_dialog.xml", target_ui_dir, substitutions)
 
105
quicklyutils.file_from_template(template_ui_dir, "Preferencescamel_case_nameDialog.ui", target_ui_dir, substitutions)
 
106
quicklyutils.file_from_template(template_ui_dir, "preferences_project_name_dialog.xml", target_ui_dir, substitutions)
 
107
 
 
108
# create the python directory and files
 
109
template_python_dir = abs_path + "python/"
 
110
target_python_dir = project_name
 
111
quicklyutils.file_from_template(template_python_dir, "Aboutcamel_case_nameDialog.py", target_python_dir, substitutions)
 
112
quicklyutils.file_from_template(template_python_dir, "Preferencescamel_case_nameDialog.py", target_python_dir, substitutions)
 
113
quicklyutils.file_from_template(template_python_dir, "project_nameconfig.py", target_python_dir, substitutions)
 
114
 
 
115
# copy the files needed for packaging
 
116
quicklyutils.file_from_template(abs_path, "project_root/setup.py", ".", substitutions)
 
117
quicklyutils.file_from_template(template_python_dir, "__init__.py", target_python_dir)
 
118
 
 
119
# create the media directory, and copy them
 
120
template_media_dir = abs_path + "data/media"
 
121
target_media_dir = "data/media"
 
122
shutil.copytree(template_media_dir,target_media_dir)
 
123
 
 
124
# copy the desktop file
 
125
quicklyutils.file_from_template(abs_path ,"project_root/project_name.desktop.in",".", substitutions)
 
126
 
 
127
# copy the executable file, set the mode to executable
 
128
quicklyutils.file_from_template(abs_path ,"bin/project_name","bin", substitutions)
 
129
os.chmod("bin/" + project_name, 0755)
 
130
 
 
131
# copy the licence file
 
132
quicklyutils.file_from_template(abs_path ,"project_root/Copyright",".", substitutions)
 
133
 
 
134
# add it to revision control
 
135
print _("Creating bzr repository and commiting")
 
136
subprocess.call(["bzr", "init"])
 
137
subprocess.call(["bzr", "add"])
 
138
subprocess.call(["bzr", "commit", "-m", "Initial project creation with Quickly!"])
 
139
 
 
140
# run the new application
 
141
print _("Launching your newly created project!")
 
142
subprocess.call(['./' + project_name], cwd='bin/')
 
143
 
 
144
# put project name in setup.py
 
145
quicklyutils.set_setup_value('name', project_name)
 
146
 
 
147
print _("Congrats, your new project is setup! cd %s/ to start hacking. Then '$ quickly help' for quickly tutorial and reference") % os.getcwd()
 
148
 
 
149
sys.exit(0)
 
150