Module: CovaIO

Included in:
Cova
Defined in:
lib/covaio.rb

Instance Method Summary collapse

Instance Method Details

#_io_app_exists(name) ⇒ Object



85
86
87
# File 'lib/covaio.rb', line 85

def _io_app_exists(name)
	return File.directory?(@dir_cova_apps_home + "/" + name)
end

#_io_clone_repo(repo, dir) ⇒ Object



110
111
112
113
114
115
116
117
118
119
# File 'lib/covaio.rb', line 110

def _io_clone_repo (repo, dir)
	pwd = Dir.pwd
	Dir.chdir(dir)
	_io_exec "git clone #{repo}"
	reponame = File.basename(repo, ".*")
	Dir.chdir(reponame)
	#_io_exec "git remote add upstream #{repo}"
	#Dir.chdir(pwd)
	return _io_isdir(dir + "/" + reponame)
end

#_io_cpdir(src, targ) ⇒ Object



143
144
145
146
147
148
149
# File 'lib/covaio.rb', line 143

def _io_cpdir(src, targ)
	if _io_isdir src and not _io_isdir targ, false
		`cp -r #{src} #{targ}`
		return _io_isdir targ
	end
	return false
end

#_io_cpfile(src, targ) ⇒ Object



151
152
153
154
155
156
157
# File 'lib/covaio.rb', line 151

def _io_cpfile(src, targ)
	if _io_isfile src and not _io_isfile targ, false
		`cp #{src} #{targ}`
		return _io_isfile targ
	end
	return false
end

#_io_exec(cmd) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/covaio.rb', line 17

def _io_exec(cmd)
	pipe = IO.popen(cmd)
	puts cmd
	while (line = pipe.gets)
	  print line		
	end
end

#_io_exec_xctool(cmd = "build", config = "Debug", sdk = "iphonesimulator") ⇒ Object



46
47
48
# File 'lib/covaio.rb', line 46

def _io_exec_xctool(cmd="build", config="Debug", sdk="iphonesimulator")
	_io_exec @dir_xctool_home + "/xctool.sh -workspace cova.xcworkspace -scheme Cova -configuration #{config} -sdk #{sdk} #{cmd}"
end

#_io_findport(port) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/covaio.rb', line 25

def _io_findport(port)
	ok = false
	times = 100
	until ok
		begin
			if times <= 0
				port = -1
				ok = true
			else
		    	socket = TCPSocket.new "localhost", port
				socket.close
				port = port + 1
				times = times - 1
			end
        rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT
        	ok = true
        end
       end
       return port
end

#_io_initObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/covaio.rb', line 3

def _io_init
	@dir_user_home 			= File.expand_path("~")
	@dir_cova_home 			= File.expand_path("~/.cova")
	@dir_cova_ios_mods_home = File.expand_path("~/.cocoapods/cova")
	@dir_cocoapods_home 	= File.expand_path("~/.cocoapods")
	@dir_xctool_home 		= File.expand_path("~/.cova/xctool")
	@dir_xcode_build_home 	= File.expand_path("~/Library/Developer/Xcode/DerivedData")
	@dir_cova_apps_home 	= File.expand_path("~/.cova/apps")

	@repo_cova 			    = "git://github.com/dancali/cova.git"
	@repo_cova_ios_mods		= "git://github.com/dancali/cova-ios-mods.git"
	@repo_xctool			= "git://github.com/facebook/xctool.git"
end

#_io_isdir(dir, expected = true) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/covaio.rb', line 55

def _io_isdir(dir,expected=true)
	_log_line (expected ? "Expecting #{dir} to exist" : "Ensuring #{dir} does not exist")
	if File.directory?(dir)
		expected ? _log_line_ok : _log_line_error
  		return true
  	end		  	

  	if expected
	  	_log_line_error
	else
		_log_line_ok
	end
  	return false
end

#_io_isfile(file, expected = true) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/covaio.rb', line 70

def _io_isfile(file,expected=true)
	_log_line (expected ? "Expecting #{file} to exist" : "Ensuring #{file} does not exist")
	if File.exist?(file)
		expected ? _log_line_ok : _log_line_error
  		return true
  	end		  	

  	if expected
	  	_log_line_error
	else
		_log_line_ok
	end
  	return false
end

#_io_lndir(src, targ) ⇒ Object



134
135
136
137
138
139
140
141
# File 'lib/covaio.rb', line 134

def _io_lndir(src, targ)
	if _io_isdir src and not _io_isdir targ, false
		`ln -s #{src} #{targ}`
		return _io_isdir targ
	end

	return false
end

#_io_ls(dir) ⇒ Object



106
107
108
# File 'lib/covaio.rb', line 106

def _io_ls(dir)
	Dir.foreach(dir) {|entry| puts "#{entry}" unless (entry =='.' || entry == '..') }
end

#_io_mkdir(dir) ⇒ Object



159
160
161
162
163
164
165
166
167
168
# File 'lib/covaio.rb', line 159

def _io_mkdir(dir)
	if File.directory?(dir)
		return true
	end
	
	_log_line "Creating #{dir}"
	`mkdir #{dir}`
	File.directory?(dir) ? _log_line_ok : _log_line_error
	return File.directory?(dir)
end

#_io_open_app_source(name) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/covaio.rb', line 89

def _io_open_app_source(name)
	if not _io_app_exists name
		_log_info "Looks like the app #{name} does not exist. Please create if first."
		_log_line_error
		return false
	end

	app_project = "#{@dir_cova_apps_home}/#{name}/ios/cova.xcworkspace"
	if not File.exist?(app_project)
		_log_info "Looks like the app #{name} was never build. Please build it first."
		return false
	end

	_io_exec "open #{app_project}"
	return true
end

#_io_pod_add_repo(name, repo) ⇒ Object



50
51
52
53
# File 'lib/covaio.rb', line 50

def _io_pod_add_repo(name, repo)
	_io_exec("pod repo add #{name} #{repo}")
	return _io_isdir(@dir_cocoapods_home + "/" + name)
end

#_io_rmdir(dir) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/covaio.rb', line 121

def _io_rmdir(dir)
	_log_line "Removing #{dir}"
	if File.directory?(dir)
		`rm -rf #{dir}`
	  	if File.directory?(dir)
	  		_log_line_error
	  		return false
		end
	end
	_log_line_ok
	return true
end