Ignore:
Timestamp:
May 8, 2012, 5:32:10 PM (14 years ago)
Author:
Jorge Pérez <josp.jorge@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
270fc19
Parents:
9062e36
Message:

refs #1502, portando cambios en TolPackage

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@4654 be4846ae-f051-483a-831f-b64e7d08527f

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol/stdlib/TolPackage/common.tol

    r9062e36 r6f9ab22  
    1 /* -*- mode: C++ -*- */
    2 //////////////////////////////////////////////////////////////////////////////
    3 // FILE   : common.tol
    4 // PURPOSE: TolPackage common tools
    5 // Funciones y estructuras comunes al lado de servidor y cliente
    6 //////////////////////////////////////////////////////////////////////////////
    7 
    8 //////////////////////////////////////////////////////////////////////////////
    9 //Información de un paquete que es relevante para la sincronización de las
    10 //copias locales con el repositorio remoto.
    11   Struct @VersionSynchro {
    12 //////////////////////////////////////////////////////////////////////////////
    13   Text te_url,                  //URL of repository
    14   Text co_name,                 //Generic name of package
    15   Text co_name_version,         //Name of versioned package
    16   Text te_extra_info,           //Extra information
    17   Text te_min_tol_version,      //Minimum compatible TOL version
    18   Text te_max_tol_version,      //maximum compatible TOL version
    19   Text te_dependencies,         //Required packages
    20   Date dh_release_date_remote,  //Publication date in remote repository
    21   Date dh_release_date_local,   //Local installing date
    22   Real nu_bytes                 //Size of remote compressed archive
    23 };
    24 
    25 //////////////////////////////////////////////////////////////////////////////
    26 //Información de un paquete que es relevante para la sincronización de las
    27 //copias locales con el repositorio remoto.
     1
     2  // [API útil]
     3  //  * Text _.autodoc.get.identifier(NameBlock package)
     4  //  * NameBlock Require(Text identifier)
     5  //  * Real AddRepository(Text url)
     6  // [API Client+Server]
     7  //  * Real InstallPackage(Text identifier)
     8  //  * Real InstallCompatible(Text pattern, Text tolVersion, Date date)
     9  //  * Real InstallLastCompatible(Text pattern)
     10  //  * Real UpdateAll(Real void)
     11  //  * Real UpgradeAll(Real void)
     12  // [API compatibilidad]
     13  //  % Set _.GetVersSyncInfo(Real void)
     14  //  % Set _.GetPackSyncInfo(Text tolVersion)
     15  //  % Set GetInstallationList(Set packages)
     16  //  * Set AtListA(Text listId)
     17  // <Leyenda>
     18  //  %: Utilizados en la GUI de TolPackage.
     19
     20  ////////////////////////////////////////////////////////////////////////////
     21  Text _.autodoc.get.identifier(NameBlock package)
     22  ////////////////////////////////////////////////////////////////////////////
     23  {
     24    package::_.autodoc.name<<"."
     25      <<package::_.autodoc.version.high<<"."<<package::_.autodoc.version.low
     26  };
     27
     28  ////////////////////////////////////////////////////////////////////////////
     29  NameBlock Require(Text identifier)
     30  ////////////////////////////////////////////////////////////////////////////
     31  {
     32    Real Eval("Real {
     33      #Require "<<identifier<<";
     34    1}");
     35    Eval(Tokenizer(identifier, ".")[1])
     36  };
     37
     38  ////////////////////////////////////////////////////////////////////////////
     39  Text _.autodoc.member.AddRepository =
     40    "Añade un repositorio a la lista de configuración del usuario:\n"
     41    "  Set TolConfigManager::Config::Upgrading::TolPackage::Repositories\n";
     42  Real AddRepository(Text url)
     43  ////////////////////////////////////////////////////////////////////////////
     44  {
     45    Set TolConfigManager::Config::Upgrading::TolPackage::Repositories :=
     46      Unique(TolConfigManager::Config::Upgrading::TolPackage::Repositories <<
     47      [[url]]);
     48    TolConfigManager::SaveConfig(TolConfigManager::Config)
     49  };
     50
     51  ////////////////////////////////////////////////////////////////////////////
     52  Text _AsOSDir(Text dir)
     53  ////////////////////////////////////////////////////////////////////////////
     54  {
     55    // OSDir* utiliza direcciones no acabadas en /
     56    Real length = TextLength(dir);
     57    If(Text Sub(dir, length, length)=="/", Sub(dir, 1, length-1), dir)
     58  };
     59
     60  ////////////////////////////////////////////////////////////////////////////
     61  Real InstallPackage(Text identifier)
     62  ////////////////////////////////////////////////////////////////////////////
     63  {
     64    Real Server::Initialize(?);
     65    Text file = Server::DownloadPackage(identifier);
     66    Real If(TextLength(file), {
     67      Real Client::InstallZip(file);
     68      Real Client::UpdateCatalog(?);
     69    1}, 0)
     70  };
     71
     72  ////////////////////////////////////////////////////////////////////////////
     73  Real InstallCompatible(Text pattern, Text tolVersion, Date date)
     74  ////////////////////////////////////////////////////////////////////////////
     75  {
     76    Real Server::Initialize(?);
     77    Text file = Server::DownloadCompatible(pattern, tolVersion, date);
     78    Real If(TextLength(file), {
     79      Real Client::InstallZip(file);
     80      Real Client::UpdateCatalog(?);
     81    1}, 0)
     82  };
     83
     84  ////////////////////////////////////////////////////////////////////////////
     85  Real InstallLastCompatible(Text pattern)
     86  ////////////////////////////////////////////////////////////////////////////
     87  {
     88    Real Server::Initialize(?);
     89    Text file = Server::DownloadLastCompatible(pattern);
     90    Real If(TextLength(file), {
     91      Real Client::InstallZip(file);
     92      Real Client::UpdateCatalog(?);
     93    1}, 0)
     94  };
     95
     96  ////////////////////////////////////////////////////////////////////////////
     97  Real UpdateAll(Real void)
     98  ////////////////////////////////////////////////////////////////////////////
     99  {
     100    @Catalog client = Client::GetCatalog(?);
     101    @Catalog server = Server::GetCatalog(?);
     102    Set updateList = server::ObtainUpdateList(client, Version, UnknownDate);
     103    If(Card(updateList), SetSum(EvalSet(updateList, Real (Set record) {
     104      WriteLn("[UpdateAll] Se actualiza "<<record::identifier);
     105      InstallPackage(record::identifier)
     106    })), 0)
     107  };
     108
     109  ////////////////////////////////////////////////////////////////////////////
     110  Real UpgradeAll(Real void)
     111  ////////////////////////////////////////////////////////////////////////////
     112  {
     113    @Catalog client = Client::GetCatalog(?);
     114    @Catalog server = Server::GetCatalog(?);
     115    Set upgradeList = server::ObtainUpgradeList(client, Version, UnknownDate);
     116    If(Card(upgradeList), SetSum(EvalSet(upgradeList, Real (Set record) {
     117      WriteLn("[UpgradeAll] Se mejora a "<<record::identifier);
     118      InstallPackage(record::identifier)
     119    })), 0)
     120  };
     121
     122  // Estructuras
     123
     124  ////////////////////////////////////////////////////////////////////////////
     125  // Para la gestión de orígenes de código. (Builder)
     126  Struct @PackageSource
     127  ////////////////////////////////////////////////////////////////////////////
     128  {
     129    Text name;
     130    Text type;
     131    Text source
     132  };
     133
     134  ////////////////////////////////////////////////////////////////////////////
     135  // Para la transmisión de información desde los repositorios. (Server)
     136  // Información de un paquete que es relevante para la sincronización de las
     137  // copias locales con el repositorio remoto.
     138  Struct @VersionSynchro
     139  ////////////////////////////////////////////////////////////////////////////
     140  {
     141    Text te_url,                  //URL of repository
     142    Text co_name,                 //Generic name of package
     143    Text co_name_version,         //Name of versioned package
     144    Text te_extra_info,           //Extra information
     145    Text te_min_tol_version,      //Minimum compatible TOL version
     146    Text te_max_tol_version,      //Maximum compatible TOL version
     147    Text te_dependencies,         //Required packages
     148    Date dh_release_date_remote,  //Publication date in remote repository
     149    Date dh_release_date_local,   //Local installing date
     150    Real nu_bytes                 //Size of remote compressed archive
     151  };
     152
     153  ////////////////////////////////////////////////////////////////////////////
     154  // Para la transmisión de información desde los repositorios. (Server)
     155  // Información de un paquete que es relevante para la sincronización de las
     156  // copias locales con el repositorio remoto.
    28157  Struct @PackageSynchro {
    29 //////////////////////////////////////////////////////////////////////////////
    30   Text te_url,                  //URL of repository
    31   Text co_name,                 //Generic name of package
    32   Text te_brief,                //Brief description of package
    33   Text te_extra_info,           //Extra information
    34   Text te_min_tol_version,      //Minimum compatible TOL version
    35   Text te_max_tol_version,      //maximum compatible TOL version
    36   Text co_last_version_remote,  //Name of last remote version
    37   Text co_last_version_local,   //Name of last local version
    38   Date dh_release_date_remote,  //Publication date in remote repository
    39   Date dh_release_date_local,   //Local installing date
    40   Real nu_bytes                 //Size of compressed file
    41 };
    42 
    43 //////////////////////////////////////////////////////////////////////////////
    44 //Información de chequeo de dependencias de un paquete
    45   Struct @TolVerReqChk {
    46 //////////////////////////////////////////////////////////////////////////////
    47   Text co_name_version,
    48   Text te_min_tol_version,
    49   Text te_max_tol_version,
    50   Text te_min_tol_version_deep,
    51   Text te_max_tol_version_deep,
    52   Real min_ok,
    53   Real max_ok,
    54   Real all_ok
    55 };
    56 
    57 //////////////////////////////////////////////////////////////////////////////
    58 Text _.official =
    59   "http://packages.tol-project.org/OfficialTolArchiveNetwork/repository.php";
    60 //////////////////////////////////////////////////////////////////////////////
    61 
    62 Set _.currentTolVersionTokens = Copy(Empty);
    63 Text _.currentTolVersion = "";
    64 Date _.currentTolReleaseDate = UnknownDate;
    65 
    66 //////////////////////////////////////////////////////////////////////////////
    67 Text _.autodoc.member.Initialize =
    68 "Inicializa el servicio de paquetes TOL";
    69 Real Initialize(Real void)
    70 //////////////////////////////////////////////////////////////////////////////
    71 {
    72   If(Card(_.currentTolVersionTokens),False,
    73   {
    74     Set _.currentTolVersionTokens := Tokenizer(Version," ");
    75     Text _.currentTolVersion :=
    76     {
    77      _.currentTolVersionTokens[1]+" "+_.currentTolVersionTokens[2]
    78     };
    79     Date _.currentTolReleaseDate :=
    80     {
    81       TextToDate(
    82        _.currentTolVersionTokens[3]+" "+_.currentTolVersionTokens[4],
    83       "%Y-%m-%d %h:%i:%s")
    84    };
    85    True
    86  })
    87 };
    88 
    89 //////////////////////////////////////////////////////////////////////////////
    90 Text _.autodoc.member.GetCurrentNameVersion =
    91 "Devuelve el nombre de versión actual de un paquete ya cargado";
    92   Text GetCurrentNameVersion(Text packageName, Real specificVersion)
    93 //////////////////////////////////////////////////////////////////////////////
    94 {
    95   NameBlock p = Eval(Tokenizer(packageName,".")[1]);
    96   Text name.version = If(!specificVersion,packageName,
    97     packageName+"."<<p::_.autodoc.version.high+"."<<p::_.autodoc.version.low)
    98 };
    99 
    100 //////////////////////////////////////////////////////////////////////////////
    101 Text _.autodoc.member.GetDeepDependencies =
    102 "Devuelve la lista de dependencias directas e indirectas de un paquete ya "
    103 "cargado";
    104 Set GetDeepDependencies(Text packageName, Real specificVersion)
    105 //////////////////////////////////////////////////////////////////////////////
    106 {
    107 //WriteLn("TRACE GetDeepDependencies 1");
    108   NameBlock p = Eval(Tokenizer(packageName,".")[1]);
    109   Set dep = If(!ObjectExist("Set","p::_.autodoc.dependencies"),Empty,
    110    p::_.autodoc.dependencies);
    111 //WriteLn("TRACE GetDeepDependencies 2");
    112 //WriteLn("TRACE GetDeepDependencies 3");
    113   If(!Card(dep), Copy(Empty),
    114   {
    115     Set aux=EvalSet(dep, Set(Text r)
    116     {
    117       Text name.version =
    118         TolPackage::GetCurrentNameVersion(r, specificVersion);
    119       [[name.version]] <<
    120       TolPackage::GetDeepDependencies(r,specificVersion)
    121     });
    122     Unique(SetConcat(aux))
    123   })
    124 };
    125 
    126 //////////////////////////////////////////////////////////////////////////////
    127 Text _.autodoc.member.PackageInfo.Extract =
    128 "Extrae la información documental de un paquete.";
    129 Set PackageInfo.Extract(NameBlock pkg)
    130 //////////////////////////////////////////////////////////////////////////////
    131 {
    132   Set info = [[
    133     Text _.autodoc.name            = pkg::_.autodoc.name;
    134     Text _.autodoc.brief           = pkg::_.autodoc.brief;
    135     Text _.autodoc.description     = pkg::_.autodoc.description;
    136     Text _.autodoc.url             = pkg::_.autodoc.url;
    137     Set  _.autodoc.keys            = pkg::_.autodoc.keys;
    138     Set  _.autodoc.authors         = pkg::_.autodoc.authors;
    139     Text _.autodoc.minTolVersion   = pkg::_.autodoc.minTolVersion;
    140     Text _.autodoc.maxTolVersion   = pkg::_.autodoc.maxTolVersion;
    141     Real _.autodoc.version.high    = pkg::_.autodoc.version.high;
    142     Real _.autodoc.version.low     = pkg::_.autodoc.version.low;
    143     Date _.autodoc.releaseDate     = pkg::_.autodoc.releaseDate;
    144     Set  _.autodoc.dependencies    = pkg::_.autodoc.dependencies;
    145     Set  _.autodoc.nonTolResources = pkg::_.autodoc.nonTolResources;
    146     Text _.autodoc.versionControl  = pkg::_.autodoc.versionControl;
    147     Text _.autodoc.extra_info      = pkg::_.autodoc.extra_info
    148   ]];
    149   Real SetIndexByName(info);
    150   info
    151 };
    152 
    153 //////////////////////////////////////////////////////////////////////////////
    154 Text _.autodoc.member.PackageInfo.AutoFill =
    155 "Rellena automaticamente algunos campos de información documental del "
    156 "paquete añadiendo los miembros que falten y cambiando su valor si es "
    157 "necesario.";
    158 Set PackageInfo.AutoFill(NameBlock pkg, Date releaseDate)
    159 //////////////////////////////////////////////////////////////////////////////
    160 {
    161   Text name = Name(pkg);
    162   Text name.version = name+"."<<
    163     pkg::_.autodoc.version.high+"."<<pkg::_.autodoc.version.low;
    164   Set dep = TolPackage::GetDeepDependencies(name, True);
    165 
    166   Real If(!ObjectExist("Text", "pkg::_.autodoc.name"),
    167   {
    168     AddMember(pkg,{Text _.autodoc.name = name })
    169   },
    170   {
    171     Text pkg::_.autodoc.name := name;
    172     True
    173   });
    174   Real If(!ObjectExist("Set", "pkg::_.autodoc.dependencies"),
    175   {
    176     AddMember(pkg,{Set _.autodoc.dependencies = dep })
    177   },
    178   {
    179     Set pkg::_.autodoc.dependencies := dep;
    180     True
    181   });
    182   Real If(!ObjectExist("Date","pkg::_.autodoc.releaseDate"),
    183   {
    184     Real AddMember(pkg,{Date _.autodoc.releaseDate = releaseDate})
    185   },
    186   {
    187     Date pkg::_.autodoc.releaseDate := releaseDate;
    188     True
    189   });
    190   Real If(!ObjectExist("Set", "pkg::_.autodoc.authors"),
    191   {
    192     AddMember(pkg,{Set _.autodoc.authors = Copy(Empty) })
    193   });
    194   Real If(!ObjectExist("Set", "pkg::_.autodoc.keys"),
    195   {
    196     AddMember(pkg,{Set _.autodoc.keys = Copy(Empty) })
    197   });
    198   Real If(!ObjectExist("Set", "pkg::_.autodoc.nonTolResources"),
    199   {
    200     AddMember(pkg,{Set _.autodoc.nonTolResources = Copy(Empty) })
    201   });
    202   Real If(!ObjectExist("Text", "pkg::_.autodoc.versionControl"),
    203   {
    204     AddMember(pkg,{Text _.autodoc.versionControl = "" })
    205   });
    206   Real If(!ObjectExist("Text", "pkg::_.autodoc.maxTolVersion"),
    207   {
    208     Real AddMember(pkg,{Text _.autodoc.maxTolVersion = "v999999999999999999" })
    209   });
    210   Real If(!ObjectExist("Text", "pkg::_.autodoc.extra_info"),
    211   {
    212     Real AddMember(pkg,{Text _.autodoc.extra_info = "" })
    213   });
    214   PackageInfo.Extract(pkg)
    215 };
    216 
    217 //////////////////////////////////////////////////////////////////////////////
    218 Text _.autodoc.member.PackageInfo.Build =
    219 "Builds the info.oza file with documental information about a loaded "
    220 "package.";
    221 Real PackageInfo.Build(NameBlock pkg, Text dirPath, Date releaseDate_)   
    222 //////////////////////////////////////////////////////////////////////////////
    223 {
    224   Date releaseDate = Date If(""<<releaseDate_!="Unknown",
    225   {
    226     releaseDate_
    227   },
    228   {
    229     Text name = Name(pkg);
    230     Text name.version = name+"."<<
    231      pkg::_.autodoc.version.high+"."<<pkg::_.autodoc.version.low;
    232     Date gmt = Copy(NowGmt);
    233     Date loc = Copy(Now);
    234     Real lag = Round(DateDif(S(0),loc,gmt)/10)*10;
    235     Text oza = dirPath+name.version+".oza";
    236     Date local = FileTime(oza);
    237     Succ(local,S(0),lag)
    238   });
    239   Set info = PackageInfo.AutoFill(pkg,releaseDate);
    240   Real OSDirMake(dirPath);
    241   Real Ois.Store(info,dirPath+"info.oza")
    242 };
    243 
     158  ////////////////////////////////////////////////////////////////////////////
     159    Text te_url,                  //URL of repository
     160    Text co_name,                 //Generic name of package
     161    Text te_brief,                //Brief description of package
     162    Text te_extra_info,           //Extra information
     163    Text te_min_tol_version,      //Minimum compatible TOL version
     164    Text te_max_tol_version,      //Maximum compatible TOL version
     165    Text co_last_version_remote,  //Name of last remote version
     166    Text co_last_version_local,   //Name of last local version
     167    Date dh_release_date_remote,  //Publication date in remote repository
     168    Date dh_release_date_local,   //Local installing date
     169    Real nu_bytes                 //Size of compressed file
     170  };
     171
     172  // Lists
     173
     174  ////////////////////////////////////////////////////////////////////////////
     175  Set _.GetVersSyncInfo(Real void) // Compatibilidad GUI
     176  ////////////////////////////////////////////////////////////////////////////
     177  {
     178    @Catalog client = Client::GetCatalog(?);
     179    @Catalog server = Server::GetCatalog(?);
     180    SetConcat(EvalSet(server::_.records, Set (Set list) {
     181      EvalSet(list, Set (Set record) {
     182        Text dependencies = If(Card(record::freeDependencies), {
     183          SetSum([[ record::freeDependencies[1] ]]
     184            << For(2, Card(record::freeDependencies), Text (Real i) {
     185              ", "<<record::freeDependencies[i]
     186          }))
     187        }, "");
     188        Text localIdentifier = client::ObtainIdentifier_Show(record::name,
     189          Version, UnknownDate, 0);
     190        Date localRelease = If(TextLength(localIdentifier), {
     191          Set localRecord = client::GetRecord(localIdentifier);
     192          localRecord::release
     193        }, TheBegin);
     194        @VersionSynchro(record::repository, record::name, record::identifier,
     195          "<...>", record::minTolVersion, record::maxTolVersion,
     196          dependencies, record::release, localRelease, ?)
     197      })
     198    }))
     199  };
     200
     201  ////////////////////////////////////////////////////////////////////////////
     202  Set _.GetPackSyncInfo(Text tolVersion) // Compatibilidad GUI
     203  ////////////////////////////////////////////////////////////////////////////
     204  {
     205    @Catalog client = Client::GetCatalog(?);
     206    @Catalog server = Server::GetCatalog(?);
     207    EvalSet(server::GetCompatibleList(tolVersion, UnknownDate),
     208      Set (Set record) {
     209      Text localIdentifier = client::ObtainIdentifier_Show(record::name,
     210        Version, UnknownDate, 0);
     211      Date localRelease = If(TextLength(localIdentifier), {
     212        Set localRecord = client::GetRecord(localIdentifier);
     213        localRecord::release
     214      }, TheBegin);
     215      @PackageSynchro(record::repository, record::name, "<...>", "<...>",
     216        record::minTolVersion, record::maxTolVersion, record::identifier,
     217        localIdentifier, record::release, localRelease, ?)
     218    })
     219  };
     220
     221  ////////////////////////////////////////////////////////////////////////////
     222  Set GetInstallationList(Set patterns) // GUI
     223  ////////////////////////////////////////////////////////////////////////////
     224  {
     225    TolPackage::@Catalog catalog = TolPackage::Server::GetCatalog(?);
     226    Set deepDs = Unique(SetConcat(EvalSet(patterns, Set (Text pattern) {
     227      [[pattern]]<<catalog::GetDeepDependencies(pattern, Version, UnknownDate)
     228    })));
     229    Set catalog::IdentifyPackages(deepDs, Version, UnknownDate)
     230  };
     231
     232  ////////////////////////////////////////////////////////////////////////////
     233  Set _ListA = Ois.Load(GetAbsolutePath("listA.oza"))[1];
     234  ////////////////////////////////////////////////////////////////////////////
     235  Set AtListA(Text listId)
     236  ////////////////////////////////////////////////////////////////////////////
     237  {
     238    Real index = FindIndexByName(_ListA, listId);
     239    If(index, _ListA[index], {
     240      Set parts = Tokenizer(listId, ".");
     241      Real index2 = FindIndexByName(_ListA, parts[1]);
     242      If(index2, {
     243        Set info = DeepCopy(_ListA[index2]);
     244        Real info::_.autodoc.version.high := Eval(parts[2]);
     245        Real info::_.autodoc.version.low := Eval(parts[3]);
     246        Text identifier = parts[1]<<"."<<parts[2]<<"."<<parts[3];
     247        PutName(identifier, info)
     248      }, Copy(Empty))
     249    })
     250  };
     251
     252
     253  ////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.