0.0
== PintosCheck -- Auto Pintos Checker to Save the Day ==
== Functionalities ==
The functionality of this simple script is to download pintos homework assignments from the mail inbox and then run through all the desired tests and finally generate reports in plain text or html formats, all automatically.
== Requirements For Running PintosCheck ==
Since all the scripts are written in ruby, PintosCheck require ruby installed on the system. I use ruby 1.8.7 for development, but ruby 1.9.* versions are expected to function as well. However, ruby 1.8.6 and lower versions are not supported. For information of downloading and installing ruby, see http://www.ruby-lang.org/en/downloads/.
In addition to ruby itself, RubyGems 1.3.* is also required because it hosts the installation source for this project and almost all other ruby projects as well. To download or update RubyGems, please go to http://gemcutter.org/pages/download for more information.
== Installation ==
Once you have all the requirements on your system, it's really easy to install PintosCheck. In the UNIX shell or Windows command line environment, type the following command(sudo if needed):
gem install pintoscheck --include-dependencies
Go grab a cup of coffee, and PintosCheck will automatically download and install itself onto the system.
To check the installation, type 'ptschk --version', and if something like 'PintosCheck 0.1.0' pops up then you're green to go!
== Finally, how do I check my students' pintos homework? ==
This project ships with a 'ptschk' command tool. This tool needs a task configuration file to actually do everything. The configuration file is in YAML format, which is basically a recursive key-value pair representation. If you're using PintosCheck for the first time, there's a very nice command line option to generate the skeleton for you. Just run 'ptschk init my_first_task.config' and a file named 'my_first_task.config' will be generated for you. Inside this file there is a set of the minimal options for the task to run properly, and you just have to fill in what you need. After you set up your configuration file, run 'ptschk run my_first_task.config' and the tasks will kick off immediately, and after a while the report will be generated. A detailed configuration options for advanced task setup will be available in production release of this project.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Activity
0.0
$Id: README.txt 204 2010-11-30 02:20:04Z pwilkins $
sm-transcript reads results of SLS processing and produces transcripts for
the SpokenMedia browser. For each file in the source folder whose extension
matches the source type, a file of destination type is created in the
destination folder. All of these parameters have default values.
Note: Examples of the commands you enter in the terminal are for *nix. The
command prompt in the examples is:
felix$ <command line>
If you are a Windows user, make the usual adjustments.
Requirements:
sm-transcript is written in Ruby and packaged as a RubyGem. Since Ruby is
not a compiled language, you will need to have Ruby installed on your
machine to run sm-transcript. You can determine if Ruby is installed by
typing "ruby -v" at a terminal prompt. It should return the version of
Ruby that is installed. If Ruby is not installed on your machine, navigate
to http://www.ruby-lang.org/ and follow the installation instructions.
sm-transcript was developed using Ruby 1.8. Other Ruby versions have not
been tested as of this release.
Installation:
You can get sm-transcript as either a RubyGem or as source from svn.
The preferred way to install this package is as a Rubygem. You can
download and install the gem with this command:
felix$ sudo gem install [--verbose] sm-transcript
This command downloads the most recent version of the gem from rubygems.org
and makes it active. Previous versions of the gem remain installed, but
are deactivated.
You must use "sudo" to properly install the gem. If you execute "gem
install" (omitting the "sudo") the gem is installed in your home gem
repository and it isn't in your path without additional configuration.
Note: You need sudo privileges to run the command as written. If you
can't sudo, then you can install it locally and will need some additional
configuration. Contact me (or your local Ruby wizard) for assistance.
The executable is now in your path.
You can cleanly uninstall the gem with this command:
felix$ sudo gem uninstall sm-transcript
If you have access to our svn repository, you are welcome to check out the
code. Be warned that the trunk tip is not necessarily stable. It changes
frequently as enhancements (and bug fixes) are added. (note that the
'smb_transcript' in the command line below is not a typo.)
svn co svn+ssh://svn.mit.edu/oeit-tsa/SMB/smb_transcript/trunk sm_transcript
build the gem by running this command from the directory you installed the
source. This is what it looks like on my machine:
felix$ rake gem
The gem will be built and put in ./pkg You can now use the gem
installation instructions above.
Using the App:
Run with no command line parameters, the app reads *.wrd files out of
./results and writes *.t1.html files to ./transcripts. These directories
are relative to where sm_transcript is called.
Note: destination files are overwritten without a warning prompt. If you
want to preserve an existing output file, rename it before running the app
again.
For example, run the app by navigating to the bin folder and enter
projects/sm_transcript/bin felix$ sm_transcript
This command run from this folder will read *.wrd files from bin/results
and write *-t1.html to bin/transcripts.
Usage: sm_transcript [options]
--srcdir PATH Read files from this folder (Default: ./results)
--destdir PATH Write files to this folder (Default: ./transcripts)
--srctype wrd | seg | txt | ttml | srt Kind of file to process (Default: wrd)
--desttype html | ttml | datajs | json Kind of file to output (Default: html)
-h, --help Show this message
There is a serious gotch'a in specifying the srctype parameter: it must
match the case of the file extension that you're processing. This means
that if the srt files that you are processing have the extension .SRT, then
you must specify the srctype as "SRT". Pretty lame, I know. I will update
the gem with a fix shortly. My apologies until then.
Troubleshooting:
sm-transcript requires additional gems to operate. The RubyGem
installation should install dependencies automatically, but when it
doesn't, you get an error that includes
... no such file to load -- builder (LoadError)
in the first few lines when you run sm-transcript, the problem is a
missing dependent gem. (the error above indicates that the Builder
gem is missing.) Try installing the missing gem. For the error above,
the command looks like this on my computer:
felix$ sudo gem install builder
See "Required Gems" below for more information.
A warning message such as:
"WARNING: Nokogiri was built against LibXML version 2.7.6,
but has dynamically loaded 2.7.7""
may be safely ignored.
If you continue to have trouble, feel free to contact me.
Upgrading:
You can easily upgrade by simply executing the same command you used to
install the gem. Running install again will add the newer version and make
it active. By default the most recent version is used, but older versions
are still available, simply inactive.
If are using svn, you should already know what to do.
Required Gems:
builder - create structured data, such as XML
extensions - added for the 'require_relative' command. (To get this
command in Ruby 1.8 you need to install this gem, for Ruby 1.9
the command is already part of the core.)
htmlentities - html parsing
json - create JSON structured data
nokogiri - xml parsing library
optparse - option parsing of command line
ostruct - open data structures
ppcommand - pp is a pretty printer. It is used only for debugging
rake - make for Ruby
rubygems - support for gems (shouldn't be needed for Ruby 1.9)
shoulda - enhancement for Test::Unit
This command installs gems on OSX and Linux:
felix$ sudo gem install <gem name>
I recommend running the following command to update to latest version of
rubygems before loading new gems.
felix$ sudo gem update --system
Unit Tests:
You may run all unit tests by navigating to the test folder and running
rake with no parameters (the default rake task runs all tests). On my
computer, it looks like this:
projects/sm_transcript/test felix$ rake
Release Notes:
Initial Version - runs under Ruby 1.8.x.
version 0.0.4 - fixes bug when processing .WRD files with CRLF line
endings.
version 0.0.5 - removed due to posting error
version 0.0.6 - added srctype of ttml and desttype of json, fixed bug where
beginning time of word was actually for previous word.
version 0.0.7 - added srt as srctype
version 0.0.8 - fixed bug that dropped last phrase from transcripts
version 1.0.0 - declared this version 1.0.0 to conform more closely with
gem numbering conventions. All tests run successfully.
To Do:
- specify individual files for processing rather than folders
- fix bug in srt processing: can't read Creole srt content.
- allow user to modify the "t1" file extension for addition languages of
the same transcript.
- update code to run under Ruby 1.9
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Activity
0.0
# COM #
COM is an object-oriented wrapper around WIN32OLE. COM makes it easy to add
behavior to WIN32OLE objects, making them easier to work with from Ruby.
## Usage ##
Using COM is rather straightforward. There’s basically four concepts to keep
track of:
1. COM objects
2. Instantiable COM objects
3. COM events
4. COM errors
Let’s look at each concept separately, using the following example as a base.
module Word end
class Word::Application < COM::Instantiable
def without_interaction
with_properties('displayalerts' => Word::WdAlertsNone){ yield }
end
def documents
Word::Documents.new(com.documents)
end
def quit(saving = Word::WdDoNotSaveChanges, *args)
com.quit saving, *args
end
end
### COM Objects ###
A COM::Object is a wrapper around a COM object. It provides error
specialization, which is discussed later and a few utility methods. You
typically use it to wrap COM objects that are returned by COM methods. If we
take the example given in the introduction, Word::Documents is a good
candidate:
class Word::Documents < COM::Object
DefaultOpenOptions = {
'confirmconversions' => false,
'readonly' => true,
'addtorecentfiles' => false,
'visible' => false
}.freeze
def open(path, options = {})
options = DefaultOpenOptions.merge(options)
options['filename'] = Pathname(path).to_com
Word::Document.new(com.open(options))
end
end
Here we override the #open method to be a bit easier to use, providing sane
defaults for COM interaction. Worth noting is the use of the #com method to
access the actual COM object to invoke the #open method on it. Also note that
Word::Document is also a COM::Object.
COM::Object provides a convenience method called #with_properties, which is
used in the #without_interaction method above. It lets you set properties on
the COM::Object during the duration of a block, restoring them after it exits
(successfully or with an error).
### Instantiable COM Objects ###
Instantiable COM objects are COM objects that we can connect to and that can be
created. The Word::Application object can, for example, be created.
Instantiable COM objects should inherit from COM::Instantiable. Instantiable
COM objects can be told what program ID to use, whether or not to allow
connecting to an already running object, and to load its associated constants
upon creation.
The program ID is used to determine what instantiable COM object to connect to.
By default the name of the COM::Instantiable class’ name is used, taking the
last two double-colon-separated components and joining them with a dot. For
Word::Application, the program ID is “Word.Application”. The program ID can be
set by using the .program_id method:
class IDontCare::ForConventions < COM::Instantiable
program_id 'Word.Application'
end
The program ID can be accessed with the same method:
Word::Application.program_id # ⇒ 'Word.Application'
Connecting to an already running COM object is not done by default, but is
sometimes desirable: the COM object might take a long time to create, or some
common state needs to be accessed. If the default for a certain instantiable
COM object should be to connect, this can be done using the .connect method:
class Word::Application < COM::Instantiable
connect
end
If no running COM object is available, then a new COM object will be created in
its stead. Whether or not a class uses the connection method can be queried
with the .connect? method:
Word::Application.connect? # ⇒ true
Whether or not to load constants associated with an instantiable COM object is
set with the .constants method:
class Word::Application < COM::Instantiable
constants true
end
and can similarly be checked:
Word::Application.constants? # ⇒ true
Constants are loaded by default.
When an instance of the instantiable COM object is created, a check is run to
see if constants should be loaded and whether or not they already have been
loaded. If they should be loaded and they haven’t already been loaded,
they’re, you guessed it, loaded. The constants are added to the module
containing the COM::Instantiable. Thus, for Word::Application, the Word module
will contain all the constants. Whether or not the constants have already been
loaded can be checked with .constants_loaded?:
Word::Application.constants_loaded # ⇒ false
That concludes the class-level methods.
Let’s begin with the #connected? method among the instance-level methods. This
method queries whether or not this instance connected to an already running COM
object:
Word::Application.new.connected? # ⇒ false
This can be very important in determining how shutdown of a COM object should
be done. If you connected to an already COM object it might be foolish to shut
it down if someone else is using it.
The #initialize method takes a couple of options:
* connect: whether or not to connect to a running instance
* constants: whether or not to load constants
These options will, when given, override the class-level defaults.
### Events ###
COM events are easily dealt with:
class Word::Application < COM::Instantiable
def initialize(options = {})
super
@events = COM::Events.new(com, 'ApplicationEvents',
'OnQuit')
end
def quit(saving = Word::WdDoNotSaveChanges, *args)
@events.observe('OnQuit', proc{ com.quit saving, *args }) do
yield if block_given?
end
end
end
To tell you the truth this API sucks and will most likely be rewritten. The
reason that it is the way it is is that WIN32OLE, which COM wraps, sucks. It’s
event API is horrid and the implementation is buggy. It will keep every
registered event block in memory for ever, freeing neither the blocks nor the
COM objects that yield the events.
### Errors ###
All errors generated by COM methods descend from COM::Error, except for those
cases where a Ruby error already exists. The following HRESULT error codes are
turned into Ruby errors:
HRESULT Error Code | Error Class
-------------------|------------
0x80004001 | NotImplementedError
0x80020005 | TypeError
0x80020006 | NoMethodError
0x8002000e | ArgumentError
0x800401e4 | ArgumentError
There are also a couple of other HRESULT error codes that are turned into more
specific errors than COM::Error:
HRESULT Error Code | Error Class
-------------------|------------
0x80020003 | MemberNotFoundError
0x800401e3 | OperationUnavailableError
Finally, when a method results in any other error, a COM::MethodInvocationError
will be raised, which can be queried for the specifics, specifically #message,
#method, #server, #code, #hresult_code, and #hresult_message.
### Pathname ###
The Pathname object receives an additional method, #to_com. This method is
useful for when you want to pass a Pathname object to a COM method. Simply
call #to_com to turn it into a String of the right encoding for COM:
Word::Application.new.documents.open(Pathname('a.docx').to_com)
# ⇒ Word::Document
## Installation ##
Install COM with
% gem install com
## License ##
You may use, copy and redistribute this library under the same [terms][1] as
Ruby itself.
[1]: http://www.ruby-lang.org/en/LICENSE.txt
## Contributors ##
* Nikolai Weibull
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
0.0
This is an experimental branch that implements a connection pool of
Net::HTTP objects instead of a connection/thread. C/T is fine if
you're only using your http threads to make connections but if you
use them in child threads then I suspect you will have a thread memory
leak. Also, I want to see if I get less connection resets if the
most recently used connection is always returned.
Also added a :force_retry option that if set to true will retry POST
requests as well as idempotent requests.
This branch is currently incompatible with the master branch in the
following ways:
* It doesn't allow you to recreate the Net::HTTP::Persistent object
on the fly. This is possible in the master version since all the
data is kept in thread local storage. For this version, you should
probably create a class instance of the object and use that in your
instance methods.
* It uses a hash in the initialize method. This was easier for me
as I use a HashWithIndifferentAccess created from a YAML file to
define my options. This should probably be modified to check the
arguments to achieve backwards compatibility.
* The method shutdown is unimplemented as I wasn't sure how I should
implement it and I don't need it as I do a graceful shutdown from
nginx to finish up my connections.
For connection issues, I completely recreate a new Net::HTTP instance.
I was running into an issue which I suspect is a JRuby bug where an
SSL connection that times out would leave the ssl context in a frozen
state which would then make that connection unusable so each time that
thread handled a connection a 500 error with the exception "TypeError:
can't modify frozen". I think Joseph West's fork resolves this issue
but I'm paranoid so I recreate the object.
Compatibility with the master version could probably be achieved by
creating a Strategy wrapper class for GenePool and a separate strategy
class with the connection/thread implementation.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Activity
0.0
U
U extends Ruby’s Unicode support. It provides a string class called
U::String with an interface that mimics that of the String class in Ruby 2.0,
but that can also be used from both Ruby 1.8. This interface also has more
complete Unicode support and never modifies the receiver. Thus, a U::String
is an immutable value object.
U comes with complete and very accurate documentation¹. The documentation can
realistically also be used as a reference to the Ruby String API and may
actually be preferable, as it’s a lot more explicit and complete than the
documentation that comes with Ruby.
¹ See http://disu.se/software/u-1.0/api/
§ Installation
Install u with
% gem install u
§ Usage
Usage is basically the following:
require 'u-1.0'
a = 'äbc'
a.upcase # ⇒ 'äBC'
a.u.upcase # ⇒ 'ÄBC'
That is, you require the library, then you invoke #u on a String. This’ll
give you a U::String that has much better Unicode support than a normal
String. It’s important to note that U only uses UTF-8, which means that #u
will try to #encode the String as such. This shouldn’t be an issue in most
cases, as UTF-8 is now more or less the universal encoding – and rightfully
so.
As U::Strings¹ are immutable value objects, there’s also a U::Buffer²
available for building U::Strings efficiently.
See the API³ for more complete usage information. The following sections
will only cover the extensions and differences that U::String exhibit from
Ruby’s built-in String class.
¹ See http://disu.se/software/u-1.0/api/U/String/
² See http://disu.se/software/u-1.0/api/U/Buffer/
³ See http://disu.se/software/u-1.0/api/
§ Unicode Properties
There are quite a few property-checking interrogators that let you check
if all characters in a U::String have the given Unicode property:
• #alnum?¹
• #alpha?²
• #assigned?³
• #case_ignorable?⁴
• #cased?⁵
• #cntrl?⁶
• #defined?⁷
• #digit?⁸
• #graph?⁹
• #newline?¹⁰
• #print?¹¹
• #punct?¹²
• #soft_dotted?¹³
• #space?¹⁴
• #title?¹⁵
• #valid?¹⁶
• #wide?¹⁷
• #wide_cjk?¹⁸
• #xdigit?¹⁹
• #zero_width?²⁰
¹ See http://disu.se/software/u-1.0/api/U/String/#alnum-p-instance-method
² See http://disu.se/software/u-1.0/api/U/String/#alpha-p-instance-method
³ See http://disu.se/software/u-1.0/api/U/String/#assigned-p-instance-method
⁴ See http://disu.se/software/u-1.0/api/U/String/#case_ignorable-p-instance-method
⁵ See http://disu.se/software/u-1.0/api/U/String/#cased-p-instance-method
⁶ See http://disu.se/software/u-1.0/api/U/String/#cntrl-p-instance-method
⁷ See http://disu.se/software/u-1.0/api/U/String/#defined-p-instance-method
⁸ See http://disu.se/software/u-1.0/api/U/String/#digit-p-instance-method
⁹ See http://disu.se/software/u-1.0/api/U/String/#graph-p-instance-method
¹⁰ See http://disu.se/software/u-1.0/api/U/String/#newline-p-instance-method
¹¹ See http://disu.se/software/u-1.0/api/U/String/#print-p-instance-method
¹² See http://disu.se/software/u-1.0/api/U/String/#punct-p-instance-method
¹³ See http://disu.se/software/u-1.0/api/U/String/#soft_dotted-p-instance-method
¹⁴ See http://disu.se/software/u-1.0/api/U/String/#space-p-instance-method
¹⁵ See http://disu.se/software/u-1.0/api/U/String/#title-p-instance-method
¹⁶ See http://disu.se/software/u-1.0/api/U/String/#valid-p-instance-method
¹⁷ See http://disu.se/software/u-1.0/api/U/String/#wide-p-instance-method
¹⁸ See http://disu.se/software/u-1.0/api/U/String/#wide_cjk-p-instance-method
¹⁹ See http://disu.se/software/u-1.0/api/U/String/#xdigit-p-instance-method
²⁰ See http://disu.se/software/u-1.0/api/U/String/#zero_width-p-instance-method
Similar to these methods are
• #folded?¹
• #lower?²
• #upper?³
which check whether a ‹U::String› has been cased in a given manner.
¹ See http://disu.se/software/u-1.0/api/U/String/#folded-p-instance-method
² See http://disu.se/software/u-1.0/api/U/String/#lower-p-instance-method
³ See http://disu.se/software/u-1.0/api/U/String/#upper-p-instance-method
There’s also a #normalized?¹ method that checks whether a ‹U::String› has
been normalized on a given form.
¹ See http://disu.se/software/u-1.0/api/U/String/#normalized-p-instance-method
You can also access certain Unicode properties of the characters of a
U::String:
• #canonical_combining_class¹
• #general_category²
• #grapheme_break³
• #line_break⁴
• #script⁵
• #word_break⁶
¹ See http://disu.se/software/u-1.0/api/U/String/#canonical_combining_class-instance-method
² See http://disu.se/software/u-1.0/api/U/String/#general_category-instance-method
³ See http://disu.se/software/u-1.0/api/U/String/#grapheme_break-instance-method
⁴ See http://disu.se/software/u-1.0/api/U/String/#line_break-instance-method
⁵ See http://disu.se/software/u-1.0/api/U/String/#script-instance-method
⁶ See http://disu.se/software/u-1.0/api/U/String/#word_break-instance-method
§ Locale-specific Comparisons
Comparisons of U::Strings respect the current locale (and also allow you
to specify a locale to use): ‹#<=>›¹, #casecmp², and #collation_key³.
¹ See http://disu.se/software/u-1.0/api/U/String/#comparison-operator
² See http://disu.se/software/u-1.0/api/U/String/#casecmp-instance-method
³ See http://disu.se/software/u-1.0/api/U/String/#collation_key-instance-method
§ Additional Enumerators
There are a couple of additional enumerators in #each_grapheme_cluster¹
and #each_word² (along with aliases #grapheme_clusters³ and #words⁴).
¹ See http://disu.se/software/u-1.0/api/U/String/#each_grapheme_cluster-instance-method
² See http://disu.se/software/u-1.0/api/U/String/#each_word-instance-method
³ See http://disu.se/software/u-1.0/api/U/String/#grapheme_clusters-instance-method
⁴ See http://disu.se/software/u-1.0/api/U/String/#words-instance-method
§ Unicode-aware Sub-sequence Removal
#Chomp¹, #chop², #lstrip³, #rstrip⁴, and #strip⁵ all look for Unicode
newline and space characters, rather than only ASCII ones.
¹ See http://disu.se/software/u-1.0/api/U/String/#chomp-instance-method
² See http://disu.se/software/u-1.0/api/U/String/#chop-instance-method
³ See http://disu.se/software/u-1.0/api/U/String/#lstrip-instance-method
⁴ See http://disu.se/software/u-1.0/api/U/String/#rstrip-instance-method
⁵ See http://disu.se/software/u-1.0/api/U/String/#strip-instance-method
§ Unicode-aware Conversions
Case-shifting methods #downcase¹ and #upcase² do proper Unicode casing
and the interface is further augmented by #foldcase³ and #titlecase⁴.
#Mirror⁵ and #normalize⁶ do conversions similar in nature to the
case-shifting methods.
¹ See http://disu.se/software/u-1.0/api/U/String/#downcase-instance-method
² See http://disu.se/software/u-1.0/api/U/String/#upcase-instance-method
³ See http://disu.se/software/u-1.0/api/U/String/#foldcase-instance-method
⁴ See http://disu.se/software/u-1.0/api/U/String/#titlecase-instance-method
⁵ See http://disu.se/software/u-1.0/api/U/String/#mirror-instance-method
⁶ See http://disu.se/software/u-1.0/api/U/String/#normalize-instance-method
§ Width Calculations
#Width¹ will return the number of cells on a terminal that a U::String
will occupy.
#Center², #ljust³, and #rjust⁴ deal in width rather than length, making
them much more useful for generating terminal output. #%⁵ (and its alias
#format⁶) similarly deal in width.
¹ See http://disu.se/software/u-1.0/api/U/String/#width-instance-method
² See http://disu.se/software/u-1.0/api/U/String/#center-instance-method
³ See http://disu.se/software/u-1.0/api/U/String/#ljust-instance-method
⁴ See http://disu.se/software/u-1.0/api/U/String/#rjust-instance-method
⁵ See http://disu.se/software/u-1.0/api/U/String/#modulo-operator
⁶ See http://disu.se/software/u-1.0/api/U/String/#format-instance-method
§ Extended Type Conversions
Finally, #hex¹, #oct², and #to_i³ use Unicode alpha-numerics for their
respective conversions.
¹ See http://disu.se/software/u-1.0/api/U/String/#hex-instance-method
² See http://disu.se/software/u-1.0/api/U/String/#oct-instance-method
³ See http://disu.se/software/u-1.0/api/U/String/#to_i-instance-method
§ News
§ 1.0.0
Initial public release!
§ Financing
Currently, most of my time is spent at my day job and in my rather busy
private life. Please motivate me to spend time on this piece of software
by donating some of your money to this project. Yeah, I realize that
requesting money to develop software is a bit, well, capitalistic of me.
But please realize that I live in a capitalistic society and I need money
to have other people give me the things that I need to continue living
under the rules of said society. So, if you feel that this piece of
software has helped you out enough to warrant a reward, please PayPal a
donation to now@disu.se¹. Thanks! Your support won’t go unnoticed!
¹ Send a donation:
https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=now@disu.se&item_name=U
§ Reporting Bugs
Please report any bugs that you encounter to the {issue tracker}¹.
¹ See https://github.com/now/u/issues
§ Authors
Nikolai Weibull wrote the code, the tests, the documentation, and this
README.
§ Licensing
U is free software: you may redistribute it and/or modify it under the
terms of the {GNU Lesser General Public License, version 3}¹ or later², as
published by the {Free Software Foundation}³.
¹ See http://disu.se/licenses/lgpl-3.0/
² See http://gnu.org/licenses/
³ See http://fsf.org/
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Activity
0.0
ALPHA Alert -- just uploaded initial release. Linux inotify is a means to receive events describing file system activity (create, modify, delete, close, etc). Sinotify was derived from aredridel's package (http://raa.ruby-lang.org/project/ruby-inotify/), with the addition of Paul Boon's tweak for making the event_check thread more polite (see http://www.mindbucket.com/2009/02/24/ruby-daemons-verifying-good-behavior/) In sinotify, the classes Sinotify::PrimNotifier and Sinotify::PrimEvent provide a low level wrapper to inotify, with the ability to establish 'watches' and then listen for inotify events using one of inotify's synchronous event loops, and providing access to the events' masks (see 'man inotify' for details). Sinotify::PrimEvent class adds a little semantic sugar to the event in to the form of 'etypes', which are just ruby symbols that describe the event mask. If the event has a raw mask of (DELETE_SELF & IS_DIR), then the etypes array would be [:delete_self, :is_dir]. In addition to the 'straight' wrapper in inotify, sinotify provides an asynchronous implementation of the 'observer pattern' for notification. In other words, Sinotify::Notifier listens in the background for inotify events, adapting them into instances of Sinotify::Event as they come in and immediately placing them in a concurrent queue, from which they are 'announced' to 'subscribers' of the event. [Sinotify uses the 'cosell' implementation of the Announcements event notification framework, hence the terminology 'subscribe' and 'announce' rather then 'listen' and 'trigger' used in the standard event observer pattern. See the 'cosell' package on github for details.] A variety of 'knobs' are provided for controlling the behavior of the notifier: whether a watch should apply to a single directory or should recurse into subdirectores, how fast it should broadcast queued events, etc (see Sinotify::Notifier, and the example in the synopsis section below). An event 'spy' can also be setup to log all Sinotify::PrimEvents and Sinotify::Events. Sinotify::Event simplifies inotify's muddled event model, sending events only for those files/directories that have changed. That's not to say you can't setup a notifier that recurses into subdirectories, just that any individual event will apply to a single file, and not to its children. Also, event types are identified using words (in the form of ruby :symbols) instead of inotify's event masks. See Sinotify::Event for more explanation. The README for inotify: http://www.kernel.org/pub/linux/kernel/people/rml/inotify/README Selected quotes from the README for inotify: * "Rumor is that the 'd' in 'dnotify' does not stand for 'directory' but for 'suck.'" * "The 'i' in inotify does not stand for 'suck' but for 'inode' -- the logical choice since inotify is inode-based." (The 's' in 'sinotify' does in fact stand for 'suck.')
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Activity
0.0
ALPHA Alert -- just uploaded initial release.
Linux inotify is a means to receive events describing file system activity (create, modify, delete, close, etc).
Sinotify was derived from aredridel's package (http://raa.ruby-lang.org/project/ruby-inotify/), with the addition of
Paul Boon's tweak for making the event_check thread more polite (see
http://www.mindbucket.com/2009/02/24/ruby-daemons-verifying-good-behavior/)
In sinotify, the classes Sinotify::PrimNotifier and Sinotify::PrimEvent provide a low level wrapper to inotify, with
the ability to establish 'watches' and then listen for inotify events using one of inotify's synchronous event loops,
and providing access to the events' masks (see 'man inotify' for details). Sinotify::PrimEvent class adds a little semantic sugar
to the event in to the form of 'etypes', which are just ruby symbols that describe the event mask. If the event has a
raw mask of (DELETE_SELF & IS_DIR), then the etypes array would be [:delete_self, :is_dir].
In addition to the 'straight' wrapper in inotify, sinotify provides an asynchronous implementation of the 'observer
pattern' for notification. In other words, Sinotify::Notifier listens in the background for inotify events, adapting
them into instances of Sinotify::Event as they come in and immediately placing them in a concurrent queue, from which
they are 'announced' to 'subscribers' of the event. [Sinotify uses the 'cosell' implementation of the Announcements
event notification framework, hence the terminology 'subscribe' and 'announce' rather then 'listen' and 'trigger' used
in the standard event observer pattern. See the 'cosell' package on github for details.]
A variety of 'knobs' are provided for controlling the behavior of the notifier: whether a watch should apply to a
single directory or should recurse into subdirectores, how fast it should broadcast queued events, etc (see
Sinotify::Notifier, and the example in the synopsis section below). An event 'spy' can also be setup to log all
Sinotify::PrimEvents and Sinotify::Events.
Sinotify::Event simplifies inotify's muddled event model, sending events only for those files/directories that have
changed. That's not to say you can't setup a notifier that recurses into subdirectories, just that any individual
event will apply to a single file, and not to its children. Also, event types are identified using words (in the form
of ruby :symbols) instead of inotify's event masks. See Sinotify::Event for more explanation.
The README for inotify:
http://www.kernel.org/pub/linux/kernel/people/rml/inotify/README
Selected quotes from the README for inotify:
* "Rumor is that the 'd' in 'dnotify' does not stand for 'directory' but for 'suck.'"
* "The 'i' in inotify does not stand for 'suck' but for 'inode' -- the logical
choice since inotify is inode-based."
(The 's' in 'sinotify' does in fact stand for 'suck.')
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Activity
0.0
The code to check for the iPhone user agent is from http://developer.apple.com. This doesn't have any dependencies. - in app/controllers/application.rb require 'is_it_iphone' class ApplicationController < ActionController::Base include IsItIPhone before_filter :adjust_format_for_iphone # Always show iPhone views end You will have these functions: iphone_user_agent? Returns true if the user agent is an iPhone. (as spec'ed on http://developer.apple.com) iphone_request? Returns true if the request came from an iPhone. Override being an iPhone with ?format=xxxx in the URL. adjust_format_for_iphone Call when you want to show iPhone views to iPhone users. Note: It is recommended by Apple that you default to showing your "normal" html page to iPhone users and allow them to choose if they want an iPhone version. With Rails 2.0, you can use its multiview capabilities by simply adding this to your app: - in config/initializers/mime_types.rb Mime::Type.register_alias "text/html", :iphone Then, just create your views using suffices of iphone.erb instead of html.erb: index.iphone.erb show.iphone.erb etc. Note: you will probably want to use a Web library specific for iPhone applications. FWIW, I use Da shcode (in the iPhone SDK) to write and debug the iPhone application and then integrate it with my Rails project.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Activity
0.0
# Rake::ToolkitProgram
Create toolkit programs easily with `Rake` and `OptionParser` syntax. Bash completions and usage help are baked in.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'rake-toolkit_program'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install rake-toolkit_program
## Quickstart
* Shebang it up (in a file named `awesome_tool.rb`)
```ruby
#!/usr/bin/env ruby
```
* Require the library
```ruby
require 'rake/toolkit_program'
```
* Make your life easier
```ruby
Program = Rake::ToolkitProgram
```
* Define your command tasks
```ruby
Program.command_tasks do
desc "Build it"
task 'build' do
# Ruby code here
end
desc "Test it"
task 'test' => ['build'] do
# Rake syntax ↑↑↑↑↑↑↑ for dependencies
# Ruby code here
end
end
```
You can use `Program.args` in your tasks to access the other arguments on the command line. For argument parsing integrated into the help provided by the program, see the use of `Rake::Task(Rake::ToolkitProgram::TaskExt)#parse_args` below.
* Wire the mainline
```ruby
Program.run(on_error: :exit_program!) if $0 == __FILE__
```
* In the shell, prepare to run the program (UNIX/Linux systems only)
```console
$ chmod +x awesome_tool.rb
$ ./awesome_tool.rb --install-completions
Completions installed in /home/rtweeks/.bashrc
Source /home/rtweeks/.bash-complete/awesome_tool.rb-completions for immediate availability.
$ source /home/rtweeks/.bash-complete/awesome_tool.rb-completions
```
* Ask for help
```console
$ ./awesome_tool.rb help
*** ./awesome_tool.rb Toolkit Program ***
.
.
.
```
## Usage
Let's look at a short sample toolkit program -- put this in `awesome.rb`:
```ruby
#!/usr/bin/env ruby
require 'rake/toolkit_program'
require 'ostruct'
ToolkitProgram = Rake::ToolkitProgram
ToolkitProgram.title = "My Awesome Toolkit of Awesome"
ToolkitProgram.command_tasks do
desc <<-END_DESC.dedent
Fooing myself
I'm not sure what I'm doing, but I'm definitely fooing!
END_DESC
task :foo do
a = ToolkitProgram.args
puts "I'm fooed#{' on a ' if a.implement}#{a.implement}"
end.parse_args(into: OpenStruct.new) do |parser, args|
parser.no_positional_args!
parser.on('-i', '--implement IMPLEMENT', 'An implement on which to be fooed') do |val|
args.implement = val
end
end
end
if __FILE__ == $0
ToolkitProgram.run(on_error: :exit_program!)
end
```
Make sure to `chmod +x awesome.rb`!
What does this support?
$ ./awesome.rb foo
I'm fooed
$ ./awesome.rb --help
*** My Awesome Toolkit of Awesome ***
Usage: ./awesome.rb COMMAND [OPTION ...]
Avaliable options vary depending on the command given. For details
of a particular command, use:
./awesome.rb help COMMAND
Commands:
foo Fooing myself
help Show a list of commands or details of one command
Use help COMMAND to get more help on a specific command.
$ ./awesome.rb help foo
*** My Awesome Toolkit of Awesome ***
Usage: ./awesome.rb foo [OPTION ...]
Fooing myself
I'm not sure what I'm doing, but I'm definitely fooing!
Options:
-i, --implement IMPLEMENT An implement on which to be fooed
$ ./awesome.rb --install-completions
Completions installed in /home/rtweeks/.bashrc
Source /home/rtweeks/.bash-complete/awesome.rb-completions for immediate availability.
$ source /home/rtweeks/.bash-complete/awesome.rb-completions
$ ./awesome.rb <tab><tab>
foo help
$ ./awesome.rb f<tab>
↳ ./awesome.rb foo
$ ./awesome.rb foo <tab>
↳ ./awesome.rb foo --
$ ./awesome.rb foo --<tab><tab>
--help --implement
$ ./awesome.rb foo --i<tab>
↳ ./awesome.rb foo --implement
$ ./awesome.rb foo --implement <tab><tab>
--help awesome.rb
$ ./awesome.rb foo --implement spoon
I'm fooed on a spoon
### Defining Toolkit Commands
Just define tasks in the block of `Rake::ToolkitProgram.command_tasks` with `task` (i.e. `Rake::DSL#task`). If `desc` is used to provide a description, the task will become visible in help and completions.
When a command task is initially defined, positional arguments to the command are available as an `Array` through `Rake::ToolkitProgram.args`.
### Option Parsing
This gem extends `Rake::Task` with a `#parse_args` method that creates a `Rake::ToolkitProgram::CommandOptionParser` (derived from the standard library's `OptionParser`) and an argument accumulator and `yield`s them to its block.
* The arguments accumulated through the `Rake::ToolkitProgram::CommandOptionParser` are available to the task in `Rake::ToolkitProgram.args`, replacing the normal `Array` of positional arguments.
* Use the `into:` keyword of `#parse_args` to provide a custom argument accumulator object for the associated command. The default argument accumulator constructor can be defined with `Rake::ToolkitProgram.default_parsed_args`. Without either of these, the default accumulator is a `Hash`.
* Options defined using `OptionParser#on` (or any of the variants) will print in the help for the associated command.
### Positional Arguments
Accessing positional arguments given after the command name depends on whether or not `Rake::Task(Rake::ToolkitProgram::TaskExt)#parse_args` has been called on the command task. If this method is not called, positional arguments will be an `Array` accessible through `Rake::ToolkitProgram.args`.
When `Rake::Task(Rake::ToolkitProgram::TaskExt)#parse_args` is used:
* `Rake::ToolkitProgram::CommandOptionParser#capture_positionals` can be used to define how positional arguments are accumulated.
* If the argument accumulator is a `Hash`, the default (without calling this method) is to assign the `Array` of positional arguments to the `nil` key of the `Hash`.
* For other types of accumulators, the positional arguments are only accessible if `Rake::ToolkitProgram::CommandOptionParser#capture_positionals` is used to define how they are captured.
* If a block is given to this method, the block of the method will receive the `Array` of positional arguments. If it is passed an argument value, that value is used as the key under which to store the positional arguments if the argument accumulator is a `Hash`.
* `Rake::ToolkitProgram::CommandOptionParser#expect_positional_cardinality` can be used to set a rule for the count of positional arguments. This will affect the _usage_ presented in the help for the associated command.
* `Rake::ToolkitProgram::CommandOptionParser#map_positional_args` may be used to transform (or otherwise process) positional arguments one at a time and in the context of options and/or arguments appearing earlier on the command line.
### Convenience Methods
* `Rake::Task(Rake::ToolkitProgram::TaskExt)#prohibit_args` is a quick way, for commands that accept no options or positional arguments, to declare this so the help and bash completions reflect this. It is equivalent to using `#parse_args` and telling the parser `parser.expect_positional_cardinality(0)`.
* `Rake::ToolkitProgram::CommandOptionParser#no_positional_args!` is a shortcut for calling `#expect_positional_cardinality(0)` on the same object.
* `Rake::Task(Rake::ToolkitProgram::TaskExt)#invalid_args!` and `Rake::ToolkitProgram::CommandOptionParser#invalid_args!` are convenient ways to raise `Rake::ToolkitProgram::InvalidCommandLine` with a message.
## OptionParser in Rubies Before and After v2.4
The `OptionParser` class was extended in Ruby 2.4 to simplify capturing options into a `Hash` or other container implementing `#[]=` in a similar way. This gem supports that, but it means that behavior varies somewhat between the pre-2.4 era and the 2.4+ era. To have consistent behavior across that version change, the recommendation is to use a `Struct`, `OpenStruct`, or custom class to hold program options rather than `Hash`.
## Development
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
To run the tests, use `rake`, `rake test`, or `rspec spec`. Tests can only be run on systems that support `Kernel#fork`, as this is used to present a pristine and isolated environment for setting up the tool. If run using Ruby 2.3 or earlier, some tests will be pending because functionality expects Ruby 2.4's `OptionParser`.
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/PayTrace/rake-toolkit_program. For further details on contributing, see [CONTRIBUTING.md](./CONTRIBUTING.md).
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025