[DEV] direct port ended ==> need to rework to be compatible with java
This commit is contained in:
parent
09c9314014
commit
1641e854df
5
src/org/atriasoft/death/ArgChoice.java
Normal file
5
src/org/atriasoft/death/ArgChoice.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package org.atriasoft.death;
|
||||||
|
|
||||||
|
record ArgChoice(String val, String description) {
|
||||||
|
|
||||||
|
}
|
@ -3,125 +3,159 @@ package org.atriasoft.death;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
record ArgChoice(String val, String description) {
|
import org.atriasoft.death.internal.Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Declare a possibility of an argument value
|
||||||
|
*/
|
||||||
|
public class ArgDefine implements ArgInterface {
|
||||||
|
private String optionSmall = "";
|
||||||
|
private String optionBig = "";
|
||||||
|
private String description = "";
|
||||||
|
private boolean haveParam = false;
|
||||||
|
private List<ArgChoice> list = new ArrayList<>();
|
||||||
|
|
||||||
|
public ArgDefine() {
|
||||||
|
this ("", "", new ArrayList<>(), "", false);
|
||||||
|
}
|
||||||
|
public ArgDefine(final String smallOption ) {
|
||||||
|
this (smallOption, "", new ArrayList<>(), "", false);
|
||||||
|
}
|
||||||
|
public ArgDefine(final String smallOption, final String bigOption ) {
|
||||||
|
this (smallOption, bigOption, new ArrayList<>(), "", false);
|
||||||
|
}
|
||||||
|
public ArgDefine(final String smallOption, final String bigOption, final List<ArgChoice> list) {
|
||||||
|
this (smallOption, bigOption, list, "", false);
|
||||||
|
}
|
||||||
|
public ArgDefine(final String smallOption, final String bigOption, final List<ArgChoice> list, final String desc) {
|
||||||
|
this (smallOption, bigOption, list, desc, false);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief Declare a possibility of an argument value
|
* Constructor.
|
||||||
|
* @param this Class handle
|
||||||
|
* @param smallOption (char) Value for the small option ex{ '-v' '-k' ... 1 single char element (no need of '-')
|
||||||
|
* @param bigOption (string) Value of the big option name ex{ '--verbose' '--kill' ... stated with -- and with the full name (no need of '--')
|
||||||
|
* @param list ([[string,string],...]) Optionnal list of availlable option{ '--mode=debug' ==> [['debug', 'debug mode'],['release', 'release the software']]
|
||||||
|
* @param desc (string) user friendly description with this parameter (default "")
|
||||||
|
* @param haveParam (bool) The option must have a parameter (default False)
|
||||||
*/
|
*/
|
||||||
public class ArgDefine {
|
public ArgDefine(final String smallOption, final String bigOption, final List<ArgChoice> list, final String desc, final boolean haveParam){
|
||||||
String option_small = "";
|
this.optionSmall = smallOption;
|
||||||
String option_big = "";
|
this.optionBig = bigOption;
|
||||||
private List<ArgChoice> list = new ArrayList<>();
|
|
||||||
/**
|
|
||||||
* @brief Contructor.
|
|
||||||
* @param[in] this Class handle
|
|
||||||
* @param[in] smallOption (char) Value for the small option ex: '-v' '-k' ... 1 single char element (no need of '-')
|
|
||||||
* @param[in] bigOption (string) Value of the big option name ex: '--verbose' '--kill' ... stated with -- and with the full name (no need of '--')
|
|
||||||
* @param[in] list ([[string,string],...]) Optionnal list of availlable option: '--mode=debug' ==> [['debug', 'debug mode'],['release', 'release the software']]
|
|
||||||
* @param[in] desc (string) user friendly description with this parameter (default "")
|
|
||||||
* @param[in] haveParam (bool) The option must have a parameter (default False)
|
|
||||||
*/
|
|
||||||
public ArgDefine(
|
|
||||||
smallOption="",// like v for -v
|
|
||||||
bigOption="",// like verbose for --verbose
|
|
||||||
list=[],// ["val", "description"]
|
|
||||||
desc="",
|
|
||||||
haveParam=False):
|
|
||||||
this.option_small = smallOption;
|
|
||||||
this.option_big = bigOption;
|
|
||||||
this.list = list;
|
this.list = list;
|
||||||
if len(this.list)!=0:
|
if (this.list.size()!=0) {
|
||||||
this.have_param = True
|
this.haveParam = true;
|
||||||
else:
|
} else if (haveParam) {
|
||||||
if True==haveParam:
|
this.haveParam = true;
|
||||||
this.have_param = True
|
} else {
|
||||||
else:
|
this.haveParam = false;
|
||||||
this.have_param = False
|
}
|
||||||
this.description = desc;
|
this.description = desc;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean is_parsable(this):
|
@Override
|
||||||
return True
|
public boolean isParsable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @brief Get the small name of the option ex: '-v'
|
* Get the small name of the option ex{ '-v'
|
||||||
* @param[in] this Class handle
|
* @param this Class handle
|
||||||
* @return (string) Small name value
|
* @return (string) Small name value
|
||||||
*/
|
*/
|
||||||
def get_option_small(this):
|
@Override
|
||||||
return this.option_small
|
public String getOptionSmall(){
|
||||||
|
return this.optionSmall;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the big name of the option ex: '--verbose'
|
* Get the big name of the option ex{ '--verbose'
|
||||||
* @param[in] this Class handle
|
* @param this Class handle
|
||||||
* @return (string) Big name value
|
* @return (string) Big name value
|
||||||
*/
|
*/
|
||||||
publis String get_option_big(this) {
|
@Override
|
||||||
return this.option_big
|
public String getOptionBig() {
|
||||||
|
return this.optionBig;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the status of getting user parameter value
|
* Get the status of getting user parameter value
|
||||||
* @param[in] this Class handle
|
* @param this Class handle
|
||||||
* @return True The user must write a value
|
* @return true; The user must write a value
|
||||||
* @return False The user must NOT write a value
|
* @return false; The user must NOT write a value
|
||||||
*/
|
*/
|
||||||
def need_parameters(this):
|
@Override
|
||||||
return this.have_param
|
public boolean needParameters(){
|
||||||
|
return this.haveParam;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @brief Compatibility with @ref ArgSection class
|
* Compatibility with @ref ArgSection class
|
||||||
* @param[in] this Class handle
|
* @param this Class handle
|
||||||
* @return (string) empty string
|
* @return (string) empty string
|
||||||
*/
|
*/
|
||||||
def get_porperties(this):
|
@Override
|
||||||
return ""
|
public String getPorperties(){
|
||||||
|
return "";
|
||||||
/**
|
}
|
||||||
* @brief Check if the user added value is correct or not with the list of availlable value
|
|
||||||
* @param[in] this Class handle
|
/**
|
||||||
* @param[in] argument (string) User parameter value (string)
|
* Check if the user added value is correct or not with the list of availlable value
|
||||||
* @return True The parameter is OK
|
* @param this Class handle
|
||||||
* @return False The parameter is NOT Availlable
|
* @param argument (string) User parameter value (string)
|
||||||
*/
|
* @return true; The parameter is OK
|
||||||
def check_availlable(this, argument):
|
* @return false; The parameter is NOT Availlable
|
||||||
if len(this.list)==0:
|
*/
|
||||||
return True
|
@Override
|
||||||
for element,desc in this.list:
|
public boolean checkAvaillable(final String argument){
|
||||||
if element == argument:
|
if (this.list.isEmpty()) {
|
||||||
return True
|
return true;
|
||||||
return False
|
}
|
||||||
|
for (ArgChoice elem : this.list){
|
||||||
/**
|
if (elem.val().equals(argument)){
|
||||||
* @brief Display the argument property when user request help
|
return true;
|
||||||
* @param[in] this Class handle
|
}
|
||||||
*/
|
}
|
||||||
def display(this):
|
return false;
|
||||||
color = debug.get_color_set()
|
}
|
||||||
if this.option_small != "" and this.option_big != "":
|
/**
|
||||||
print(" " + color['red'] + "-" + this.option_small + "" + color['default'] + " / " + color['red'] + "--" + this.option_big + color['default'])
|
* Display the argument property when user request help
|
||||||
elif this.option_small != "":
|
* @param this Class handle
|
||||||
print(" " + color['red'] + "-" + this.option_small + color['default'])
|
*/
|
||||||
elif this.option_big != "":
|
@Override
|
||||||
print(" " + color['red'] + "--" + this.option_big + color['default'])
|
public void display() {
|
||||||
else:
|
if (!this.optionSmall.isEmpty() && !this.optionBig.isEmpty()){
|
||||||
print(" ???? ==> internal error ...")
|
Log.print(" -" + this.optionSmall + " / --" + this.optionBig);
|
||||||
if this.description != "":
|
} else if (!this.optionSmall.isEmpty()){
|
||||||
print(" " + this.description)
|
Log.print(" -" + this.optionSmall);
|
||||||
if len(this.list)!=0:
|
} else if (!this.optionBig.isEmpty()){
|
||||||
hasDescriptiveElement=False
|
Log.print(" --" + this.optionBig);
|
||||||
for val,desc in this.list:
|
} else {
|
||||||
if desc!="":
|
Log.print(" ???? ==> internal error ...");
|
||||||
hasDescriptiveElement=True
|
}
|
||||||
break;
|
if (!this.description.isEmpty()){
|
||||||
if hasDescriptiveElement==True:
|
Log.print(" " + this.description);
|
||||||
for val,desc in this.list:
|
}
|
||||||
print(" " + val + " : " + desc)
|
if (!this.list.isEmpty()){
|
||||||
else:
|
boolean hasDescriptiveElement = false;
|
||||||
tmpElementPrint = ""
|
for (ArgChoice elem : this.list) {
|
||||||
for val,desc in this.list:
|
if (!elem.description().isEmpty()) {
|
||||||
if len(tmpElementPrint)!=0:
|
hasDescriptiveElement = true;
|
||||||
tmpElementPrint += " / "
|
break;
|
||||||
tmpElementPrint += val
|
}
|
||||||
print(" { " + tmpElementPrint + " }")
|
}
|
||||||
|
if (hasDescriptiveElement) {
|
||||||
|
for (ArgChoice elem : this.list){
|
||||||
|
Log.print(" " + elem.val() + " { " + elem.description());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
String tmpElementPrint = "";
|
||||||
|
for (ArgChoice elem : this.list){
|
||||||
|
if (!tmpElementPrint.isEmpty()) {
|
||||||
|
tmpElementPrint += " / ";
|
||||||
|
}
|
||||||
|
tmpElementPrint += elem.val();
|
||||||
|
}
|
||||||
|
Log.print(" { " + tmpElementPrint + " }");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
53
src/org/atriasoft/death/ArgElement.java
Normal file
53
src/org/atriasoft/death/ArgElement.java
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
package org.atriasoft.death;
|
||||||
|
|
||||||
|
import org.atriasoft.death.internal.Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Single argument class. It permit to define the getted argument.
|
||||||
|
*/
|
||||||
|
public class ArgElement {
|
||||||
|
private final String option;
|
||||||
|
private final String arg;
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
* @param this Class handle
|
||||||
|
* @param option (string) Option name (write in fullmode ex{ '--verbose' even if user write '-v')
|
||||||
|
* @param value (string) Writed value by the user (defult '')
|
||||||
|
*/
|
||||||
|
public ArgElement(final String option, final String value) {
|
||||||
|
this.option = option;
|
||||||
|
this.arg = value;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Get the name of the argument{ (write in fullmode ex{ '--verbose' even if user write '-v')
|
||||||
|
* @param this Class handle
|
||||||
|
* @return (string) The argument name
|
||||||
|
*/
|
||||||
|
public String getOptionName(){
|
||||||
|
return this.option;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get argument data set by the user
|
||||||
|
* @param this Class handle
|
||||||
|
* @return (string) The argument value
|
||||||
|
*/
|
||||||
|
public String getArg(){
|
||||||
|
return this.arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the Argument property
|
||||||
|
* @param this Class handle
|
||||||
|
*/
|
||||||
|
public void display() {
|
||||||
|
if (this.arg.isEmpty()) {
|
||||||
|
Log.info("option { " + this.option);
|
||||||
|
} else if ( this.option.isEmpty()) {
|
||||||
|
Log.info("element { " + this.arg);
|
||||||
|
}else{
|
||||||
|
Log.info("option { " + this.option + "{" + this.arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
53
src/org/atriasoft/death/ArgInterface.java
Normal file
53
src/org/atriasoft/death/ArgInterface.java
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
package org.atriasoft.death;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Declare an argument value and store it in a parameter
|
||||||
|
*/
|
||||||
|
public interface ArgInterface {
|
||||||
|
boolean isParsable();
|
||||||
|
/**
|
||||||
|
* Get the small name of the option ex{ '-v'
|
||||||
|
* @param this Class handle
|
||||||
|
* @return (string) Small name value
|
||||||
|
*/
|
||||||
|
public String getOptionSmall();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the big name of the option ex{ '--verbose'
|
||||||
|
* @param this Class handle
|
||||||
|
* @return (string) Big name value
|
||||||
|
*/
|
||||||
|
public String getOptionBig();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the status of getting user parameter value
|
||||||
|
* @param this Class handle
|
||||||
|
* @return true; The user must write a value
|
||||||
|
* @return false; The user must NOT write a value
|
||||||
|
*/
|
||||||
|
public boolean needParameters();
|
||||||
|
/**
|
||||||
|
* Compatibility with @ref ArgSection class
|
||||||
|
* @param this Class handle
|
||||||
|
* @return (string) empty string
|
||||||
|
*/
|
||||||
|
public String getPorperties();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the user added value is correct or not with the list of availlable value
|
||||||
|
* @param this Class handle
|
||||||
|
* @param argument (string) User parameter value (string)
|
||||||
|
* @return true; The parameter is OK
|
||||||
|
* @return false; The parameter is NOT Availlable
|
||||||
|
*/
|
||||||
|
public boolean checkAvaillable(final String argument);
|
||||||
|
/**
|
||||||
|
* Display the argument property when user request help
|
||||||
|
* @param this Class handle
|
||||||
|
*/
|
||||||
|
public void display() ;
|
||||||
|
|
||||||
|
default boolean isOptionnal() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
78
src/org/atriasoft/death/ArgSection.java
Normal file
78
src/org/atriasoft/death/ArgSection.java
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
package org.atriasoft.death;
|
||||||
|
|
||||||
|
import org.atriasoft.death.internal.Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Section Class definition (permit to add a comment when requesting help
|
||||||
|
*/
|
||||||
|
public class ArgSection implements ArgInterface {
|
||||||
|
private final String description;
|
||||||
|
private final String section;
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param this Class handle
|
||||||
|
* @param sectionName (string) Name of the cestion ex{ "option" is displayed [option]
|
||||||
|
* @param desc (string) Comment assiciated with the group
|
||||||
|
*/
|
||||||
|
public ArgSection(final String sectionName, final String desc) {
|
||||||
|
this.section = sectionName;
|
||||||
|
this.description = desc;
|
||||||
|
}
|
||||||
|
public ArgSection(final String sectionName) {
|
||||||
|
this(sectionName,"");
|
||||||
|
}
|
||||||
|
public ArgSection() {
|
||||||
|
this("");
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean isParsable(){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Compatibility with @ref ArgDefine class
|
||||||
|
* @param this Class handle
|
||||||
|
* @return empty string
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getOptionSmall(){
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compatibility with @ref ArgDefine class
|
||||||
|
* @param this Class handle
|
||||||
|
* @return empty string
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getOptionBig(){
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get property print value with the correct writing mode
|
||||||
|
* @param this Class handle
|
||||||
|
* @return String to display in the short line help
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getPorperties(){
|
||||||
|
return " [" + this.section + "]";
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Display the argument property when user request help
|
||||||
|
* @param this Class handle
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void display(){
|
||||||
|
Log.print(" [" + this.section + "] { " + this.description);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean needParameters() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean checkAvaillable(final String argument) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
115
src/org/atriasoft/death/ArgVolatile.java
Normal file
115
src/org/atriasoft/death/ArgVolatile.java
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
package org.atriasoft.death;
|
||||||
|
|
||||||
|
import org.atriasoft.death.internal.Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Declare an argument value and store it in a parameter
|
||||||
|
*/
|
||||||
|
public class ArgVolatile implements ArgInterface {
|
||||||
|
private final String destOption;
|
||||||
|
private final boolean optionnal;
|
||||||
|
private final String description;
|
||||||
|
private int count = 0;
|
||||||
|
|
||||||
|
public ArgVolatile() {
|
||||||
|
this("");
|
||||||
|
}
|
||||||
|
public ArgVolatile(final String destOption) {
|
||||||
|
this(destOption, false);
|
||||||
|
}
|
||||||
|
public ArgVolatile(final String destOption, final boolean optionnal) {
|
||||||
|
this(destOption, optionnal, "");
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Contructor.
|
||||||
|
* @param this Class handle
|
||||||
|
* @param destOption (string) Where to store the option name
|
||||||
|
* @param optionnal (bool) this element can be not present
|
||||||
|
* @param desc (string) user friendly description with this parameter (default "")
|
||||||
|
*/
|
||||||
|
public ArgVolatile(final String destOption, final boolean optionnal, final String desc ) {
|
||||||
|
this.destOption = destOption;
|
||||||
|
if (destOption.isEmpty()) {
|
||||||
|
Log.critical("volatil argument must be store in an argument name");
|
||||||
|
}
|
||||||
|
this.optionnal = optionnal;
|
||||||
|
this.description = desc;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean isParsable(){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Get the small name of the option ex{ '-v'
|
||||||
|
* @param this Class handle
|
||||||
|
* @return (string) Small name value
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getOptionSmall(){
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the big name of the option ex{ '--verbose'
|
||||||
|
* @param this Class handle
|
||||||
|
* @return (string) Big name value
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getOptionBig(){
|
||||||
|
return this.destOption;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the status of getting user parameter value
|
||||||
|
* @param this Class handle
|
||||||
|
* @return true; The user must write a value
|
||||||
|
* @return false; The user must NOT write a value
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean needParameters(){
|
||||||
|
if (this.count == 0) {
|
||||||
|
this.count++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Compatibility with @ref ArgSection class
|
||||||
|
* @param this Class handle
|
||||||
|
* @return (string) empty string
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getPorperties() {
|
||||||
|
return " [" + this.destOption + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the user added value is correct or not with the list of availlable value
|
||||||
|
* @param this Class handle
|
||||||
|
* @param argument (string) User parameter value (string)
|
||||||
|
* @return true; The parameter is OK
|
||||||
|
* @return false; The parameter is NOT Availlable
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean checkAvaillable(final String argument){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Display the argument property when user request help
|
||||||
|
* @param this Class handle
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void display() {
|
||||||
|
Log.print(" [" + this.destOption + "]");
|
||||||
|
if (this.optionnal) {
|
||||||
|
Log.print("(OPTIONNAL)");
|
||||||
|
}
|
||||||
|
if (this.description != "") {
|
||||||
|
Log.print(" " + this.description);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean isOptionnal() {
|
||||||
|
return this.optionnal;
|
||||||
|
}
|
||||||
|
}
|
299
src/org/atriasoft/death/Arguments.java
Normal file
299
src/org/atriasoft/death/Arguments.java
Normal file
@ -0,0 +1,299 @@
|
|||||||
|
package org.atriasoft.death;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.atriasoft.death.internal.Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to define the argument list available for a program
|
||||||
|
*/
|
||||||
|
public class Arguments {
|
||||||
|
private final List<ArgInterface> listProperties = new ArrayList<>();
|
||||||
|
private List<String> listElementStop = new ArrayList<>();
|
||||||
|
private int lastElementParsed = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
* @param this Class handle
|
||||||
|
*/
|
||||||
|
public Arguments(){
|
||||||
|
}
|
||||||
|
public void add(){
|
||||||
|
add("");
|
||||||
|
}
|
||||||
|
public void add(final String smallOption){
|
||||||
|
add(smallOption, "");
|
||||||
|
}
|
||||||
|
public void add(final String smallOption, final String bigOption){
|
||||||
|
add(smallOption, bigOption, new ArrayList<>());
|
||||||
|
}
|
||||||
|
public void add(final String smallOption, final String bigOption, final List<ArgChoice> list){
|
||||||
|
add(smallOption, bigOption, list, "");
|
||||||
|
}
|
||||||
|
public void add(final String smallOption, final String bigOption, final List<ArgChoice> list, final String desc){
|
||||||
|
add(smallOption, bigOption, list, desc, false);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Add a new argument possibilities...
|
||||||
|
* @param this Class handle
|
||||||
|
* @param smallOption (char) Value for the small option ex{ '-v' '-k' ... 1 single char element (no need of '-')
|
||||||
|
* @param bigOption (string) Value of the big option name ex{ '--verbose' '--kill' ... stated with -- and with the full name (no need of '--')
|
||||||
|
* @param list ([[string,string],...]) Optionnal list of availlable option{ '--mode=debug' ==> [['debug', 'debug mode'],['release', 'release the software']]
|
||||||
|
* @param desc (string) user friendly description with this parameter (default "")
|
||||||
|
* @param haveParam (bool) The option must have a parameter (default false)
|
||||||
|
*/
|
||||||
|
public ArgDefine add(final String smallOption, final String bigOption, final List<ArgChoice> list, final String desc, final boolean haveParam){
|
||||||
|
ArgDefine tmp = new ArgDefine(smallOption, bigOption, list, desc, haveParam);
|
||||||
|
this.listProperties.add(tmp);
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
public void addArg(){
|
||||||
|
addArg("");
|
||||||
|
}
|
||||||
|
public void addArg(final String destOption){
|
||||||
|
addArg(destOption, false);
|
||||||
|
}
|
||||||
|
public void addArg(final String destOption, final boolean optionnal){
|
||||||
|
addArg(destOption, optionnal, "");
|
||||||
|
}
|
||||||
|
public void addArg(final String destOption, final boolean optionnal, final String desc){
|
||||||
|
this.listProperties.add(new ArgVolatile(destOption, optionnal, desc));
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Add section on argument list
|
||||||
|
* @param this Class handle
|
||||||
|
* @param sectionName (string) Name of the cestion ex{ "option" is displayed [option]
|
||||||
|
* @param sectionDesc (string) Comment assiciated with the group
|
||||||
|
*/
|
||||||
|
public void addSection(final String sectionName, final String sectionDesc){
|
||||||
|
this.listProperties.add(new ArgSection(sectionName, sectionDesc));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void parse(final List<String> args) {
|
||||||
|
parse(args, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void parse(final List<String> args, final int startPositionParsing) {
|
||||||
|
parse(args, startPositionParsing, false);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Parse the argument set in the command line
|
||||||
|
* @param this Class handle
|
||||||
|
* @param startPositionParsing position to start the parsing in the arguments
|
||||||
|
*/
|
||||||
|
public List<ArgElement> parse(final List<String> args, final int startPositionParsing, final boolean haveUnknowArgument) {
|
||||||
|
List<ArgElement> listArgument = new ArrayList<>();// composed of list element
|
||||||
|
boolean notParseNextElement=false;
|
||||||
|
for (int iii=startPositionParsing; iii <args.size(); iii++){
|
||||||
|
this.lastElementParsed = iii;
|
||||||
|
// special case of parameter in some elements
|
||||||
|
if ( notParseNextElement) {
|
||||||
|
notParseNextElement = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Log.verbose("parse [" + iii + "]=" + args.get(iii));
|
||||||
|
String argument = args.get(iii);
|
||||||
|
// check if we get a stop parsing element{
|
||||||
|
if (this.listElementStop.contains(argument)) {
|
||||||
|
Log.debug("stop at position{ " + iii);
|
||||||
|
listArgument.add(new ArgElement("", argument));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
String[] optionList = argument.split("=");
|
||||||
|
Log.verbose("ListArgument = " + optionList);
|
||||||
|
String option = optionList[0];
|
||||||
|
String optionParam = argument.substring(option.length()+1);
|
||||||
|
Log.verbose(" option= " + option);
|
||||||
|
Log.verbose(" optionParam= " + optionParam);
|
||||||
|
boolean argumentFound=false;
|
||||||
|
if (option.startsWith("--")){
|
||||||
|
// big argument
|
||||||
|
for (ArgInterface prop :this.listProperties) {
|
||||||
|
if (!prop.isParsable()){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (prop.getOptionBig().isEmpty()){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (prop.getOptionBig().equals(option.substring(2))){
|
||||||
|
// find it
|
||||||
|
Log.verbose("find argument 2 { " + option.substring(2));
|
||||||
|
if (prop.needParameters()) {
|
||||||
|
String internalSub = option.substring(2+prop.getOptionBig().length());
|
||||||
|
if (!internalSub.isEmpty()) {
|
||||||
|
if (!optionParam.isEmpty()){
|
||||||
|
// wrong argument ...
|
||||||
|
Log.warning("maybe wrong argument for { '" + prop.getOptionBig() + "' cmdLine='" + argument + "'");
|
||||||
|
prop.display();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
optionParam = internalSub;
|
||||||
|
}
|
||||||
|
if (optionParam.isEmpty()) {
|
||||||
|
// Get the next parameters
|
||||||
|
if (args.size() > iii+1) {
|
||||||
|
optionParam = args.get(iii+1);
|
||||||
|
notParseNextElement=true;
|
||||||
|
} else {
|
||||||
|
// missing arguments
|
||||||
|
Log.warning("parsing argument error { '" + prop.getOptionBig() + "' Missing { subParameters ... cmdLine='" + argument + "'");
|
||||||
|
prop.display();
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!prop.checkAvaillable(optionParam)){
|
||||||
|
Log.warning("argument error { '" + prop.getOptionBig() + "' SubParameters not availlable ... cmdLine='" + argument + "' option='" + optionParam + "'");
|
||||||
|
prop.display();
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
listArgument.add(new ArgElement(prop.getOptionBig(),optionParam));
|
||||||
|
argumentFound = true;
|
||||||
|
} else {
|
||||||
|
if (!optionParam.isEmpty()) {
|
||||||
|
Log.warning("parsing argument error { '" + prop.getOptionBig() + "' need no subParameters { '" + optionParam + "' cmdLine='" + argument + "'");
|
||||||
|
prop.display();
|
||||||
|
}
|
||||||
|
listArgument.add(new ArgElement(prop.getOptionBig(), ""));
|
||||||
|
argumentFound = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!argumentFound) {
|
||||||
|
if (!haveUnknowArgument) {
|
||||||
|
Log.error("UNKNOW argument { '" + argument + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (option.startsWith("-")) {
|
||||||
|
// small argument
|
||||||
|
for (ArgInterface prop : this.listProperties) {
|
||||||
|
if (!prop.isParsable()){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (prop.getOptionSmall().isEmpty()){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (prop.getOptionSmall() == option.substring(1, 1+prop.getOptionSmall().length())) {
|
||||||
|
// find it
|
||||||
|
Log.verbose("find argument 1 { " + option.substring(1, 1+prop.getOptionSmall().length()));
|
||||||
|
if (prop.needParameters()) {
|
||||||
|
String internalSub = option.substring(1+prop.getOptionSmall().length());
|
||||||
|
if (!internalSub.isEmpty()){
|
||||||
|
if (!optionParam.isEmpty()) {
|
||||||
|
// wrong argument ...
|
||||||
|
Log.warning("maybe wrong argument for { '" + prop.getOptionBig() + "' cmdLine='" + argument + "'");
|
||||||
|
prop.display();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
optionParam = internalSub;
|
||||||
|
}
|
||||||
|
if (optionParam.isEmpty()){
|
||||||
|
// Get the next parameters
|
||||||
|
if (args.size() > iii+1) {
|
||||||
|
optionParam = args.get(iii+1);
|
||||||
|
notParseNextElement=true;
|
||||||
|
} else {
|
||||||
|
// missing arguments
|
||||||
|
Log.warning("parsing argument error { '" + prop.getOptionBig() + "' Missing { subParameters cmdLine='" + argument + "'");
|
||||||
|
prop.display();
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!prop.checkAvaillable(optionParam)) {
|
||||||
|
Log.warning("argument error { '" + prop.getOptionBig() + "' SubParameters not availlable ... cmdLine='" + argument + "' option='" + optionParam + "'");
|
||||||
|
prop.display();
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
listArgument.add(new ArgElement(prop.getOptionBig(),optionParam));
|
||||||
|
argumentFound = true;
|
||||||
|
}else{
|
||||||
|
if (!optionParam.isEmpty()){
|
||||||
|
Log.warning("parsing argument error { '" + prop.getOptionBig() + "' need no subParameters { '" + optionParam + "' cmdLine='" + argument + "'");
|
||||||
|
prop.display();
|
||||||
|
}
|
||||||
|
listArgument.add(new ArgElement(prop.getOptionBig(), ""));
|
||||||
|
argumentFound = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!argumentFound) {
|
||||||
|
// small argument
|
||||||
|
for (ArgInterface prop : this.listProperties) {
|
||||||
|
if (prop.isParsable() || prop.getOptionBig().isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (prop.needParameters()) {
|
||||||
|
listArgument.add(new ArgElement(prop.getOptionBig(), argument));
|
||||||
|
argumentFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!argumentFound) {
|
||||||
|
// unknow element ... ==> just add in the list ...
|
||||||
|
Log.verbose("unknow argument { " + argument);
|
||||||
|
listArgument.add(new ArgElement("", argument));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// for prop in this.list_properties{
|
||||||
|
// Log.info(" opt=[" + prop.get_option_big() + "] parsable=" + str(prop.is_parsable()))
|
||||||
|
|
||||||
|
// This is a real specific case in home user will have an help that is printed "help"
|
||||||
|
boolean helpIsRequest = false;
|
||||||
|
for ( ArgElement argument : listArgument) {
|
||||||
|
// argument.display()
|
||||||
|
if (argument.getOptionName().equals("help")) {
|
||||||
|
helpIsRequest = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ArgInterface prop : this.listProperties) {
|
||||||
|
if (prop.isParsable() || prop.getOptionBig().isEmpty() ){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (prop.needParameters() && !prop.isOptionnal()) {
|
||||||
|
Log.critical("Missing argument{ [" + prop.getOptionBig() + "]");//, crash = (help_is_request==false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// for argument in list_argument{
|
||||||
|
// argument.display()
|
||||||
|
// exit(0)
|
||||||
|
return listArgument;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop parsing at a specific position
|
||||||
|
* @param this Class handle
|
||||||
|
* @param listOfElement List of element that stop the parsing
|
||||||
|
*/
|
||||||
|
public void setStopAt(final List<String> listOfElement){
|
||||||
|
this.listElementStop = listOfElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the last element parsed.
|
||||||
|
* @param this Class handle
|
||||||
|
*/
|
||||||
|
public int getLastParsed(){
|
||||||
|
return this.lastElementParsed;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Display help on console output
|
||||||
|
* @param this Class handle
|
||||||
|
* @param actionName opation to set at the end of the application name
|
||||||
|
*/
|
||||||
|
public void display(final String actionName){
|
||||||
|
Log.print("usage:");
|
||||||
|
String listOfPropertiesArg = "";
|
||||||
|
for (ArgInterface element : this.listProperties) {
|
||||||
|
listOfPropertiesArg += element.getPorperties();
|
||||||
|
}
|
||||||
|
Log.print(" " + actionName + " " + listOfPropertiesArg + " ...");
|
||||||
|
for (ArgInterface element : this.listProperties) {
|
||||||
|
element.display();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,151 +0,0 @@
|
|||||||
package org.atriasoft.death;
|
|
||||||
//!/usr/bin/python
|
|
||||||
// -*- coding: utf-8 -*-
|
|
||||||
//#
|
|
||||||
//# @author Edouard DUPIN
|
|
||||||
//#
|
|
||||||
//# @copyright 2012, Edouard DUPIN, all right reserved
|
|
||||||
//#
|
|
||||||
//# @license MPL v2.0 (see license file)
|
|
||||||
//#
|
|
||||||
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
// Local import
|
|
||||||
import org.atriasoft.death.internal.Log;
|
|
||||||
|
|
||||||
public class Env {
|
|
||||||
|
|
||||||
public static final int ret_manifest_is_not_existing = -5;
|
|
||||||
public static final int ret_action_is_not_existing = -10;
|
|
||||||
public static final int ret_action_executing_system_error = -11;
|
|
||||||
public static final int ret_action_wrong_parameters = -12;
|
|
||||||
public static final int ret_action_partial_done = -13;
|
|
||||||
public static final int ret_action_fail = -14;
|
|
||||||
|
|
||||||
public static int ret_action_need_updtate = 15;
|
|
||||||
|
|
||||||
public static String system_base_name = "island";
|
|
||||||
|
|
||||||
public static void set_system_base_name(String val) {
|
|
||||||
system_base_name = val;
|
|
||||||
}
|
|
||||||
public static String get_system_base_name() {
|
|
||||||
return system_base_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String get_system_config_name() {
|
|
||||||
return "." + system_base_name + "Config.json";
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean fetch_manifest = true;
|
|
||||||
|
|
||||||
public static void set_fetch_manifest(boolean val) {
|
|
||||||
fetch_manifest = val;
|
|
||||||
}
|
|
||||||
public static boolean get_fetch_manifest() {
|
|
||||||
return fetch_manifest;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int wait_between_sever_command = 0;
|
|
||||||
|
|
||||||
public static void set_wait_between_sever_command(int val) {
|
|
||||||
wait_between_sever_command = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int get_wait_between_sever_command() {
|
|
||||||
return wait_between_sever_command;
|
|
||||||
}
|
|
||||||
public static String filter_command = "";
|
|
||||||
|
|
||||||
public static void set_filter_command(String val) {
|
|
||||||
filter_command = val;
|
|
||||||
}
|
|
||||||
public static String get_filter_command() {
|
|
||||||
return filter_command;
|
|
||||||
}
|
|
||||||
public static boolean need_process_with_filter(String data) {
|
|
||||||
if (filter_command.equals("")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (data.length() < filter_command.length()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (data.substring(0,filter_command.length()).equals(filter_command)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean display_folder_instead_of_git_name = true;
|
|
||||||
|
|
||||||
public static void set_display_folder_instead_of_git_name(boolean val) {
|
|
||||||
display_folder_instead_of_git_name = val;
|
|
||||||
}
|
|
||||||
public static boolean get_display_folder_instead_of_git_name() {
|
|
||||||
return display_folder_instead_of_git_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Path island_root_path = null;
|
|
||||||
private static Path island_path_user_config = null;
|
|
||||||
private static Path island_path = null;
|
|
||||||
private static Path island_path_config_old = null;
|
|
||||||
private static Path island_path_config = null;
|
|
||||||
private static Path island_path_manifest = null;
|
|
||||||
|
|
||||||
|
|
||||||
static {
|
|
||||||
//String tmp = island_root_path.toAbsolutePath().toString();
|
|
||||||
//Log.info("Current absolute path is: " + tmp);
|
|
||||||
island_root_path = Paths.get("");
|
|
||||||
Path tmpPath = island_root_path;
|
|
||||||
while (!Files.isDirectory(tmpPath.resolve("." + get_system_base_name()))) {
|
|
||||||
tmpPath = tmpPath.getParent();
|
|
||||||
if (tmpPath == null) {
|
|
||||||
Log.critical("the root path of " + get_system_base_name() + " must not be upper parent paths of (" + island_root_path.toAbsolutePath() + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
island_root_path = tmpPath;
|
|
||||||
island_path_user_config = island_root_path.resolve(get_system_config_name());
|
|
||||||
island_path = island_root_path.resolve("." + get_system_base_name());
|
|
||||||
island_path_config_old = island_path.resolve("config.txt");
|
|
||||||
island_path_config = island_path.resolve("config.json");
|
|
||||||
island_path_manifest = island_path.resolve("manifest");
|
|
||||||
}
|
|
||||||
//#
|
|
||||||
//# @brief to use later to know where the ".island" parent path is ...
|
|
||||||
//# @return the parent path of the ".island"
|
|
||||||
//#
|
|
||||||
public static Path get_island_root_path() {
|
|
||||||
return island_root_path;
|
|
||||||
}
|
|
||||||
public static Path get_island_path() {
|
|
||||||
return island_path;
|
|
||||||
}
|
|
||||||
public static Path get_island_path_config() {
|
|
||||||
return island_path_config;
|
|
||||||
}
|
|
||||||
public static Path get_island_path_config_old() {
|
|
||||||
return island_path_config_old;
|
|
||||||
}
|
|
||||||
public static Path get_island_path_manifest() {
|
|
||||||
return island_path_manifest;
|
|
||||||
}
|
|
||||||
public static Path get_island_path_user_config() {
|
|
||||||
return island_path_user_config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Log.error("island_root_path = " + island_root_path.toAbsolutePath());
|
|
||||||
Log.error("island_path_user_config = " + island_path_user_config.toAbsolutePath());
|
|
||||||
Log.error("island_path = " + island_path.toAbsolutePath());
|
|
||||||
Log.error("island_path_config_old = " + island_path_config_old.toAbsolutePath());
|
|
||||||
Log.error("island_path_config = " + island_path_config.toAbsolutePath());
|
|
||||||
Log.error("island_path_manifest = " + island_path_manifest.toAbsolutePath());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,185 +0,0 @@
|
|||||||
package org.atriasoft.death;
|
|
||||||
|
|
||||||
|
|
||||||
public class MainIsland {
|
|
||||||
|
|
||||||
debug.verbose("List of actions: " + str(actions.get_list_of_action()))
|
|
||||||
|
|
||||||
my_args = arguments.Arguments()
|
|
||||||
my_args.add_section("option", "Can be set one time in all case")
|
|
||||||
my_args.add("h", "help", desc="Display this help")
|
|
||||||
my_args.add("v", "verbose", list=[
|
|
||||||
["0","None"],
|
|
||||||
["1","error"],
|
|
||||||
["2","warning"],
|
|
||||||
["3","info"],
|
|
||||||
["4","debug"],
|
|
||||||
["5","verbose"],
|
|
||||||
["6","extreme_verbose"],
|
|
||||||
], desc="display debug level (verbose) default =2")
|
|
||||||
my_args.add("c", "color", desc="Display message in color")
|
|
||||||
my_args.add("n", "no-fetch-manifest", haveParam=false, desc="Disable the fetch of the manifest")
|
|
||||||
my_args.add("F", "filter", haveParam=true, desc="Filter the action on a list of path or subpath: -f library")
|
|
||||||
my_args.add("f", "folder", haveParam=false, desc="Display the folder instead of the git repository name")
|
|
||||||
my_args.add("w", "wait", haveParam=true, desc="Wait between 2 acces on the server (needed when the server is really slow to remove ssh connection) (default=" + str(env.get_wait_between_sever_command()) + ")")
|
|
||||||
my_args.set_stop_at(actions.get_list_of_action())
|
|
||||||
local_argument = my_args.parse()
|
|
||||||
|
|
||||||
//
|
|
||||||
// @brief Display the help of this makefile.
|
|
||||||
//
|
|
||||||
public void usage():
|
|
||||||
color = debug.get_color_set()
|
|
||||||
// generic argument displayed :
|
|
||||||
my_args.display()
|
|
||||||
print(" Action availlable" )
|
|
||||||
list_actions = actions.get_list_of_action();
|
|
||||||
for elem in list_actions:
|
|
||||||
print(" " + color['green'] + elem + color['default'])
|
|
||||||
print(" " + actions.get_action_help(elem))
|
|
||||||
"""
|
|
||||||
print(" " + color['green'] + "init" + color['default'])
|
|
||||||
print(" initialize a 'island' interface with a manifest in a git ")
|
|
||||||
print(" " + color['green'] + "sync" + color['default'])
|
|
||||||
print(" Syncronise the currect environement")
|
|
||||||
print(" " + color['green'] + "status" + color['default'])
|
|
||||||
print(" Dump the status of the environement")
|
|
||||||
"""
|
|
||||||
print(" ex: " + sys.argv[0] + " -c init http://github.com/atria-soft/manifest.git")
|
|
||||||
print(" ex: " + sys.argv[0] + " sync")
|
|
||||||
exit(0)
|
|
||||||
|
|
||||||
public void check_boolean(value):
|
|
||||||
if value == "" \
|
|
||||||
or value == "1" \
|
|
||||||
or value == "true" \
|
|
||||||
or value == "true" \
|
|
||||||
or value == true:
|
|
||||||
return true
|
|
||||||
return false
|
|
||||||
|
|
||||||
// preparse the argument to get the verbose element for debug mode
|
|
||||||
public void parse_generic_arg(argument, active):
|
|
||||||
debug.extreme_verbose("parse arg : " + argument.get_option_name() + " " + argument.get_arg() + " active=" + str(active))
|
|
||||||
if argument.get_option_name() == "help":
|
|
||||||
if active == false:
|
|
||||||
usage()
|
|
||||||
return true
|
|
||||||
elif argument.get_option_name()=="jobs":
|
|
||||||
if active == true:
|
|
||||||
//multiprocess.set_core_number(int(argument.get_arg()))
|
|
||||||
pass
|
|
||||||
return true
|
|
||||||
elif argument.get_option_name()=="wait":
|
|
||||||
if active == true:
|
|
||||||
env.set_wait_between_sever_command(int(argument.get_arg()))
|
|
||||||
return true
|
|
||||||
elif argument.get_option_name() == "verbose":
|
|
||||||
if active == true:
|
|
||||||
debug.set_level(int(argument.get_arg()))
|
|
||||||
return true
|
|
||||||
elif argument.get_option_name() == "folder":
|
|
||||||
if active == true:
|
|
||||||
env.set_display_folder_instead_of_git_name(true)
|
|
||||||
return true
|
|
||||||
elif argument.get_option_name() == "color":
|
|
||||||
if active == true:
|
|
||||||
if check_boolean(argument.get_arg()) == true:
|
|
||||||
debug.enable_color()
|
|
||||||
else:
|
|
||||||
debug.disable_color()
|
|
||||||
return true
|
|
||||||
elif argument.get_option_name() == "filter":
|
|
||||||
if active == true:
|
|
||||||
env.set_filter_command(str(argument.get_arg()))
|
|
||||||
return true
|
|
||||||
elif argument.get_option_name() == "no-fetch-manifest":
|
|
||||||
if active == false:
|
|
||||||
env.set_fetch_manifest(false)
|
|
||||||
return true
|
|
||||||
return false
|
|
||||||
|
|
||||||
// open configuration of island:
|
|
||||||
config_file = env.get_island_path_user_config()
|
|
||||||
if os.path.isfile(config_file) == true:
|
|
||||||
sys.path.append(os.path.dirname(config_file))
|
|
||||||
debug.debug("Find basic configuration file: '" + config_file + "'")
|
|
||||||
// the file exist, we can open it and get the initial configuration:
|
|
||||||
configuration_file = __import__(env.get_system_config_name()[:-3])
|
|
||||||
|
|
||||||
if "get_exclude_path" in dir(configuration_file):
|
|
||||||
data = configuration_file.get_exclude_path()
|
|
||||||
debug.debug(" get default config 'get_exclude_path' val='" + str(data) + "'")
|
|
||||||
env.set_exclude_search_path(data)
|
|
||||||
|
|
||||||
if "get_default_color" in dir(configuration_file):
|
|
||||||
data = configuration_file.get_default_color()
|
|
||||||
debug.debug(" get default config 'get_default_color' val='" + str(data) + "'")
|
|
||||||
parse_generic_arg(arg_element.ArgElement("color", str(data)), true)
|
|
||||||
|
|
||||||
if "get_default_debug_level" in dir(configuration_file):
|
|
||||||
data = configuration_file.get_default_debug_level()
|
|
||||||
debug.debug(" get default config 'get_default_debug_level' val='" + str(data) + "'")
|
|
||||||
parse_generic_arg(arg_element.ArgElement("verbose", str(data)), true)
|
|
||||||
|
|
||||||
if "get_default_folder" in dir(configuration_file):
|
|
||||||
data = configuration_file.get_default_folder()
|
|
||||||
debug.debug(" get default config 'get_default_folder' val='" + str(data) + "'")
|
|
||||||
parse_generic_arg(arg_element.ArgElement("folder", str(data)), true)
|
|
||||||
|
|
||||||
if "get_default_wait" in dir(configuration_file):
|
|
||||||
data = configuration_file.get_default_wait()
|
|
||||||
debug.debug(" get default config 'get_default_wait' val='" + str(data) + "'")
|
|
||||||
parse_generic_arg(arg_element.ArgElement("wait", str(data)), true)
|
|
||||||
|
|
||||||
if "get_default_filter" in dir(configuration_file):
|
|
||||||
data = configuration_file.get_default_filter()
|
|
||||||
debug.debug(" get default config 'get_default_filter' val='" + str(data) + "'")
|
|
||||||
parse_generic_arg(arg_element.ArgElement("filter", str(data)), true)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// parse default unique argument:
|
|
||||||
for argument in local_argument:
|
|
||||||
parse_generic_arg(argument, true)
|
|
||||||
|
|
||||||
// remove all generic arguments:
|
|
||||||
new_argument_list = []
|
|
||||||
for argument in local_argument:
|
|
||||||
if parse_generic_arg(argument, false) == true:
|
|
||||||
continue
|
|
||||||
new_argument_list.append(argument)
|
|
||||||
|
|
||||||
// now the first argument is: the action:
|
|
||||||
if len(new_argument_list) == 0:
|
|
||||||
debug.warning("--------------------------------------")
|
|
||||||
debug.warning("Missing the action to do ...")
|
|
||||||
debug.warning("--------------------------------------")
|
|
||||||
usage()
|
|
||||||
|
|
||||||
|
|
||||||
// TODO : move tin in actions ...
|
|
||||||
list_actions = actions.get_list_of_action();
|
|
||||||
|
|
||||||
action_to_do = new_argument_list[0].get_arg()
|
|
||||||
new_argument_list = new_argument_list[1:]
|
|
||||||
if action_to_do not in list_actions:
|
|
||||||
debug.warning("--------------------------------------")
|
|
||||||
debug.warning("Wrong action type : '" + str(action_to_do) + "' availlable list: " + str(list_actions) )
|
|
||||||
debug.warning("--------------------------------------")
|
|
||||||
usage()
|
|
||||||
|
|
||||||
// todo : Remove this
|
|
||||||
if action_to_do != "init" \
|
|
||||||
and os.path.exists(env.get_island_path()) == false:
|
|
||||||
debug.error("Can not execute a island cmd if we have not initialize a config: '" + str("." + env.get_system_base_name()) + "' in upper 6 parent path")
|
|
||||||
exit(-1)
|
|
||||||
|
|
||||||
|
|
||||||
ret = actions.execute(action_to_do, my_args.get_last_parsed()+1)
|
|
||||||
|
|
||||||
exit (ret)
|
|
||||||
// stop all started threads;
|
|
||||||
//multiprocess.un_init()
|
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user