| Class | AutomateIt::ShellManager |
| In: |
lib/automateit/shell_manager.rb
|
| Parent: | AutomateIt::Plugin::Manager |
The ShellManager provides Unix-like shell commands for manipulating files and executing commands.
WARNING: Previewing code can be dangerous. Read previews.txt for instructions on how to write code that can be safely previewed.
Backup sources if they exist. Returns the names of the backups created.
Options:
These backups are copies of the original sources saved into the same directories as the originals. The pathnames of these copies are timestamped and guaranteed to be unique, so you can have multiple backups of the same sources.
WARNING: This method is not conditional. It will make a backup every time it‘s called if the sources exist. Therefore, only execute this method when its needed.
For example, backup a file:
backup("/tmp/myfile") # => "/tmp/myfile.1190994237_M2xhLrC6Sj.bak
In the above example, the backup‘s name contains two special strings. The "1190994237" is the time the backup was made in seconds since the Epoch. The "M2xhLrC6Sj" is a random string used to guarantee the uniqueness of this backup in case two are made at exactly the same time.
Changes the directory into the specified dir. If called with a block, changes to the directory for the duration of the block, and then changes back to the previous directory at the end.
WARNING: Previewing code can be dangerous. Read previews.txt for instructions on how to write code that can be safely previewed.
Change the permission mode of the targets. Returns an array of targets modified or false if all have the desired mode.
Change the permission mode of the targets recursively. Returns an array of targets modified or false if all have the desired mode.
Change the user and group ownership of the targets. You can leave either the user or group as nil if you don‘t want to change it. Returns an array of targets modified or false if all have the desired ownership.
Change the user and group ownership of the targets recursively. You can leave either the user or group as nil if you don‘t want to change it. Returns an array of targets modified or false if all have the desired ownership.
Change the permissions of the targets. This command is like the chmod and chown in a single command.
Options:
Copy the sources to the target. Returns an array of sources copied or false if all are present.
Options:
Copy the sources to the target recursively. Returns an array of sources copied or false if all are present.
Copy the sources to the target recursively. Returns an array of sources copied or false if all are present.
Copy the source to the target and set its mode. Returns true if the file was installed or false if already present.
Create a hard link between the source and target. Your platform must support hard links to use this. Returns the target created or false if the link is already present.
Create a symbolic link between the sources and target. Your platform must support symbolic links to use this. Returns an array of sources linked or false if all are already present.
Create a symbolic link between the sources and target. If the target already exists, will remove it and recreate it. Your platform must support symbolic links to use this. Returns an array of sources linked or false if all are already present.
Create a directory or directories. Returns an array of directories created or false if all directories are already present.
Options:
WARNING: Previewing code can be dangerous. Read previews.txt for instructions on how to write code that can be safely previewed.
Create a directory or directories with their parents. Returns an array of directories created or false if all directories are already present.
Options same as mkdir.
Example:
File.exists?("/tmp/foo") # => false
mkdir_p("/tmp/foo/bar")
File.exists?("/tmp/foo") # => true
File.exists?("/tmp/foo/bar") # => true
WARNING: Previewing code can be dangerous. Read previews.txt for instructions on how to write code that can be safely previewed.
Creates a temporary file. Optionally takes a name argument which is purely cosmetic, e.g., if the name is "foo", the routine may create a temporary file named /tmp/foo_qeKo7nJk1s.
When called with a block, invokes the block with the path of the temporary file and deletes the file at the end of the block.
Without a block, returns the path of the temporary file and you‘re responsible for removing it when done.
Creates a temporary directory. See mktemp for details on the name argument.
When called with a block, invokes the block with the path of the temporary directory and recursively deletes the directory and its contents at the end of the block.
Without a block, returns the path of the temporary directory and you‘re responsible for removing it when done.
CAUTION: Read notes at the top of ShellManager for potentially problematic situations that may be encountered if using this command in preview mode!
Move the sources to the target. Returns an array of sources copied or false if none of the sources exist.
Remove the targets recursively and forcefully. Returns a list of targets removed or false if none of them exist.
Remove a directory or directories. The directories must be empty or an exception is thrown. Returns the directories removed or false if none of the directories exist.
Create the targets as files if needed and update their modification time. Unlike most other commands provided by ShellManager, this one will always modify the targets. Returns an array of targets modified.
Options: