-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.php
More file actions
106 lines (89 loc) · 3.37 KB
/
create.php
File metadata and controls
106 lines (89 loc) · 3.37 KB
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
<?php
class Project {
protected $project_name = '';
protected $projects_folder = '';
protected $ps = '\\'; // path separator
protected $work_dir = 'work';
protected $task_dir = 'task';
protected $folders_to_create = array();
protected $texteditor = '';
protected $keepass = '';
protected $keepass_database = '';
public function __construct($project_name) {
if (!$project_name) die('Empty project name!');
$this->loadConfig('config.ini');
$this->project_name = trim($project_name, $this->ps);
$this->project_path = $this->projects_folder . $this->ps . $this->project_name;
$this->folders_to_create = array($this->work_dir, $this->task_dir, 'backup', 'backup' . $this->ps . 'real', 'backup' . $this->ps . 'test', 'doc');
}
public function create() {
if (!is_dir($this->projects_folder)) $this->createDir($this->projects_folder);
if (is_dir($this->project_path)) die("Project '$this->project_name' allready exists!");
$this->createDir($this->project_path);
chdir($this->project_path);
array_map(array($this, 'createDir'), $this->folders_to_create);
if (strpos($this->texteditor, 'sublime') !== false) {
exec('"' . $this->texteditor. '" "' . $this->createSublimeProject() .'"');
$this->createFPTSyncSettings();
}
$this->createTxtFile($this->task_dir . $this->ps . 'jira.txt');
$this->createTxtFile($this->task_dir . $this->ps . 'task.txt');
$this->gitInit();
$this->createKeepassEntrie();
}
protected function gitInit() {
chdir($this->work_dir);
$gitIgnore = '.gitignore';
$this->createTxtFile($gitIgnore, ".gitignore\nftpsync.settings");
exec("git init");
chdir($this->project_path);
}
protected function createSublimeProject() {
$sublime_project_file = array(
'folders' => array(
array('path' => $this->work_dir),
array('path' => $this->task_dir),
)
);
$sublime_project_file_path = "$this->project_name.sublime-project";
$this->createTxtFile($sublime_project_file_path, json_encode($sublime_project_file, JSON_PRETTY_PRINT));
return $sublime_project_file_path;
}
protected function createFPTSyncSettings() {
chdir($this->work_dir);
$sublime_ftpsync = array($this->project_name => array(
'host' => '', 'username' => '', 'password' => null, 'path' => '', 'upload_on_save' => true, 'tls' => true)
);
$this->createTxtFile('ftpsync.settings', json_encode($sublime_ftpsync, JSON_PRETTY_PRINT));
chdir($this->project_path);
}
protected function loadConfig($iniFile) {
$ini = parse_ini_file($iniFile);
foreach ($ini as $key => $value) {
$this->$key = $value;
}
}
protected function createKeepassEntrie() {
if ($this->keepass && $this->keepass_database)
exec("\"$this->keepass\" \"$this->keepass_database\"");
}
protected function createDir($dirname, $recuresive=false) {
$result = mkdir($dirname, 0760, $recuresive);
echo $result ? "Dirictory '$dirname' created\n" : "Cannot create directory: '$dirname'\n";
return $result;
}
protected function createTxtFile($filename, $content='') {
if ( ($fp = fopen($filename, 'a')) === false ) {
echo "Cannot create file: '$filename'\n";
return;
}
fwrite($fp, $content);
fclose($fp);
echo "File $filename created\n";
}
}
echo 'Enter project name: ';
$project_name = trim(fgets(STDIN));
$proj = new Project($project_name);
$proj->create();
?>