Why must I use local path rather than 'svn://' with SVN bindings? - ruby

I'm using the Ruby SVN bindings built with SWIG. Here's a little tutorial.
When I do this
#repository = Svn::Repos.open('/path/to/repository')
I can access the repository fine. But when I do this
#repository = Svn::Repos.open('svn://localhost/some/path')
It fails with
/SourceCache/subversion/subversion-35/subversion/subversion/libsvn_subr/io.c:2710: 2: Can't open file 'svn://localhost/format': No such file or directory
When I do this from the command line, I do get output
svn ls svn://localhost/some/path
Any ideas why I can't use the svn:// protocol?
EDIT
Here's what I ended up doing, and it works.
require 'svn/ra'
class SvnWrapper
def initialize(repository_uri, repository_username, repository_password)
# Remove any trailing slashes from the path, as the SVN library will choke
# if it finds any.
#repository_uri = repository_uri.gsub(/[\/]+$/, '')
# Initialize repository session.
#context = Svn::Client::Context.new
#context.add_simple_prompt_provider(0) do |cred, realm, username, may_save|
cred.username = repository_username
cred.password = repository_password
cred.may_save = true
end
config = {}
callbacks = Svn::Ra::Callbacks.new(#context.auth_baton)
#session = Svn::Ra::Session.open(#repository_uri, config, callbacks)
end
def ls(relative_path, revision = nil)
relative_path = relative_path.gsub(/^[\/]+/, '').gsub(/[\/]+$/, '')
entries, properties = #session.dir(relative_path, revision)
return entries.keys.sort
end
def info(relative_path, revision = nil)
path = File.join(#repository_uri, relative_path)
data = {}
#context.info(path, revision) do |dummy, infoStruct|
# These values are enumerated at http://svn.collab.net/svn-doxygen/structsvn__info__t.html.
data['url'] = infoStruct.URL
data['revision'] = infoStruct.rev
data['kind'] = infoStruct.kind
data['repository_root_url'] = infoStruct.repos_root_url
data['repository_uuid'] = infoStruct.repos_UUID
data['last_changed_revision'] = infoStruct.last_changed_rev
data['last_changed_date'] = infoStruct.last_changed_date
data['last_changed_author'] = infoStruct.last_changed_author
data['lock'] = infoStruct.lock
end
return data
end
end
Enjoy.

The svn command is a client. It communicates with the Subversion server using several protocols (http(s)://, svn:// and file:///).
Repos.open is a repository function (much like svnadmin for instance). It operates directly on the database, and doesn't use a client protocol to communicate with the server.

Related

Is there a ruby method for finding a blob uri?

I checked the whole azure-storage-blob gem and didn't find any way to get the URI for a blob. Is there some way to construct it correctly and in a generic way that will work for any other blob in any region?
I used S3 SDK before and I'm well grounded in S3 but new to Azure.
There is a protected method called blob_uri that looks like this:
def blob_uri(container_name, blob_name, query = {}, options = {})
if container_name.nil? || container_name.empty?
path = blob_name
else
path = ::File.join(container_name, blob_name)
end
options = { encode: true }.merge(options)
generate_uri(path, query, options)
end
So you could take the short cut of:
blob_client = Azure::Storage::Blob::BlobService.create(storage_account_name: 'XXX' , storage_access_key: 'XXX')
blob_client.send(:blob_uri, container_name,blob_name)
However, the actual URI is simply:
https://[storage_account_name].blob.core.windows.net/container/[container[s]]/[blob file name]
So since you have to know the blob name and the container to access to blob.
File.join(blob_client.host,container,blob_name)
Is the URI to the blob

How to create publicly readable object store containers with ruby openstack gem?

I have tried to create publicly readable openstack object store containers like this:
os = OpenStack::Connection.create(...)
container = os.create_container(container_name)
container.set_metadata({'X-Container-Read' => '.r:*'})
Using my code above, the newly created containers are private.
What is the correct way to create containers with public read permissions with the ruby openstack gem?
You can try the following way.
You can redfine the create_container method
then
class MyStack < OpenStack::Swift::Connection
def create_container(containername)
super
#connection.req("PUT", path, {:headers=>{"Content-Length"=>"0", "X-Container-Read" => ".r:*", "X-Container-Write" => ".r:*}})
OpenStack::Swift::Container.new(self, containername)
end
end
These "X-Container-Read" => ".r:*", "X-Container-Write" => ".r:*" header value you need to set.
or
container.set_metadata({"X-Container-Read" => ".r:*", "X-Container-Write" => ".r:*"})
Here's what I ended up doing:
module PubliclyRedableContainerMonkeyPatch
def create_publicy_readable_container(containername)
raise OpenStack::Exception::InvalidArgument.new("Container name cannot contain '/'") if containername.match("/")
raise OpenStack::Exception::InvalidArgument.new("Container name is limited to 256 characters") if containername.length > 256
path = "/#{URI.encode(containername.to_s)}"
#connection.req("PUT", path, {:headers=>{"Content-Length"=>"0", "X-Container-Read" => ".r:*"}})
OpenStack::Swift::Container.new(self, containername)
end
end
OpenStack::Swift::Connection.include PubliclyRedableContainerMonkeyPatch
os = OpenStack::Connection.create(...)
container = os.create_publicy_readable_container(container_name)
Worksforme. :)

Puppet: How to require an additional resource in a custom type

I am writing a custom type for Puppet and use the following code to copy a module file specified by a puppet url to the user's home directory:
def generate
if self[:source]
uri = URI.parse(self[:source])
path = File.join(Etc.getpwnam(self[:user])[:dir], File.basename(uri.path))
file_opts = {}
file_opts[:name] = File.join(Etc.getpwnam(self[:user])[:dir], File.basename(uri.path))
file_opts[:ensure] = self[:ensure] == :absent ? :absent : :file
file_opts[:source] = self[:source]
file_opts[:owner] = self[:user]
self[:source] = path
Puppet::Type.type(:file).new(file_opts)
end
end
Things are working fine so far. The resource is added to the catalog and created on the agent side. But I have a problem...
How can I specify that this additional file resource must be created before the actual type gets executed? Unfortunatley, I cannot find an example which shows how to specify a dependency on an optional resource that is defined in a generate method.

Bintray VCS Tagging

So I have a Bintray repository, but I'm having difficulty uploading to it from gradle. Well, what I mean is version management is not working how I want it, currently for every single .jar I upload, I have to increment the version in my configuration, and dependencies. I know this is not how it's supposed to be done. My question is how do I automate/implement VCS tagging with Bintray. Right now my configuration for uploading looks like so (using the bintray plugin):
bintray {
user = "$bintrayUser"
key = "$bintrayKey"
publications = ['maven']
dryRun = false
publish = true
pkg {
repo = "$targetBintrayRepo"
name = "$targetBintrayPackage"
desc = ''
websiteUrl = "$programWebsiteUrl"
issueTrackerUrl = "$programIssueUrl"
vcsUrl = "$programVcsUrl"
licenses = ["$programLicense"]
labels = []
publicDownloadNumbers = true
version {
name = "$programVersion"
released = new java.util.Date()
vcsTag = "$programVcsTag"
}
}
}
And my variables are:
def programVersion = '0'
def programVcsTag = '0.0.0'
def programGroup = 'com.gmail.socraticphoenix'
def targetBintrayRepo = 'Main'
def targetBintrayPackage = 'java-api'
def programLicense = 'MIT'
def programWebsiteUrl = 'https://github.com/meguy26/PlasmaAPI'
def programIssueUrl = 'https://github.com/meguy26/PlasmaAPI/issues'
def programVcsUrl = 'https://github.com/meguy26/PlasmaAPI.git'
Yet here no tags appear, and running publish again (even with a different vcs tag) results in a version already exists error. (Could not upload to 'https://api.bintray.com/content/meguy26/Main/java-api/0/com/gmail/socraticphoenix/PlasmaAPI/0/PlasmaAPI-0.jar': HTTP/1.1 409 Conflict [message:Unable to upload files: An artifact with the path 'com/gmail/socraticphoenix/PlasmaAPI/0/PlasmaAPI-0.jar' already exists])
Sorry if I'm being noobish, but I don't understand why its not working, I filled out all the appropriate variables (I thought)
Bintray does not support multiple tags per version. Version is a unique string. If you want to release something from the same version with different tags, compose a Bintray version string with from your program version and tag, e.g. "$programVersion-$programVcsTag"

Rally APIs: How to Move A Test Folder

I've worked with the script outlined in the following answer:
Rally APIs: How to copy Test Folder and member Test Cases
and it's handy, but what I really want to do is to move an entire Test Folder into a different project. This is next to impossible through the Rally User Interface. According to Rally Support, the only way to do this in the UI is:
Un-assign the Test Cases from their current Test Folder
Setup a Custom Grid app on your dashboard
Use the Custom Grid bulk edit to update the Project of the Test Cases
Lastly use the Custom Grid bulk edit to update the Test Folder - now that you're in the target Project, of the Test Cases
Even though the above process is clunky, it is easier now than it used to be before the advent of the bulk edit within the Custom Grids. Before you had to go through and edit each Test Case one-by-one which was very manual and slow.
However, we have several thousand Test Cases we need to move, and the Custom Grid has a fatal flaw for us. It will only show the first 200 records in a query. So we would have to manually change our grid query in a step wise manner to accomplish the move we need. This is barely better than editing Test Cases one-by-one. Is there a way to move a Test Folder with Test Cases from one Project to another, using a script? Please tell me there is.
The following script will perform this task - it will move all Test Cases from a Source Test Folder identified by FormattedID, to a Target Test Folder, also identified by FormattedID. The Source Test Folder and Target Test Folder can be in different Projects (although they must be within the same Workspace). Like the Copy script referenced in the question, the Target Test Folder must exist, i.e. the script will not create a Test Folder for you if the Target is not found.
For those needing to install and configure the Ruby REST Toolkit, links are here:
Developer Portal: Rally REST API for Ruby
Github
# Copyright 2002-2012 Rally Software Development Corp. All Rights Reserved.
require 'rally_api'
$my_base_url = "https://rally1.rallydev.com/slm"
$my_username = "user#company.com"
$my_password = "password"
$my_workspace = "My Workspace"
$my_project = "My Project"
$wsapi_version = "1.39"
# Test Folders
$source_test_folder_formatted_id = "TF8"
$target_test_folder_formatted_id = "TF11"
#==================== Make a connection to Rally ====================
config = {:base_url => $my_base_url}
config[:username] = $my_username
config[:password] = $my_password
config[:workspace] = $my_workspace
config[:project] = $my_project
config[:version] = $wsapi_version
#rally = RallyAPI::RallyRestJson.new(config)
begin
# Lookup source Test Folder
source_test_folder_query = RallyAPI::RallyQuery.new()
source_test_folder_query.type = :testfolder
source_test_folder_query.fetch = true
source_test_folder_query.query_string = "(FormattedID = \"" + $source_test_folder_formatted_id + "\")"
source_test_folder_result = #rally.find(source_test_folder_query)
# Lookup Target Test Folder
target_test_folder_query = RallyAPI::RallyQuery.new()
target_test_folder_query.type = :testfolder
target_test_folder_query.fetch = true
target_test_folder_query.query_string = "(FormattedID = \"" + $target_test_folder_formatted_id + "\")"
target_test_folder_result = #rally.find(target_test_folder_query)
if source_test_folder_result.total_result_count == 0
puts "Source Test Folder: " + $source_test_folder_formatted_id + "not found. Exiting."
exit
end
if target_test_folder_result.total_result_count == 0
puts "Target Test Folder: " + $target_test_folder_formatted_id + "not found. Target must exist before moving."
exit
end
source_test_folder = source_test_folder_result.first()
target_test_folder = target_test_folder_result.first()
# Populate full object for both Source and Target Test Folders
full_source_test_folder = source_test_folder.read
full_target_test_folder = target_test_folder.read
# Grab collection of Source Test Cases
source_test_cases = source_test_folder["TestCases"]
# Loop through Source Test Cases and Move to Target
source_test_cases.each do |source_test_case|
begin
test_case_to_update = source_test_case.read
source_test_case_formatted_id = test_case_to_update["FormattedID"]
target_project = full_target_test_folder["Project"]
target_project_full_object = target_project.read
target_project_name = target_project_full_object["Name"]
source_project = full_source_test_folder["Project"]
source_project_full_object = source_project.read
source_project_name = source_project_full_object["Name"]
puts "Source Project Name: #{source_project_name}"
puts "Target Project Name: #{target_project_name}"
# Test if the source project and target project are the same
source_target_proj_match = source_project_name.eql?(target_project_name)
# If the target Test Folder is in a different Project, we have to do some homework first:
# "un-Test Folder" the project
# Assign the Test Case to the Target Project
# Assign the Test Case to the Target Test Folder
if !source_target_proj_match then
fields = {}
fields["TestFolder"] = ""
test_case_updated = #rally.update(:testcase, test_case_to_update.ObjectID, fields) #by ObjectID
puts "Test Case #{source_test_case_formatted_id} successfully dissociated from: #{$source_test_folder_formatted_id}"
# Get full object on Target Project and assign Test Case to Target Project
fields = {}
fields["Project"] = target_project_full_object
test_case_updated = #rally.update(:testcase, test_case_to_update.ObjectID, fields) #by ObjectID
puts "Test Case #{source_test_case_formatted_id} successfully assigned to Project: #{target_project_name}"
end
# Change the Test Folder attribute on the Test Case
fields = {}
fields["TestFolder"] = target_test_folder
test_case_updated = #rally.update(:testcase, test_case_to_update.ObjectID, fields) #by ObjectID
puts "Test Case #{source_test_case_formatted_id} successfully moved to #{$target_test_folder_formatted_id}"
rescue => ex
puts "Test Case #{source_test_case_formatted_id} not updated due to error"
puts ex
end
end
end

Resources