Menu

cimit / Blog: Recent posts

40 | Hierarchy - countries transformed to dirs from flie lines

Given:
* a bunch of files where each row is a country title.

Find:
* transform the given files bunch to a directory bunch where each directory contains a sub directory for each country.

Solution:

~~~~

!/bin/sh

expand()
{
region=$1
if test $region != expand.sh
then
mkdir ${region}
for country in cat $region
do
mkdir ${region}
/$country
done
fi
}

for region in ls
do
expand $region
done
~~~~... read more

Posted by Ivan Bilimov 2015-12-12

30 | Countries

Proto phase S-1 (shell)

Implemented

  1. List of countries (1958): 99 countries total.

Usage

Countries count by parts of the world and total

% wc /data/cimit/countries/*
Here /data/cimit is your local clone of the cimit GIT repository.
Conunts of countries are in the first output column. The first column of the last line contains the total count of registered countries.

Posted by Ivan Bilimov 2015-12-06

20 | cimit Syntax and test cases

Test cases

% 
% # country directory
% 
% cimit list countries
% cimit add country France
% cimit add country 'Russian Federation'
% cimit list countries
France
Russian Federation
% cimit rename country 'Russian Federation' Russia
% cimit list countries
France
Russia
% cimit delete country France
% cimit list countries
Russia
% cimit add country France
% cimit add country France
cimit: France is already in the list
% cimit rename country France Russia
cimit: Russia is already in the list
% cimit list countries
Russia
France
% ls /var/games/cimit/struct
France  Russia
% 
% # organizations structure
% 
% cimit add org UN # global organization
% cimit add orgs UN
cimit: UN is already exists
% cimit add dept Center
% cimit add depts Center
cimit: Center is already exists
% cimit add dept Comission Center # add department
% cimit add dept 'Section 1' Comission Center # located dept
% cimit list countries
Russia
France
% cimit add dept 'Section 3' Comission Romania # auto add country
% cimit list countries
Russia
France
Romania
% cimit list depts # all first level
1   UN       -
2   Center   -
% cimit recurse depts # all hier
<GLOBAL>:
1   UN
2   Center:
    3   Comission
        4   Section 1   France
        5   Section 3   Romania
% cimit add dept Section\ 1 CIA USA # auto add located org
% cimit list depts
1   UN       -
2   Center   -
6   CIA      USA
% cimit recurse depts
<GLOBAL>:
1   UN
2   Center:
    3   Comission:
        4   Section 1   France
        5   Section 3   Romania
USA:
6   CIA
    7   Section 1
% cimit list depts - # only global depts
1   UN       -
2   Center   -
% cimit add dept 'Section 1' CIA Romania
cimit: CIA already has got Section 1 dept
% cimit recurse depts - # depts of only global orgs
<GLOBAL>:
1   UN
2   Center:
    3   Comission:
        4   Section 1   France
        5   Section 3   Romania
% cimit add org Interpol # auto add global org
% cimit list depts -
1   UN         -
2   Center     -
8   Interpol   -
% cimit edit dept 4 city Paris
% cat /var/games/cimit/struct/France/4
Name:Section 1
Parent:3
Country:France
City:Paris
Status:functioning
Note:Section one
% cimit add org Police France
% cimit list depts --country France
9   Police   France
% cimit add dept Paris\ PD 9
% cimit view dept Paris\ PD
Paris PD (France) is a dept of Police (France).
Status: functioning
Code: 10
% cimit view dept 10
Paris PD (France) is a dept of Police (France).
Status: functioning
Code: 10
% cimit get dept 10 city
% cimit edit dept 10 city Paris
% cimit get dept 10 city
Paris
% cimit view dept Paris' PD
Paris PD (Paris, France) is a dept of Police (France).
Status: functioning
Code: 10
% cimit recurse depts --country France
France:
9   Police   France
    10   Paris PD   France   Paris
% cimit add org 1 MI5 UK
% cimit list orgs --country 'U.*'
6   CIA   USA
11  MI5   UK
% cimit recurse orgs --country 'U.*'
USA:
6   CIA   USA
    7   Section 1
UK:
11  MI5   UK
    12   1   UK
% cimit get dept MI5 name
MI5
% cimit get dept 11 name
MI5
% cimit get dept MI5 code
11
% cimit rename dept MI5 MI-5
% cimit get dept 11 name
MI-5
% cimit rename dept 11 MI5
% cimit get dept MI5 name
MI5
% cimit list depts CIA
7   Section 1   USA
% cimit recurse depts CIA
CIA:
   7   Section 1   USA
% cimit list depts 6
7   Section 1   USA
% cimit recurse depts 6
CIA:
   7   Section 1   USA
% cimit list depts 'C.*'
#TODO
% cimit recurse depts 'C.*'
#TODO
% cimit delete dept CIA
#TODO: delete empty dept by name demo
% cimit delete dept 6 --child u
#TODO: delete dept by code and make the parent dept to be parent
#      for deleted dept children demo
% cimit delete org CIA --child r
#TODO: recursive deletion of the organization by its name demo
% cimit delete depts CIA --child 1
#TODO: delete an org by its name and move its depts to new
#      parent specified by code demo
% cimit delete depts 6 --child UN
#TODO: delete an org by its code and move its depts to new
#      parent specified by name demo
% cimit delete depts 6 --child c
#TODO: ...and close child depts demo
% cimit get dept UN state
functioning
% cimit close dept UN
% cimit state dept UN
closed
% cimit suspend org UN
cimit: UN is closed
% cimit reopen org UN
% cimit get org UN state
functioning
% cimit reopen org UN
cimit: UN is already functioning
% cimit resume org UN
cimit: UN is already functioning
% cimit suspend dept UN
% cimit resume org UN
% cimit get dept UN state
functioning
% 
% # person directory
% 
% ls /var/games/cimit/people
% cimit add man 'Marcelo Raymond'
% cimit add woman 'Sarah Salvador'
% ls /var/games/cimit/people
1 2
% cat /var/games/cimit/people/1
name:Marcelo Raymond
gender:male
condition:alive
% cimit view person 'Sarah Salvador'
Person code 2
Name        Sarah Salvador
Gender      female
Condition   alive
% cimit view person 2
Person code 2
Name        Sarah Salvador
Gender      female
Condition   alive
% cimit add person 3
cimit: 3 is not a valid person name
% cimit get person condition 'Sarah Salvador'
alive
% cimit get person name 1
Marcelo Raymond
% cimit get person name 3
% cimit add person 'Marcelo Raymond'
% cimit get person name 3
Marcelo Raymond
% cimit get person gender 3
male
% cimit get woman condition 'Marcelo Raymond'
alive
alive
% cimit edit person condition dead 'Marcelo Raymond'
cimit: there are several persons named Marcelo Raymond, use person code
% cimit get person code 'Marcelo Raymond'
1
3
% cimit edit person condition dead 3
% cimit get person condition 'Marcelo Raymond'
alive
dead
% cimit get person condition 3
dead
% cimit get person condition 1
alive
% cimit edit person code 3 4
cimit: code is the system field, it can not be edited
% cimit edit woman test_field 'some value' 'Sarah Salvador'
% cimit get woman test_field 2
some value

Scripts structure... read more

Posted by Ivan Bilimov 2015-11-16