Skip to content
Snippets Groups Projects
Commit a89b048e authored by Andre Starosta's avatar Andre Starosta
Browse files

Scripts colocados no ar

parents
Branches
No related tags found
No related merge requests found
# To use local gem:
$LOAD_PATH.unshift('/home/starosta/c3sl/seppir/scriptsRuby/rest-client-gem/lib')
require 'dspace'
list_all=true
create_community=true
create_collection=true
create_item=true
# ============================================================================ #
# Create Dspace Client
client = Dspace::Client.new(dspace_api: 'https://seppirdev.c3sl.ufpr.br:8443/rest')
if !client.is_running?
raise 'Can\'t connect to DSpace API.'
end
# Login on Dspace
client.login 'admin@seppirdev.com', 'adminadmin'
# ============================================================================ #
if list_all
# ============================================================================ #
# List all COMMUNITIES/COLLECTIONS/ITEMS
# GET ALL COMMUNITIES
client.communities.all.each do |community|
puts "-> #{community.name}"
# GET ALL COMMUNITIES's COLLECTIONS
client.communities.collections(:id => community.id).each do |collection|
puts "\t->#{collection.name}"
# GET ALL COLLECTIONS's ITEMS
client.collections.items(:id => collection.id, limit: 10, offset: 0, expand: "metadata").each do |item|
puts "\t\t->#{item.name}"
# GET ALL ITEMS's BITSTREAMS
client.items.bitstreams(:id => item.id).each do |bitstream|
puts "\t\t\t->#{bitstream.name}"
end
end
end
end
# ============================================================================ #
end
if create_community
# ============================================================================ #
# Create COMMUNITY
community = client.communities.create(
Dspace::Community.new(
{
'name' => "Community Created by dspace-rest-client",
'introductoryText' => "introductoryText for this awesome community!",
'shortDescription' => "shortDescription for this awesome community!",
'sidebarText' => "sidebarText for this awesome community!"
}
)
)
puts "Created community!\n#{community.inspect}\n"
# Update COMMUNITY
community.name = "Community Updated by dspace-rest-client"
if (client.communities.update(community, id: community.id))
puts "Community successfully updated!"
end
# ============================================================================ #
end
if create_collection
# ============================================================================ #
# Create COLLECTION
collection = client.communities.create_collection(
Dspace::Collection.new(
{
'name' => "Collection Created by dspace-rest-client",
'introductoryText' => "introductoryText for this awesome collection!",
'shortDescription' => "shortDescription for this awesome collection!",
'sidebarText' => "sidebarText for this awesome collection!"
}
),
id: community.id
)
puts "Created collection!\n#{collection.inspect}\n"
# Update COMMUNITY
collection.name = "Collection Updated by dspace-rest-client"
if (client.collections.update(collection, id: collection.id))
puts "Collection successfully updated!"
end
# ============================================================================ #
end
if create_item
# ============================================================================ #
# Create ITEM
item_metadata = Dspace::Item.new(
'metadata' => [
{'key' => "dc.title", 'value' => "Item Created by dspace-rest-client"},
{'key' => "dc.description", 'value' => "Description for this awesome item!"}
]
)
item = client.collections.create_item(item_metadata, id: collection.id)
puts "Created item!\n#{item.inspect}\n"
# Get ITEM's METADATA
item = client.items.find(id: item.id, :expand => "metadata")
item.metadata.each do |m|
puts "| #{m.key} => #{m.value}"
end
# ============================================================================ #
end
nome="01.0 APRESENTAÇÃO"
descricao="Esta unidade contém um breve resumo executivo do Projeto Nova Cartografia Social das Comunidades Quilombolas no Brasil, executado mediante a assinatura da Carta-Acordo entre Universidade Estadual do Maranhão (UEMA), Fundação de Apoio ao Ensino, Pesquisa e Extensão (FAPEAD) e a Secretaria de Políticas de Promoção da Igualdade Racial (SEPPIR), Projeto PNUD BRA 13/020."
def explore_files(path)
Dir.chdir(path)
d = Dir['**/*'].reject {|fn| File.directory?(fn) }.reject{|fn| File.extname(fn) != '.metadata'}.sort
p d.count
d.each do |files|
f = File.open(files,"r")
f.each_line{|line|
puts line
}
f.close
end
end
explore_files("/home/starosta/c3sl/seppir/scriptsRuby/files/SEPPIR_SoNucleos")
data = Array.new(2)
i = 0
file='exemplo.metadata'
f = File.open(file, "r")
f.each_line { |line|
data[i] = line
i += 1
}
f.close
data.each{|line|
puts line.scan(/"(.*)"/)
}
#==LOCAL GEM REFERENCE==#
$LOAD_PATH.unshift('/home/starosta/c3sl/seppir/scriptsRuby/rest-client-gem/lib')
require 'dspace'
#=======================#
#==PARAMETERS ATTRIBUTION==#
task = ARGV[0]
param1 = ARGV[1]
param2 = ARGV[2]
param3 = ARGV[3]
param4 = ARGV[4]
#==========================#
p "dasd"
#==AUTHENTICATION==#
client = Dspace::Client.new(dspace_api: 'https://seppirdev.c3sl.ufpr.br:8443/rest')
if !client.is_running?
raise 'Can\'t connect to DSpace API.'
end
client.login 'admin@seppirdev.com', 'adminadmin'
#==================#
#==LIST ALL ITEMS==#
if task == "list"
#==LIST COMMUNITIES==#
if param1 == "community"
client.communities.all.each do |community|
puts "-> #{community.name},ID:#{community.id}"
end
end
#==LIST COLLECTIONS==#
if param1 == "collection"
client.communities.all.each do |community|
client.communities.collections(:id => community.id).each do |collection|
puts "\t->#{collection.name},ID:#{collection.id}"
end
end
end
#==ITEMS COLLECTIONS==#
if param1 == "item"
client.communities.all.each do |community|
client.communities.collections(:id => community.id).each do |collection|
client.collections.items(:id => collection.id, limit: 10, offset: 0, expand: "metadata").each do |item|
puts "\t\t->#{item.name},ID:#{item.id}"
end
end
end
end
end
#==================#
if task == "create"
#==CREATE COMMUNITY==#
if param1 == "community"
community = client.communities.create(
Dspace::Community.new(
{
'name' => param2
}
)
)
end
#==CREATE COLLECTION==#There are no files associated with this item.
if param1 == "collection"
collection = client.communities.create_collection(
Dspace::Collection.new(
{
'name' => param2
}
),
id: param3
)
end
#==CREATE ITEM==#
if param1 == "item"
item_metadata = Dspace::Item.new({
'metadata' => [
{'key' => "dc.title", 'value' => param2},
{'key' => "dc.description", 'value' => param3}]
})
item = client.collections.create_item(item_metadata, id: param4)
file = File.new('/home/starosta/c3sl/seppir/scriptsRuby/files/file1.pdf','r')
bitstream = client.items.add_bitstream(file, id: item.id, name: 'File1.pdf', description: 'testing upload a pdf book')
end
#=======================#
end
#==DELETE ALL FOR TESTING==#
if task == "delete"
client.communities.all.each do |community|
client.communities.delete(id: community.id)
end
end
working on: file4.pdf
working on: file5.txt
working on: SEPPIR_SoNucleos
working on: file2.pdf
working on: file1.pdf
working on: file3.pdf
:q
tml><body><h1>It works!</h1></body></html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Author" content="Made by 'tree'">
<meta name="GENERATOR" content="$Version: $ tree v1.5.3 (c) 1996 - 2009 by Steve Baker, Thomas Moore, Francesc Rocher, Kyosuke Tokoro $">
<title>Banco de Dados SEPPIR - Quilombolas</title>
<style type="text/css">
<!--
BODY { font-family : courier, monospace, sans-serif; }
P { font-weight: normal; font-family : courier, monospace, sans-serif; color: black; background-color: transparent;}
B { font-weight: normal; color: black; background-color: transparent;}
A:visited { font-weight : normal; text-decoration : none; background-color : transparent; margin : 0px 0px 0px 0px; padding : 0px 0px 0px 0px; display: inline; }
A:link { font-weight : normal; text-decoration : none; margin : 0px 0px 0px 0px; padding : 0px 0px 0px 0px; display: inline; }
A:hover { color : #000000; font-weight : normal; text-decoration : underline; background-color : yellow; margin : 0px 0px 0px 0px; padding : 0px 0px 0px 0px; display: inline; }
A:active { color : #000000; font-weight: normal; background-color : transparent; margin : 0px 0px 0px 0px; padding : 0px 0px 0px 0px; display: inline; }
.VERSION { font-size: small; font-family : arial, sans-serif; }
.NORM { color: black; background-color: transparent;}
.FIFO { color: purple; background-color: transparent;}
.CHAR { color: yellow; background-color: transparent;}
.DIR { color: blue; background-color: transparent;}
.BLOCK { color: yellow; background-color: transparent;}
.LINK { color: aqua; background-color: transparent;}
.SOCK { color: fuchsia; background-color: transparent;}
.EXEC { color: green; background-color: transparent;}
-->
</style>
<script type="text/javascript"> function goBack() {window.history.back();} </script>
</head>
<body>
<h1>Banco de Dados SEPPIR - Quilombolas</h1>
<p><a class="NORM" href="http://186.233.93.44/BancoDeDadosSEPPIR/">http://186.233.93.44/BancoDeDadosSEPPIR/</a>
<br> ├── <a class="DIR" href="http://186.233.93.44/BancoDeDadosSEPPIR//01.0 – APRESENTAÇÃO/">01.0 – APRESENTAÇÃO</a><br> ├── <a class="DIR" href="http://186.233.93.44/BancoDeDadosSEPPIR//02.0 – CONGRESSO NACIONAL E SEUS ATOS/">02.0 – CONGRESSO NACIONAL E SEUS ATOS</a><br> ├── <a class="DIR" href="http://186.233.93.44/BancoDeDadosSEPPIR//03.0 – AGÊNCIAS GOVERNAMENTAIS E SUAS AÇÕES/">03.0 – AGÊNCIAS GOVERNAMENTAIS E SUAS AÇÕES</a><br> ├── <a class="DIR" href="http://186.233.93.44/BancoDeDadosSEPPIR//04.0 – BIBLIOTECAS/">04.0 – BIBLIOTECAS</a><br> ├── <a class="DIR" href="http://186.233.93.44/BancoDeDadosSEPPIR//05.0 – JURISPRUDÊNCIA SOBRE QUESTÕES QUILOMBOLAS/">05.0 – JURISPRUDÊNCIA SOBRE QUESTÕES QUILOMBOLAS</a><br> ├── <a class="DIR" href="http://186.233.93.44/BancoDeDadosSEPPIR//06.0 – MINISTÉRIO PÚBLICO FEDERAL/">06.0 – MINISTÉRIO PÚBLICO FEDERAL</a><br> ├── <a class="DIR" href="http://186.233.93.44/BancoDeDadosSEPPIR//07.1 – REDES UNIVERSITÁRIAS E GRUPOS DE PESQUISA_CNPQ/">07.1 – REDES UNIVERSITÁRIAS E GRUPOS DE PESQUISA_CNPQ</a><br> ├── <a class="DIR" href="http://186.233.93.44/BancoDeDadosSEPPIR//08.0 – PUBLICAÇÕES ACADÊMICAS/">08.0 – PUBLICAÇÕES ACADÊMICAS</a><br> ├── <a class="DIR" href="http://186.233.93.44/BancoDeDadosSEPPIR//10.0 – PUBLICAÇÕES NOVA CARTOGRAFIA SOCIAL DA AMAZÔNIA/">10.0 – PUBLICAÇÕES NOVA CARTOGRAFIA SOCIAL DA AMAZÔNIA</a><br> ├── <a class="DIR" href="http://186.233.93.44/BancoDeDadosSEPPIR//11.0 - ORIENTAÇÃO PARA ACONPANHAMENTO DE MATÉRIAS LEGISLATIVAS E ATOS DO EXECUTIVO/">11.0 - ORIENTAÇÃO PARA ACONPANHAMENTO DE MATÉRIAS LEGISLATIVAS E ATOS DO EXECUTIVO</a><br> └── <a class="DIR" href="http://186.233.93.44/BancoDeDadosSEPPIR//12.0 - ORIENTAÇÃO PARA ACOMPAMHAMENTO DE DECISÕES JUDICIAIS/">12.0 - ORIENTAÇÃO PARA ACOMPAMHAMENTO DE DECISÕES JUDICIAIS</a> <br><br>
</p>
<p>
<br><br>
</p>
<hr>
<a class="DIR" href="http://186.233.93.44/BancoDeDadosSEPPIR">Volta para o início</a><br>
<button onclick="goBack()">Volta</button>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment