arpm 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ module ARPM
2
+ class Config
3
+
4
+ def self.base_directory
5
+ if OS.windows?
6
+ lib_dir = "/My Documents/Arduino/libraries/"
7
+ else OS.mac?
8
+ lib_dir = "/Documents/Arduino/libraries/"
9
+ end
10
+
11
+ base = File.expand_path("~")
12
+
13
+ "#{base}#{lib_dir}"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,33 @@
1
+ module ARPM
2
+ class Libfile
3
+
4
+ attr_accessor :content
5
+
6
+ def initialize(content)
7
+ @content = content
8
+ end
9
+
10
+ def self.location
11
+ Dir.pwd + "/Libfile"
12
+ end
13
+
14
+ def dependencies
15
+
16
+ packages = []
17
+
18
+ content.gsub!(/\r\n?/, "\n")
19
+ content.each_line do |line|
20
+
21
+ if line.start_with?('lib')
22
+ elements = line.scan(/"([^"]*)"/) + line.scan(/'([^']*)'/)
23
+ packages << {elements[0][0] => elements[1][0]}
24
+ end
25
+
26
+ end
27
+
28
+ packages
29
+
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,106 @@
1
+ module ARPM
2
+ class List
3
+
4
+ def self.register(package, version)
5
+ # Make sure the list exists
6
+ FileUtils.touch(path) unless File.exists?(path)
7
+
8
+ packages = JSON.parse(File.read(path)) rescue []
9
+
10
+ # Is any version of this pacakge installed?
11
+ if ARPM::List.includes?(package.name)
12
+
13
+ # Is this version already installed?
14
+ unless ARPM::List.includes?(package.name, version)
15
+
16
+ # No it isn't, so add this version to the list
17
+ packages.select { |p| p.keys[0] == package.name }.first[package.name] << version
18
+
19
+ end
20
+
21
+ else
22
+
23
+ # It isn't so add the whole package
24
+ packages << {package.name => [version]}
25
+
26
+ end
27
+
28
+ # Write that shit down
29
+ f = File.open(path, 'w')
30
+ f.write(JSON.generate(packages, :quirks_mode => true))
31
+ f.close
32
+
33
+ end
34
+
35
+ def self.unregister(package, version)
36
+
37
+ packages = JSON.parse(File.read(path)) rescue []
38
+
39
+ # Is any version of this pacakge installed?
40
+ if ARPM::List.includes?(package.name)
41
+ if package.installed_versions.size > 0
42
+
43
+ # Get the remaining versions
44
+ remaining_versions = packages.select { |p| p.keys[0] == package.name }.first[package.name] - [version]
45
+
46
+ packages.select { |p| p.keys[0] == package.name }.first[package.name] = remaining_versions
47
+ else
48
+ packages.delete(package.name)
49
+ end
50
+ end
51
+
52
+ # Write that shit down
53
+ f = File.open(path, 'w')
54
+ f.write(JSON.generate(packages, :quirks_mode => true))
55
+ f.close
56
+
57
+ end
58
+
59
+ def self.includes?(package_name, version = nil)
60
+
61
+ # Get all the packages
62
+ packages = JSON.parse(File.read(path)) rescue []
63
+
64
+ # Search for the specified package
65
+ list_package = packages.select { |p| p.keys[0] == package_name }
66
+
67
+ # Was the version specified?
68
+ if version
69
+
70
+ # Yes, so only return yes if the specified version is installed
71
+ return list_package.first[package_name].include?(version)
72
+
73
+ else
74
+
75
+ # No, so return yes if any versions of the package are installed
76
+ return list_package.first
77
+ end
78
+ end
79
+
80
+ def self.versions(package_name)
81
+ # Get all the packages
82
+ packages = JSON.parse(File.read(path)) rescue []
83
+
84
+ # Search for the specified package
85
+ list_package = packages.select { |p| p.keys[0] == package_name }.first
86
+
87
+ # Return an array of the versions
88
+ list_package[package_name]
89
+
90
+ end
91
+
92
+ def self.all
93
+ # Get all the packages
94
+ packages = JSON.parse(File.read(path)) rescue []
95
+
96
+ packages
97
+ end
98
+
99
+ private
100
+
101
+ def self.path
102
+ ARPM::Config.base_directory + "/arpm.txt"
103
+ end
104
+
105
+ end
106
+ end
@@ -0,0 +1,17 @@
1
+ module OS
2
+ def OS.windows?
3
+ (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
4
+ end
5
+
6
+ def OS.mac?
7
+ (/darwin/ =~ RUBY_PLATFORM) != nil
8
+ end
9
+
10
+ def OS.unix?
11
+ !OS.windows?
12
+ end
13
+
14
+ def OS.linux?
15
+ OS.unix? and not OS.mac?
16
+ end
17
+ end
@@ -0,0 +1,120 @@
1
+ module ARPM
2
+ class Package
3
+
4
+ attr_accessor :name
5
+ attr_accessor :authors
6
+ attr_accessor :versions
7
+ attr_accessor :repository
8
+
9
+ def initialize(opts = {})
10
+ opts.each { |k,v| instance_variable_set("@#{k}", v) }
11
+ end
12
+
13
+ # Search for a new package
14
+ def self.search(name, exact_match = true)
15
+
16
+ # Grab the package list
17
+ data = URI.parse("https://raw.githubusercontent.com/alfo/arpm/master/packages.json").read
18
+ packages = JSON.parse(data)
19
+
20
+ if exact_match
21
+
22
+ # Search the packages for one with the same name
23
+ remote_packages = packages.select { |p| p['name'] == name }
24
+
25
+ else
26
+
27
+ # Search for packages with similar names and return them
28
+ remote_packages = packages.select { |p| p['name'].include? name }
29
+
30
+ end
31
+
32
+ # Did the search return any results?
33
+ if remote_packages.any?
34
+
35
+ packages = []
36
+ remote_packages.each do |remote_package|
37
+
38
+ # Get a list of tags from the remote repo
39
+ tags = Git::Lib.new.ls_remote(remote_package["repository"])["tags"]
40
+
41
+ # Delete any tags that aren't version numbers
42
+ tags.each { |t| tags.delete(t) unless t[0].is_number? }
43
+
44
+ # Sort the tags newest to oldest
45
+ versions = Hash[tags.sort.reverse]
46
+
47
+ # Create a new package object and return it
48
+ packages << Package.new(:name => remote_package["name"],
49
+ :authors => remote_package["authors"],
50
+ :repository => remote_package["repository"],
51
+ :versions => versions)
52
+
53
+ end
54
+
55
+ if exact_match
56
+ return packages.first
57
+ else
58
+ return packages
59
+ end
60
+
61
+ else
62
+ # The package doesn't exist, so return false
63
+ false
64
+ end
65
+ end
66
+
67
+ def latest_version
68
+ if versions.kind_of?(Array)
69
+ versions.first
70
+ else
71
+ versions.keys.first.to_s
72
+ end
73
+ end
74
+
75
+ def install_path(version = nil)
76
+
77
+ # Take the latest_version unless it's been specified
78
+ version = latest_version unless version
79
+
80
+ # Creat the install path
81
+ path = ARPM::Config.base_directory + name
82
+
83
+ # Arduino doesn't like dots or dashes in library names
84
+ path = path + "_#{version.gsub('.', '_')}"
85
+
86
+ end
87
+
88
+ def install(version)
89
+ # Clone the repository!
90
+ repo = Git.clone(repository, install_path(version))
91
+
92
+ # It does, so checkout the right version
93
+ repo.checkout("tags/#{version}")
94
+
95
+ # Register the package to the list
96
+ register(version)
97
+ end
98
+
99
+ def uninstall(version)
100
+ # Remove the files
101
+ FileUtils.rm_r(install_path(version)) rescue ""
102
+
103
+ # Unregister it
104
+ unregister(version)
105
+ end
106
+
107
+ def register(version)
108
+ ARPM::List.register(self, version)
109
+ end
110
+
111
+ def unregister(version)
112
+ ARPM::List.unregister(self, version)
113
+ end
114
+
115
+ def installed_versions
116
+ ARPM::List.versions(self.name)
117
+ end
118
+
119
+ end
120
+ end
@@ -0,0 +1,24 @@
1
+ class String
2
+ def black; "\033[30m#{self}\033[0m" end
3
+ def red; "\033[31m#{self}\033[0m" end
4
+ def green; "\033[32m#{self}\033[0m" end
5
+ def brown; "\033[33m#{self}\033[0m" end
6
+ def blue; "\033[34m#{self}\033[0m" end
7
+ def magenta; "\033[35m#{self}\033[0m" end
8
+ def cyan; "\033[36m#{self}\033[0m" end
9
+ def gray; "\033[37m#{self}\033[0m" end
10
+ def bg_black; "\033[40m#{self}\0330m" end
11
+ def bg_red; "\033[41m#{self}\033[0m" end
12
+ def bg_green; "\033[42m#{self}\033[0m" end
13
+ def bg_brown; "\033[43m#{self}\033[0m" end
14
+ def bg_blue; "\033[44m#{self}\033[0m" end
15
+ def bg_magenta; "\033[45m#{self}\033[0m" end
16
+ def bg_cyan; "\033[46m#{self}\033[0m" end
17
+ def bg_gray; "\033[47m#{self}\033[0m" end
18
+ def bold; "\033[1m#{self}\033[22m" end
19
+ def reverse_color; "\033[7m#{self}\033[27m" end
20
+
21
+ def is_number?
22
+ true if Float(self) rescue false
23
+ end
24
+ end
@@ -0,0 +1,148 @@
1
+ # Add the directory containing this file to the start of the load path if it
2
+ # isn't there already.
3
+ $:.unshift(File.dirname(__FILE__)) unless
4
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
5
+
6
+ require 'git/author'
7
+ require 'git/base'
8
+ require 'git/branch'
9
+ require 'git/branches'
10
+ require 'git/diff'
11
+ require 'git/index'
12
+ require 'git/lib'
13
+ require 'git/log'
14
+ require 'git/object'
15
+ require 'git/path'
16
+ require 'git/remote'
17
+ require 'git/repository'
18
+ require 'git/status'
19
+ require 'git/stash'
20
+ require 'git/stashes'
21
+ require 'git/working_directory'
22
+
23
+ lib = Git::Lib.new(nil, nil)
24
+ unless lib.meets_required_version?
25
+ $stderr.puts "[WARNING] The git gem requires git #{lib.required_command_version.join('.')} or later, but only found #{lib.current_command_version.join('.')}. You should probably upgrade."
26
+ end
27
+
28
+ # Git/Ruby Library
29
+ #
30
+ # This provides bindings for working with git in complex
31
+ # interactions, including branching and merging, object
32
+ # inspection and manipulation, history, patch generation
33
+ # and more. You should be able to do most fundamental git
34
+ # operations with this library.
35
+ #
36
+ # This module provides the basic functions to open a git
37
+ # reference to work with. You can open a working directory,
38
+ # open a bare repository, initialize a new repo or clone an
39
+ # existing remote repository.
40
+ #
41
+ # Author:: Scott Chacon (mailto:schacon@gmail.com)
42
+ # License:: MIT License
43
+ module Git
44
+
45
+ #g.config('user.name', 'Scott Chacon') # sets value
46
+ #g.config('user.email', 'email@email.com') # sets value
47
+ #g.config('user.name') # returns 'Scott Chacon'
48
+ #g.config # returns whole config hash
49
+ def config(name = nil, value = nil)
50
+ lib = Git::Lib.new
51
+ if(name && value)
52
+ # set value
53
+ lib.config_set(name, value)
54
+ elsif (name)
55
+ # return value
56
+ lib.config_get(name)
57
+ else
58
+ # return hash
59
+ lib.config_list
60
+ end
61
+ end
62
+
63
+ def global_config(name = nil, value = nil)
64
+ self.class.global_config(name, value)
65
+ end
66
+
67
+ # open a bare repository
68
+ #
69
+ # this takes the path to a bare git repo
70
+ # it expects not to be able to use a working directory
71
+ # so you can't checkout stuff, commit things, etc.
72
+ # but you can do most read operations
73
+ def self.bare(git_dir, options = {})
74
+ Base.bare(git_dir, options)
75
+ end
76
+
77
+ # clones a remote repository
78
+ #
79
+ # options
80
+ # :bare => true (does a bare clone)
81
+ # :repository => '/path/to/alt_git_dir'
82
+ # :index => '/path/to/alt_index_file'
83
+ #
84
+ # example
85
+ # Git.clone('git://repo.or.cz/rubygit.git', 'clone.git', :bare => true)
86
+ #
87
+ def self.clone(repository, name, options = {})
88
+ Base.clone(repository, name, options)
89
+ end
90
+
91
+ # Export the current HEAD (or a branch, if <tt>options[:branch]</tt>
92
+ # is specified) into the +name+ directory, then remove all traces of git from the
93
+ # directory.
94
+ #
95
+ # See +clone+ for options. Does not obey the <tt>:remote</tt> option,
96
+ # since the .git info will be deleted anyway; always uses the default
97
+ # remote, 'origin.'
98
+ def self.export(repository, name, options = {})
99
+ options.delete(:remote)
100
+ repo = clone(repository, name, {:depth => 1}.merge(options))
101
+ repo.checkout("origin/#{options[:branch]}") if options[:branch]
102
+ Dir.chdir(repo.dir.to_s) { FileUtils.rm_r '.git' }
103
+ end
104
+
105
+ # Same as g.config, but forces it to be at the global level
106
+ #
107
+ #g.config('user.name', 'Scott Chacon') # sets value
108
+ #g.config('user.email', 'email@email.com') # sets value
109
+ #g.config('user.name') # returns 'Scott Chacon'
110
+ #g.config # returns whole config hash
111
+ def self.global_config(name = nil, value = nil)
112
+ lib = Git::Lib.new(nil, nil)
113
+ if(name && value)
114
+ # set value
115
+ lib.global_config_set(name, value)
116
+ elsif (name)
117
+ # return value
118
+ lib.global_config_get(name)
119
+ else
120
+ # return hash
121
+ lib.global_config_list
122
+ end
123
+ end
124
+
125
+ # initialize a new git repository, defaults to the current working directory
126
+ #
127
+ # options
128
+ # :repository => '/path/to/alt_git_dir'
129
+ # :index => '/path/to/alt_index_file'
130
+ def self.init(working_dir = '.', options = {})
131
+ Base.init(working_dir, options)
132
+ end
133
+
134
+ # open an existing git working directory
135
+ #
136
+ # this will most likely be the most common way to create
137
+ # a git reference, referring to a working directory.
138
+ # if not provided in the options, the library will assume
139
+ # your git_dir and index are in the default place (.git/, .git/index)
140
+ #
141
+ # options
142
+ # :repository => '/path/to/alt_git_dir'
143
+ # :index => '/path/to/alt_index_file'
144
+ def self.open(working_dir, options = {})
145
+ Base.open(working_dir, options)
146
+ end
147
+
148
+ end