Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cod
06-05-2018, 11:06 AM
Post: #81
RE: Cod
Regarding the instruction "cod help", it cannot list out the available commands as described in the tutorial. Instead, it seems to be designed to see a certain action's usage. The usage is:
Code:
cod help [-h] <action_name>

RR rayluk
Find all posts by this user
Quote this message in a reply
06-05-2018, 02:17 PM
Post: #82
RE: Cod
(06-05-2018 11:06 AM)cchen Wrote:  Regarding the instruction "cod help", it cannot list out the available commands as described in the tutorial. Instead, it seems to be designed to see a certain action's usage. The usage is:
Code:
cod help [-h] <action_name>

RR rayluk

This should be a bug in cod. When typing `cod help`, it shows the following
Code:
[rayluk@desktop ~]$ cod help
usage: cod help [-h] <action_name>
cod help: error: too few arguments

However, when typing `cod --help`, it works normally
Code:
[rayluk@desktop ~]$ cod --help
usage: cod

optional arguments:
  -h, --help    show this help message and exit

The most commonly used cod commands are:
  
    add         Add files to the source tree
    branch      Create a branch
    checkout    Checkout a branch
    clone       Create a local clone of the source tree
    help        print help info of commands.
    commit      Commit files
    history     Show history
    log        
                   Well... I don't know how to do 'log'. Do you mean 'history' ?
    install     Touch $HOME/.cod/modules.config and install cod for the current user
    list        List names of all available repositories, or print infos about tree_name
    update_local
                According to cod configuration to update server address
    mv          Move or rename a file, a directory, or a symlink
    newme       Create a new cod executable
    notify      Add an email account to the notification list of a code tree
    push        Push the local source tree to the repository
    pull        Pull files from the repository to update the local source tree
    read        Create a local clone of the source tree for read only
    rm          "Remove files from the source tree
    status      Show the current status of the source tree
    sync        Synchronize modules
    update      Update cod and its modules
    release     Make a release of a repository including all its dependence

More info at http//tab.d-thinker.org/showthread.php?tid=2280
Please report any bugs to lingu

@cchen

Please propose the proper behaviour of cod and fix the bug in the usage.
Find all posts by this user
Quote this message in a reply
06-05-2018, 02:20 PM
Post: #83
RE: Cod
(06-05-2018 10:38 AM)cchen Wrote:  
Code:
export PATH=$PATH:~/forest/code/code
This line of code should be changed to
Code:
export PATH=~/forest/code/code:$PATH

This is because the variable $PATH looks like this:
Code:
.../thinker/bin:/home/cchen/forest/code/code:/...
As thinker/bin:/ is in the front of home/cchen/forest/code, we should change the ordering of PATH

RR rayluk
This is good to me, please update to headpost
Find all posts by this user
Quote this message in a reply
06-06-2018, 10:23 AM
Post: #84
RE: Cod
Regarding the instruction "cod help", it cannot list out the available commands as described in the tutorial. Instead, the usage is:
Code:
cod help [-h] <action_name>
which can show how to use a certain action, for example:
Code:
Drive example:
[cchen@localhost ~]$ cod help -h status
usage: cod status [-h] [--verbose <number>] [-v]

optional arguments:
  -h, --help          show this help message and exit
  --verbose <number>  Verbose mode. Causes cod to print debugging messages
                      about its progress. This is helpful in debugging clone,
                      path problems. --verbose number can use 1 or 2 to choose
                      mode.
  -v                  equivalent to '--verbose 1'.

The true command for listing available actions should be:
Code:
cod --help
the result should look like this:
Code:
usage: cod

optional arguments:
  -h, --help    show this help message and exit

The most commonly used cod commands are:
  
    add         Add files to the source tree
    branch      Create a branch
    checkout    Checkout a branch
    clone       Create a local clone of the source tree
    help        print help info of commands.
    commit      Commit files
    history     Show history
    log        
                   Well... I don't know how to do 'log'. Do you mean 'history' ?
    install     Touch $HOME/.cod/modules.config and install cod for the current user
    list        List names of all available repositories, or print infos about tree_name
    update_local
                According to cod configuration to update server address
    mv          Move or rename a file, a directory, or a symlink
    newme       Create a new cod executable
    notify      Add an email account to the notification list of a code tree
    push        Push the local source tree to the repository
    pull        Pull files from the repository to update the local source tree
    read        Create a local clone of the source tree for read only
    rm          "Remove files from the source tree
    status      Show the current status of the source tree
    sync        Synchronize modules
    update      Update cod and its modules
    release     Make a release of a repository including all its dependence

More info at http//tab.d-thinker.org/showthread.php?tid=2280

RR rayluk
Find all posts by this user
Quote this message in a reply
06-06-2018, 11:47 AM
Post: #85
RE: Cod
(06-06-2018 10:23 AM)cchen Wrote:  Regarding the instruction "cod help", it cannot list out the available commands as described in the tutorial. Instead, the usage is:
Code:
cod help [-h] <action_name>
which can show how to use a certain action, for example:
Code:
Drive example:
[cchen@localhost ~]$ cod help -h status
usage: cod status [-h] [--verbose <number>] [-v]

optional arguments:
  -h, --help          show this help message and exit
  --verbose <number>  Verbose mode. Causes cod to print debugging messages
                      about its progress. This is helpful in debugging clone,
                      path problems. --verbose number can use 1 or 2 to choose
                      mode.
  -v                  equivalent to '--verbose 1'.

The true command for listing available actions should be:
Code:
cod --help
the result should look like this:
Code:
usage: cod

optional arguments:
  -h, --help    show this help message and exit

The most commonly used cod commands are:
  
    add         Add files to the source tree
    branch      Create a branch
    checkout    Checkout a branch
    clone       Create a local clone of the source tree
    help        print help info of commands.
    commit      Commit files
    history     Show history
    log        
                   Well... I don't know how to do 'log'. Do you mean 'history' ?
    install     Touch $HOME/.cod/modules.config and install cod for the current user
    list        List names of all available repositories, or print infos about tree_name
    update_local
                According to cod configuration to update server address
    mv          Move or rename a file, a directory, or a symlink
    newme       Create a new cod executable
    notify      Add an email account to the notification list of a code tree
    push        Push the local source tree to the repository
    pull        Pull files from the repository to update the local source tree
    read        Create a local clone of the source tree for read only
    rm          "Remove files from the source tree
    status      Show the current status of the source tree
    sync        Synchronize modules
    update      Update cod and its modules
    release     Make a release of a repository including all its dependence

More info at http//tab.d-thinker.org/showthread.php?tid=2280

RR rayluk

LGTM ( looks good to me )

Please merge proper info the headpost and update related codes. Save a copy of the headpost like what I did in ( http://tab.d-thinker.org/showthread.php?...http://tab.d-thinker.org/showthread.php?tid=7209&pid=7452 ) before you do any changes.
Find all posts by this user
Quote this message in a reply
06-06-2018, 12:49 PM
Post: #86
RE: Cod
Save a copy of head post

Cod
Cod is a Python script that helps retrieve source and binary files from multiple repositories of potentially different types. It considers all world's program code, source and binary, as a forest, and helps people walk and work in this forest.

You can think of Cod as a meta source code version control system. It enables the programmer to manage a "source forest", not a source tree. Given a module name, context or other relevant information, cod attempts to direct the actions to specific repositories at different locations. It restricts the actions upon a repository to enforce a simple workflow.

Currently cod supports git, and, consequently, you can use cod like git, but remember that this will change soon and cod restricts the actions to a subset of git's functions.

Prerequisites
Cod typically runs in a command-line interface, such as a shell in or a Cygwin command window on Microsoft Windows.

Cod requires the following software:
1. SSH
2. Python (cod assumes the python program is in /usr/bin/ )
3. git (client)

How to get cod
Installing cod is easy -- you simply get the cod program and run it. The cod program is distributed in the following two ways.

(1) Python source code: The source code of cod is available at git://codb.d-thinker.org/code.git and you can obtain a read-only copy of the source code with the following command:

Code:
git clone git://codb.d-thinker.org/code

Note that the repository name is 'code', not 'cod'. The cod program is cod.py in the repository, and you can run it directly in a Python-enabled environment.

For advanced users: You need to also set up authentication keys and Cod extensions (to be introduced in detail later). Refer to the 'Authentication' section for instructions on setting up keys. The extension files is usually set up automatically by cod when you run a cod command, and you can add more modules to the extension after you get familiar with how it works.

For basic set up, you can run the 'update' command of cod to set up the cod working environment, as shown in the following command line.

Code:
python code/cod.py update
python code/cod.py update

Note that you need to run 'update' twice. This is due to a special situation in the automatic extension setup process. In the future, you need to run 'cod update' once to update all the code trees in the extension.

Note that by default, repositories cloned with the above command is read-only.

Completing these steps, you have set up the cod tool! You may skip the following sections and start using cod. Later, when you want to do advanced configurations, you can come back to this article and continue with further configurations. Enjoy!

For advanced users: You might want to commit changes to the repository as a developer. In that case, you can refer to the "Update read-only repository configuration with update_local" session in later parts of this tutorial. You can also clone a repository as an authenticated user from the start, please refer to the session "Clone a repository as an authenticated user".

Now cod is set up in the right directory, most likely ~/forest/code/code, and you can starting using it. If the command above fails due to authentication errors, most likely the repository is not open to public, and authentication is needed. Please refer to the section "Authentication" below to set up the keys.

To learn more about the cod command line, use the following command to print the help message.

Code:
python code/cod.py help

There is also a shell script 'cod' in the code directory that helps run the cod.py python script. Therefore, the command above is equivalent to

Code:
code/cod help

which is hopefully more convenient.

(2) (Temporarily not available) Standalone program: Pre-compiled programs are available for downloading at http://cod.shufangkeji.com/ . You can download a suitable version and run it directly on Linux. This currently works only in the Linux environment.

Note that the "git clone" command placed the cod programs in ~/code. This is different from the normal convention of cod. Usually, cod stores code trees in the $GROUND_DIR directory, which is usually "~/forest". Since you have already got the cod program, you can obtain itself again by running the following command.

Code:
code/cod read code

This will store the cod programs in $GROUNND_DIR/code/code. Be aware that 'cod read' obtains a read-only copy of the program. If you want to modify the cod program, you need to use 'cod clone' instead of 'cod read'.

It is advisable to include "cod" in a directory in PATH so that you can directly run it in the command line. For example, if you use bash, you may want to add the following line to the ~/.bashrc

Code:
export PATH=$PATH:~/forest/code/code

You may also choose to create an alias for invoking "python /path/to/cod.py".

After cod is functional, you can always update to the latest version of cod using cod itself. Examples in this post provide hints on how to do it.

For advanced users: Authentication

The "cod read" command we described earlier does not require authentication. However, if you like to have write-access to some code trees, it is necessary to set up authentication. Cod uses public/private key authentication. New users need to generate a key pair if they don’t have one, and send the public key to the administrator. The user can generate the key pair by executing this command:

Code:
$ ssh-keygen -t rsa

After generating the key pair, if you want to access one certain CT tree such as bin, dstools, send the public key (~/.ssh/id_rsa.pub) with the repository info (those info shown by `cod list <repo name>`) to the administrator ( majordomo@d-thinker.org ) and ask he/she to create an account grant the access right such as read, read/write permission for you. After receiving confirmation from the administrator, the user can starts to use cod.

If the private key corresponding to the public key you send to the administrator is not the default one (~/.ssh/id_rsa) used by SSH, the user needs to direct SSH to use the matching private key when running Cod. One solution is to use the config file ~/.ssh/config and add a few lines like the following example. Suppose the private key to be used for cod is id_rsa_codb.

Code:
Host codb.d-thinker.org
Port 22
User git
IdentityFile ~/.ssh/id_rsa_codb

Using the default key pair for Cod will eliminate this complication. Nevertheless, you are advised to add a few entries to ~/.ssh/config because some code trees use non-standard SSH ports. Please refer to http://tab.d-thinker.org/showthread.php?tid=2581 for details.

For advanced users: Update configuration with update_local
An existing repository can be read-only without authentication. The config file of the repository has url in the form of "git://....". You might want to update the code and commit the changes, in that case, go to the repository folder, and use this command.
Code:
cod update_local

The command modify the config file for git and you can now commit to the repository if you are an authenticated user.

For advanced users: Clone a repository as an authenticated user
You can also clone a repository ( i.e., the repository does not exists in the forest so far ) as an authenticated user. In such case, you can make modifications and commit changes.
Code:
cod clone <repository name>
If the command fails, most likely you are not authenticated to the repository. Please ask for permission
Usage
Cod manages a "source forest", and the forest contains one or more source trees, each tree managed by an version control system, such as git (Subversion will be supported soon). It is supposed that all the source code trees are in one "ground" directory. Usually the ground directory is the directory in which you issue "cod clone" commands. Suppose the ground directory's name is "shenandoah", the source code trees may look like the following example:


shenandoah
|___ tree1 (git repository one)
|___ tree2 (git repository two)
|___ tree3 (git repository three)


But the directories should not form a structure like the following:


shenandoah
|___ tree1 (git repository one)
|___ subdir2 ___ subdir22 ___ tree2 (git repository two)
|___ subdir3 ___ tree3 (git repository three)


That is to say, the forest ground directory should contain only sub-directorys that represents a valid source code tree managed by some version control system. In practice, this requirement can be easily met by issuing the source tree retrieval command (git clone, svn co, etc.) in the ground directory.

The following examples show typical usage of cod.

- To print the list of cod commands, run

cod help

- The cod standalone program itself is contained in the 'bin' code tree. You can clone the bin code tree as follows and obtain the latest version of cod:

cod clone bin

Clone should be done in the ground directory. If the clone is successful, two directories 'bin' and 'bin/bin' should be created and contain the file cod together with other files in the code tree.

- Many cod commands need to run in the work directory managed by the version management tool (e.g., git). We should thus enter the work directory as shown in the following example.

cd $GROUND_DIR/bin/bin

- We typically use branches to manage multiple concurrent versions of the code. Refer to Branch rules for more information. For example, if we work on the 'rc' branch, we can use the following git command to switch to the required branch.

git checkout rc

- To pull the latest files from the repository to the local cloned source tree, run

cod pull

- Create and add a file. For example, add a file README as follows.

cod add README

- Edit files and commit the changes. For example, run the following command to commit changes in README.

cod commit -m "Some modifications on README" README

- Push the changes to the server.

cod push

Extensions
Many developers want to extend cod for his or her own environment. Cod has an extension interface that allows the developer to do so -- http://tab.shufangkeji.com:680/showthread.php?tid=2424 .

---
Revisions:
20170206/zli: Add one sentence to denote the end of simple set up
20170106/zli: Revert changes about two "cod update" because it's still needed.
20170105/zli: Add "update_local" and "clone" session for advanced users
20170105/zli: Remove authentication requirement, remove the requirement for "update" twice
20160524/gl: State that the standalone version is not available now.
20150616/gl: Mention the key problem if cod update fails.
20150616/gl: Recommend to use 'cod update' after getting cod.
20150314/gl: Remove the .hope file usage.
20141203/gl: Update the URL for standalone distributions to cod.shufangkeji.com. Remove the attachment (cod.py) in this post.
20141127/gl: Update the URL cod.d-thinker.org.
20141122/gl: Introduce the code/cod script.
20141018/gl: Add a link to specific configurations in ~/.ssh/config.
20140823/gl: Add a section for extensions.
20140822/gl: Add git info.
20180417/cwt: add majordomo info.
20180419/zheny: add example to email majordomo
20180420/zheny: modify the link added in 20180419
20180604/cwt: update the instruction to grant permission.
Find all posts by this user
Quote this message in a reply
06-06-2018, 02:46 PM
Post: #87
RE: Cod
As discussed, you can use the simple reply function to save the copy of headpost next time

(06-06-2018 12:49 PM)cchen Wrote:  Save a copy of head post

Cod
Cod is a Python script that helps retrieve source and binary files from multiple repositories of potentially different types. It considers all world's program code, source and binary, as a forest, and helps people walk and work in this forest.

You can think of Cod as a meta source code version control system. It enables the programmer to manage a "source forest", not a source tree. Given a module name, context or other relevant information, cod attempts to direct the actions to specific repositories at different locations. It restricts the actions upon a repository to enforce a simple workflow.

Currently cod supports git, and, consequently, you can use cod like git, but remember that this will change soon and cod restricts the actions to a subset of git's functions.

Prerequisites
Cod typically runs in a command-line interface, such as a shell in or a Cygwin command window on Microsoft Windows.

Cod requires the following software:
1. SSH
2. Python (cod assumes the python program is in /usr/bin/ )
3. git (client)

How to get cod
Installing cod is easy -- you simply get the cod program and run it. The cod program is distributed in the following two ways.

(1) Python source code: The source code of cod is available at git://codb.d-thinker.org/code.git and you can obtain a read-only copy of the source code with the following command:

Code:
git clone git://codb.d-thinker.org/code

Note that the repository name is 'code', not 'cod'. The cod program is cod.py in the repository, and you can run it directly in a Python-enabled environment.

For advanced users: You need to also set up authentication keys and Cod extensions (to be introduced in detail later). Refer to the 'Authentication' section for instructions on setting up keys. The extension files is usually set up automatically by cod when you run a cod command, and you can add more modules to the extension after you get familiar with how it works.

For basic set up, you can run the 'update' command of cod to set up the cod working environment, as shown in the following command line.

Code:
python code/cod.py update
python code/cod.py update

Note that you need to run 'update' twice. This is due to a special situation in the automatic extension setup process. In the future, you need to run 'cod update' once to update all the code trees in the extension.

Note that by default, repositories cloned with the above command is read-only.

Completing these steps, you have set up the cod tool! You may skip the following sections and start using cod. Later, when you want to do advanced configurations, you can come back to this article and continue with further configurations. Enjoy!

For advanced users: You might want to commit changes to the repository as a developer. In that case, you can refer to the "Update read-only repository configuration with update_local" session in later parts of this tutorial. You can also clone a repository as an authenticated user from the start, please refer to the session "Clone a repository as an authenticated user".

Now cod is set up in the right directory, most likely ~/forest/code/code, and you can starting using it. If the command above fails due to authentication errors, most likely the repository is not open to public, and authentication is needed. Please refer to the section "Authentication" below to set up the keys.

To learn more about the cod command line, use the following command to print the help message.

Code:
python code/cod.py help

There is also a shell script 'cod' in the code directory that helps run the cod.py python script. Therefore, the command above is equivalent to

Code:
code/cod help

which is hopefully more convenient.

(2) (Temporarily not available) Standalone program: Pre-compiled programs are available for downloading at http://cod.shufangkeji.com/ . You can download a suitable version and run it directly on Linux. This currently works only in the Linux environment.

Note that the "git clone" command placed the cod programs in ~/code. This is different from the normal convention of cod. Usually, cod stores code trees in the $GROUND_DIR directory, which is usually "~/forest". Since you have already got the cod program, you can obtain itself again by running the following command.

Code:
code/cod read code

This will store the cod programs in $GROUNND_DIR/code/code. Be aware that 'cod read' obtains a read-only copy of the program. If you want to modify the cod program, you need to use 'cod clone' instead of 'cod read'.

It is advisable to include "cod" in a directory in PATH so that you can directly run it in the command line. For example, if you use bash, you may want to add the following line to the ~/.bashrc

Code:
export PATH=$PATH:~/forest/code/code

You may also choose to create an alias for invoking "python /path/to/cod.py".

After cod is functional, you can always update to the latest version of cod using cod itself. Examples in this post provide hints on how to do it.

For advanced users: Authentication

The "cod read" command we described earlier does not require authentication. However, if you like to have write-access to some code trees, it is necessary to set up authentication. Cod uses public/private key authentication. New users need to generate a key pair if they don’t have one, and send the public key to the administrator. The user can generate the key pair by executing this command:

Code:
$ ssh-keygen -t rsa

After generating the key pair, if you want to access one certain CT tree such as bin, dstools, send the public key (~/.ssh/id_rsa.pub) with the repository info (those info shown by `cod list <repo name>`) to the administrator ( majordomo@d-thinker.org ) and ask he/she to create an account grant the access right such as read, read/write permission for you. After receiving confirmation from the administrator, the user can starts to use cod.

If the private key corresponding to the public key you send to the administrator is not the default one (~/.ssh/id_rsa) used by SSH, the user needs to direct SSH to use the matching private key when running Cod. One solution is to use the config file ~/.ssh/config and add a few lines like the following example. Suppose the private key to be used for cod is id_rsa_codb.

Code:
Host codb.d-thinker.org
Port 22
User git
IdentityFile ~/.ssh/id_rsa_codb

Using the default key pair for Cod will eliminate this complication. Nevertheless, you are advised to add a few entries to ~/.ssh/config because some code trees use non-standard SSH ports. Please refer to http://tab.d-thinker.org/showthread.php?tid=2581 for details.

For advanced users: Update configuration with update_local
An existing repository can be read-only without authentication. The config file of the repository has url in the form of "git://....". You might want to update the code and commit the changes, in that case, go to the repository folder, and use this command.
Code:
cod update_local

The command modify the config file for git and you can now commit to the repository if you are an authenticated user.

For advanced users: Clone a repository as an authenticated user
You can also clone a repository ( i.e., the repository does not exists in the forest so far ) as an authenticated user. In such case, you can make modifications and commit changes.
Code:
cod clone <repository name>
If the command fails, most likely you are not authenticated to the repository. Please ask for permission
Usage
Cod manages a "source forest", and the forest contains one or more source trees, each tree managed by an version control system, such as git (Subversion will be supported soon). It is supposed that all the source code trees are in one "ground" directory. Usually the ground directory is the directory in which you issue "cod clone" commands. Suppose the ground directory's name is "shenandoah", the source code trees may look like the following example:


shenandoah
|___ tree1 (git repository one)
|___ tree2 (git repository two)
|___ tree3 (git repository three)


But the directories should not form a structure like the following:


shenandoah
|___ tree1 (git repository one)
|___ subdir2 ___ subdir22 ___ tree2 (git repository two)
|___ subdir3 ___ tree3 (git repository three)


That is to say, the forest ground directory should contain only sub-directorys that represents a valid source code tree managed by some version control system. In practice, this requirement can be easily met by issuing the source tree retrieval command (git clone, svn co, etc.) in the ground directory.

The following examples show typical usage of cod.

- To print the list of cod commands, run

cod help

- The cod standalone program itself is contained in the 'bin' code tree. You can clone the bin code tree as follows and obtain the latest version of cod:

cod clone bin

Clone should be done in the ground directory. If the clone is successful, two directories 'bin' and 'bin/bin' should be created and contain the file cod together with other files in the code tree.

- Many cod commands need to run in the work directory managed by the version management tool (e.g., git). We should thus enter the work directory as shown in the following example.

cd $GROUND_DIR/bin/bin

- We typically use branches to manage multiple concurrent versions of the code. Refer to Branch rules for more information. For example, if we work on the 'rc' branch, we can use the following git command to switch to the required branch.

git checkout rc

- To pull the latest files from the repository to the local cloned source tree, run

cod pull

- Create and add a file. For example, add a file README as follows.

cod add README

- Edit files and commit the changes. For example, run the following command to commit changes in README.

cod commit -m "Some modifications on README" README

- Push the changes to the server.

cod push

Extensions
Many developers want to extend cod for his or her own environment. Cod has an extension interface that allows the developer to do so -- http://tab.shufangkeji.com:680/showthread.php?tid=2424 .

---
Revisions:
20170206/zli: Add one sentence to denote the end of simple set up
20170106/zli: Revert changes about two "cod update" because it's still needed.
20170105/zli: Add "update_local" and "clone" session for advanced users
20170105/zli: Remove authentication requirement, remove the requirement for "update" twice
20160524/gl: State that the standalone version is not available now.
20150616/gl: Mention the key problem if cod update fails.
20150616/gl: Recommend to use 'cod update' after getting cod.
20150314/gl: Remove the .hope file usage.
20141203/gl: Update the URL for standalone distributions to cod.shufangkeji.com. Remove the attachment (cod.py) in this post.
20141127/gl: Update the URL cod.d-thinker.org.
20141122/gl: Introduce the code/cod script.
20141018/gl: Add a link to specific configurations in ~/.ssh/config.
20140823/gl: Add a section for extensions.
20140822/gl: Add git info.
20180417/cwt: add majordomo info.
20180419/zheny: add example to email majordomo
20180420/zheny: modify the link added in 20180419
20180604/cwt: update the instruction to grant permission.
Find all posts by this user
Quote this message in a reply
06-08-2018, 04:04 PM
Post: #88
RE: Cod
Just reminding, DO follow the instructions in http://tab.d-thinker.org/showthread.php?tid=4081 to update code after installing. Otherwise, the code you get is obsolete and may lead you to a wrong code tree. For example, new version of code locates sinai in a server different from the old version.

@xwcwt : should we add this reminder to the headpost?
Find all posts by this user
Quote this message in a reply
06-08-2018, 04:30 PM
Post: #89
RE: Cod
Save a copy of headpost

(10-20-2013 06:57 AM)lingu Wrote:  Cod is a Python script that helps retrieve source and binary files from multiple repositories of potentially different types. It considers all world's program code, source and binary, as a forest, and helps people walk and work in this forest.

You can think of Cod as a meta source code version control system. It enables the programmer to manage a "source forest", not a source tree. Given a module name, context or other relevant information, cod attempts to direct the actions to specific repositories at different locations. It restricts the actions upon a repository to enforce a simple workflow.

Currently cod supports git, and, consequently, you can use cod like git, but remember that this will change soon and cod restricts the actions to a subset of git's functions.

Prerequisites
Cod typically runs in a command-line interface, such as a shell in or a Cygwin command window on Microsoft Windows.

Cod requires the following software:
1. SSH
2. Python (cod assumes the python program is in /usr/bin/ )
3. git (client)

How to get cod
Installing cod is easy -- you simply get the cod program and run it. The cod program is distributed in the following two ways.

(1) Python source code: The source code of cod is available at git://codb.d-thinker.org/code.git and you can obtain a read-only copy of the source code with the following command:

Code:
git clone git://codb.d-thinker.org/code

Note that the repository name is 'code', not 'cod'. The cod program is cod.py in the repository, and you can run it directly in a Python-enabled environment.

For advanced users: You need to also set up authentication keys and Cod extensions (to be introduced in detail later). Refer to the 'Authentication' section for instructions on setting up keys. The extension files is usually set up automatically by cod when you run a cod command, and you can add more modules to the extension after you get familiar with how it works.

For basic set up, you can run the 'update' command of cod to set up the cod working environment, as shown in the following command line.

Code:
python code/cod.py update
python code/cod.py update

Note that you need to run 'update' twice. This is due to a special situation in the automatic extension setup process. In the future, you need to run 'cod update' once to update all the code trees in the extension.

Note that by default, repositories cloned with the above command is read-only.

Completing these steps, you have set up the cod tool! You may skip the following sections and start using cod. Later, when you want to do advanced configurations, you can come back to this article and continue with further configurations. Enjoy!

For advanced users: You might want to commit changes to the repository as a developer. In that case, you can refer to the "Update read-only repository configuration with update_local" session in later parts of this tutorial. You can also clone a repository as an authenticated user from the start, please refer to the session "Clone a repository as an authenticated user".

Now cod is set up in the right directory, most likely ~/forest/code/code, and you can starting using it. If the command above fails due to authentication errors, most likely the repository is not open to public, and authentication is needed. Please refer to the section "Authentication" below to set up the keys.

To learn more about the cod command line, use the following command to print the help message.

Code:
python code/cod.py help

There is also a shell script 'cod' in the code directory that helps run the cod.py python script. Therefore, the command above is equivalent to

Code:
code/cod --help

which is hopefully more convenient.

To see the usage of a certain action, use the following command:
Code:
cod [-h] help <action-name>
for example:
Code:
Drive example:
[cchen@localhost ~]$ cod help -h status
usage: cod status [-h] [--verbose <number>] [-v]

optional arguments:
  -h, --help          show this help message and exit
  --verbose <number>  Verbose mode. Causes cod to print debugging messages
                      about its progress. This is helpful in debugging clone,
                      path problems. --verbose number can use 1 or 2 to choose
                      mode.
  -v                  equivalent to '--verbose 1'.

(2) (Temporarily not available) Standalone program: Pre-compiled programs are available for downloading at http://cod.shufangkeji.com/ . You can download a suitable version and run it directly on Linux. This currently works only in the Linux environment.

Note that the "git clone" command placed the cod programs in ~/code. This is different from the normal convention of cod. Usually, cod stores code trees in the $GROUND_DIR directory, which is usually "~/forest". Since you have already got the cod program, you can obtain itself again by running the following command.

Code:
code/cod read code

This will store the cod programs in $GROUNND_DIR/code/code. Be aware that 'cod read' obtains a read-only copy of the program. If you want to modify the cod program, you need to use 'cod clone' instead of 'cod read'.

It is advisable to include "cod" in a directory in PATH so that you can directly run it in the command line. For example, if you use bash, you may want to add the following line to the ~/.bashrc

Code:
export PATH=$PATH:~/forest/code/code

You may also choose to create an alias for invoking "python /path/to/cod.py".

After cod is functional, you can always update to the latest version of cod using cod itself. Examples in this post provide hints on how to do it.

For advanced users: Authentication

The "cod read" command we described earlier does not require authentication. However, if you like to have write-access to some code trees, it is necessary to set up authentication. Cod uses public/private key authentication. New users need to generate a key pair if they don’t have one, and send the public key to the administrator. The user can generate the key pair by executing this command:

Code:
$ ssh-keygen -t rsa

After generating the key pair, if you want to access one certain CT tree such as bin, dstools, send the public key (~/id_rsa.pub) with the repository info (those info shown by `cod list <repo name>`) to the administrator ( majordomo@d-thinker.org ) and ask he/she to create an account grant the access right such as read, read/write permission for you. After receiving confirmation from the administrator, the user can starts to use cod.

If the private key corresponding to the public key you send to the administrator is not the default one (~/id_rsa) used by SSH, the user needs to direct SSH to use the matching private key when running Cod. One solution is to use the config file ~/.ssh/config and add a few lines like the following example. Suppose the private key to be used for cod is id_rsa_codb.

Code:
Host codb2.dthink.net
User git
IdentityFile ~/id_rsa

Host codb3.zettadom.com
Port 13122
User gito
IdentityFile ~/id_rsa

Host codb3.datathinking.org
Port 13122
User gito
IdentityFile ~/id_rsa

Host codb4.d-thinker.org
Port 2822
User git
IdentityFile ~/id_rsa

Host cb8.hututa.cn
Port 18022
User gito
IdentityFile ~/id_rsa

Host codb.hututa.com
Port 12322
User git
IdentityFile ~/id_rsa

Host trajan.d-thinker.org
Port 22
User git
IdentityFile ~/id_rsa

Host git.baijia.info
Port 22111
User git

Notice that the identity file specified in config file has to be the real path to private key.

Please also change the permission and owner of config file properly. Config file is supposed to be ONLY owned by the user, rw by the user. Use the following commands:
Code:
chmod 600 ~/.ssh/config
chown $USER ~/.ssh/config

Using the default key pair for Cod will eliminate this complication. Nevertheless, you are advised to add a few entries to ~/.ssh/config because some code trees use non-standard SSH ports. Please refer to http://tab.d-thinker.org/showthread.php?tid=2581 for details.

For advanced users: Update configuration with update_local
An existing repository can be read-only without authentication. The config file of the repository has url in the form of "git://....". You might want to update the code and commit the changes, in that case, go to the repository folder, and use this command.
Code:
cod update_local

The command modify the config file for git and you can now commit to the repository if you are an authenticated user.

For advanced users: Clone a repository as an authenticated user
You can also clone a repository ( i.e., the repository does not exists in the forest so far ) as an authenticated user. In such case, you can make modifications and commit changes.
Code:
cod clone <repository name>
If the command fails, most likely you are not authenticated to the repository. Please ask for permission
Usage
Cod manages a "source forest", and the forest contains one or more source trees, each tree managed by an version control system, such as git (Subversion will be supported soon). It is supposed that all the source code trees are in one "ground" directory. Usually the ground directory is the directory in which you issue "cod clone" commands. Suppose the ground directory's name is "shenandoah", the source code trees may look like the following example:


shenandoah
|___ tree1 (git repository one)
|___ tree2 (git repository two)
|___ tree3 (git repository three)


But the directories should not form a structure like the following:


shenandoah
|___ tree1 (git repository one)
|___ subdir2 ___ subdir22 ___ tree2 (git repository two)
|___ subdir3 ___ tree3 (git repository three)


That is to say, the forest ground directory should contain only sub-directorys that represents a valid source code tree managed by some version control system. In practice, this requirement can be easily met by issuing the source tree retrieval command (git clone, svn co, etc.) in the ground directory.

The following examples show typical usage of cod.

- To print the list of cod commands, run

cod help

- The cod standalone program itself is contained in the 'bin' code tree. You can clone the bin code tree as follows and obtain the latest version of cod:

cod clone bin

Clone should be done in the ground directory. If the clone is successful, two directories 'bin' and 'bin/bin' should be created and contain the file cod together with other files in the code tree.

- Many cod commands need to run in the work directory managed by the version management tool (e.g., git). We should thus enter the work directory as shown in the following example.

cd $GROUND_DIR/bin/bin

- We typically use branches to manage multiple concurrent versions of the code. Refer to Branch rules for more information. For example, if we work on the 'rc' branch, we can use the following git command to switch to the required branch.

git checkout rc

- To pull the latest files from the repository to the local cloned source tree, run

cod pull

- Create and add a file. For example, add a file README as follows.

cod add README

- Edit files and commit the changes. For example, run the following command to commit changes in README.

cod commit -m "Some modifications on README" README

- Push the changes to the server.

cod push

Extensions
Many developers want to extend cod for his or her own environment. Cod has an extension interface that allows the developer to do so -- http://tab.shufangkeji.com:680/showthread.php?tid=2424 .

---
Revisions:
20170206/zli: Add one sentence to denote the end of simple set up
20170106/zli: Revert changes about two "cod update" because it's still needed.
20170105/zli: Add "update_local" and "clone" session for advanced users
20170105/zli: Remove authentication requirement, remove the requirement for "update" twice
20160524/gl: State that the standalone version is not available now.
20150616/gl: Mention the key problem if cod update fails.
20150616/gl: Recommend to use 'cod update' after getting cod.
20150314/gl: Remove the .hope file usage.
20141203/gl: Update the URL for standalone distributions to cod.shufangkeji.com. Remove the attachment (cod.py) in this post.
20141127/gl: Update the URL cod.d-thinker.org.
20141122/gl: Introduce the code/cod script.
20141018/gl: Add a link to specific configurations in ~/.ssh/config.
20140823/gl: Add a section for extensions.
20140822/gl: Add git info.
20180417/cwt: add majordomo info.
20180419/zheny: add example to email majordomo
20180420/zheny: modify the link added in 20180419
20180604/cwt: update the instruction to grant permission.
20180606/cchen: update config file content, fix the syntax of "help" command, add the step of modifying the permission and ownership info of config
Find all posts by this user
Quote this message in a reply
06-13-2018, 02:49 PM (This post was last modified: 06-13-2018 02:52 PM by zheny.)
Post: #90
RE: Cod
RR zhenzhang


Quote:For advanced users: Update configuration with update_local
An existing repository can be read-only without authentication. The config file of the repository has url in the form of "git://....". You might want to update the code and commit the changes, in that case, go to the repository folder, and use this command.
Code:
cod update_local

I suggest to move the info to the step 'python code/cod.py update'
something like
Quote:
Code:
python code/cod.py update
python code/cod.py update
Note that you need to run 'update' twice. This is due to a special situation in the automatic extension setup process. In the future, you need to run 'cod update' once to update all the code trees in the extension.

Note that by default, repositories cloned with the above command is read-only.
((For advanced users: Update configuration with update_local
An existing repository can be read-only without authentication. ->))The config file of the repository has url in the form of "git://....". You might want to update the code and commit the changes, in that case, go to the repository folder, and use this command.
Code:
cod update_local
Find all posts by this user
Quote this message in a reply
Post Reply 


  • View a Printable Version
  • Send this Thread to a Friend
  • Subscribe to this thread
  • Show the subscribers of this thread:
  • Add subscribers to this thread:
Forum Jump: