diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..fffb27eaefcd145ca2750b7f62135e27fe4e7693 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +html/* +attic/* +/.project +/.cproject +/.pydevproject +/.externalToolBuilders +/.settings +.directory +generated* +sysroots +bitbake-logs +/temp +*.o +*.cgi diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..923969ef34ddf94b39ecf66738ec868708fc431f --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +# Runs 'make', 'make install', and 'make clean' in specified subdirectories +SUBDIRS := src +INSTALLDIRS = $(SUBDIRS:%=install-%) +CLEANDIRS = $(SUBDIRS:%=clean-%) + +#TARGETDIR=$(DESTDIR)/www/pages + +all: $(SUBDIRS) + @echo "make all top" + +$(SUBDIRS): + $(MAKE) -C $@ + +install: $(INSTALLDIRS) + @echo "make install top" + +$(INSTALLDIRS): + $(MAKE) -C $(@:install-%=%) install + +clean: $(CLEANDIRS) + @echo "make clean top" + +$(CLEANDIRS): + $(MAKE) -C $(@:clean-%=%) clean + +.PHONY: all install clean $(SUBDIRS) $(INSTALLDIRS) $(CLEANDIRS) + diff --git a/VERSION b/VERSION new file mode 100644 index 0000000000000000000000000000000000000000..631b9b56c69f107f284d11ebb45fb58cae76aaad --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.0 diff --git a/eclipse_project_setup/.cproject b/eclipse_project_setup/.cproject new file mode 100644 index 0000000000000000000000000000000000000000..c122aa7d8d22f41acbc5e04eea31ba0e81278de5 --- /dev/null +++ b/eclipse_project_setup/.cproject @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eclipse_project_setup/.externalToolBuilders/SCP apps-editconf to target.launch b/eclipse_project_setup/.externalToolBuilders/SCP apps-editconf to target.launch new file mode 100644 index 0000000000000000000000000000000000000000..dda8b619ba7eeac00ee7c50184d881f3b576d24b --- /dev/null +++ b/eclipse_project_setup/.externalToolBuilders/SCP apps-editconf to target.launch @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/eclipse_project_setup/.project b/eclipse_project_setup/.project new file mode 100644 index 0000000000000000000000000000000000000000..172fafdfcf28cc1174d76fffd65b4a2148b8f056 --- /dev/null +++ b/eclipse_project_setup/.project @@ -0,0 +1,41 @@ + + + elphel-apps-editconf + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + full,incremental, + + + + + org.eclipse.ui.externaltools.ExternalToolBuilder + full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/SCP apps-editconf to target.launch + + + + + org.eclipse.ui.externaltools.ExternalToolBuilder + full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder (2).launch + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/run_bitbake.sh b/run_bitbake.sh new file mode 100755 index 0000000000000000000000000000000000000000..8e63ac07d7557338735aef7ef7e5a520b62e3ee7 --- /dev/null +++ b/run_bitbake.sh @@ -0,0 +1,11 @@ +#!/bin/bash +args="$@" +while (( "$#" )); do + shift +done +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +echo "Launching bitbake $args" +cd $DIR/../../poky +. ./oe-init-build-env +bitbake $args | sed -u 's@| @@' +exit 0 diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..fff5f02a075ee52545acc13050bc65834a4e631d --- /dev/null +++ b/src/Makefile @@ -0,0 +1,42 @@ + +#INSTDIR = $(prefix)/usr/local/bin/ +CGIDIR = /www/pages +BINDIR = /usr/bin/ +INSTMODE = 0755 +INSTOWNER = root +INSTGROUP = root + +PROGS = editconf.cgi unescape strconf.cgi +SRCS = editconf.c unescape.c strconf.cpp +OBJS = editconf.o unescape.o + +OBJS += $(SOURCES:.cpp=.o) + +CFLAGS += -Wall -I$(STAGING_DIR_HOST)/usr/include-uapi + +all: $(PROGS) + +strconf.cgi: strconf.o + $(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@ +editconf.cgi: editconf.o + $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ +unescape: unescape.o + $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ + +install: $(PROGS) + $(INSTALL) $(OWN) -d $(DESTDIR) + $(INSTALL) $(OWN) -d $(DESTDIR)$(CGIDIR) + $(INSTALL) $(OWN) -d $(DESTDIR)$(BINDIR) + $(INSTALL) -m $(INSTMODE) -o $(INSTOWNER) -g $(INSTGROUP) strconf.cgi $(DESTDIR)$(CGIDIR) + $(INSTALL) -m $(INSTMODE) -o $(INSTOWNER) -g $(INSTGROUP) editconf.cgi $(DESTDIR)$(CGIDIR) + $(INSTALL) -m $(INSTMODE) -o $(INSTOWNER) -g $(INSTGROUP) unescape $(DESTDIR)$(BINDIR) + $(INSTALL) -m $(INSTMODE) -o $(INSTOWNER) -g $(INSTGROUP) xmlxmt.cgi $(DESTDIR)$(CGIDIR) + $(INSTALL) -m $(INSTMODE) -o $(INSTOWNER) -g $(INSTGROUP) editconf.php $(DESTDIR)$(CGIDIR) +clean: + rm -rf $(PROGS) *.o core +#dependency: +# make depend +#depend: +# makedepend -Y -- $(CFLAGS) -- $(SRCS) 2>/dev/null +# touch dependency +# DO NOT DELETE diff --git a/src/editconf.c b/src/editconf.c new file mode 100644 index 0000000000000000000000000000000000000000..a4e230b40e774f1afb4b04a63b7df987cbcf7718 --- /dev/null +++ b/src/editconf.c @@ -0,0 +1,271 @@ +/* +** -----------------------------------------------------------------------------** +** editconf.c +** +** Copyright (C) 2006 Elphel, Inc. +** +** -----------------------------------------------------------------------------** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +** -----------------------------------------------------------------------------** +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#define THIS_DEBUG 1 +#define QRY_MAXPARAMS 64 + +char copyQuery [4096]; +const char *uri; +const char *method; +const char *query; + +struct key_value { + char *key; + char *value; +}; + +struct key_value gparams[QRY_MAXPARAMS+1]; + +int unescape(char *, int); +int hexdigit(char); +char * paramValue(struct key_value *, char *); +int parseQuery(struct key_value *, char *); + + +int main(argc, argv) + int argc; + char *argv[]; +{ + int i; //,j,k,a,l; + char fileName[256]; + char confKey[256]; +// char confSection[256]; + char confValue[1024]; + char *confFile=NULL; + char *confFileCopy=NULL; + char * v; + int useEQ=1; + FILE * cfile; + int thisError=0; + size_t fileSize; + char * cp; + char * ep; + char * lineEnd; + char * lineStart; + char * keyStart; + char * valueStart; + + + fileName[0]=0; fileName[sizeof(fileName)-1]=0; + confKey[0]=0; confKey[sizeof(confKey)-1]=0; + confValue[0]=0; confValue[sizeof(confValue)-1]=0; +// short int hsz[2]; + +// struct stat buf; + + method = getenv("REQUEST_METHOD"); + query = getenv("QUERY_STRING"); + uri = getenv("REQUEST_URI"); + if (argc > 1) method = NULL; // to fix a bug when a script is called as CGI and uses editconf as a command line app. + if (method == NULL) { + if (argc<3) {printf("This program should be run as a CGI from the web server or:\n" \ + "editconf filename key - will return a key value if any\n" \ + "editconf filename key value - will set a value to a key (using '=' as separator)" \ + "editconf filename key value 0 - will set a value to a key (using ' ' as separator)"); + exit (0);} + strncpy(fileName,argv[1], sizeof(fileName)); + strncpy(confKey, argv[2], sizeof(confKey)); + if (argc>3) strncpy(confValue,argv[3], sizeof(confValue)); + if (argc>4) useEQ =atoi(argv[4]); + + /* Not a CGI! */ +// printf("This program should be run as a CGI from the web server!\n"); +// exit(1); + } else { + + i= (query)? strlen (query):0; +// fprintf(stderr,"querry length=%d\n", i); + + if (i>(sizeof(copyQuery)-1)) i= sizeof(copyQuery)-1; + if (i>0) strncpy(copyQuery,query, i); + copyQuery[i]=0; + unescape(copyQuery,sizeof(copyQuery)); + + parseQuery(gparams, copyQuery); + + if((v = paramValue(gparams, "file")) != NULL) strncpy(fileName,v, sizeof(fileName)); + if((v = paramValue(gparams, "key")) != NULL) strncpy(confKey,v, sizeof(confKey)); + if((v = paramValue(gparams, "value")) != NULL) strncpy(confValue,v, sizeof(confValue)); + if((v = paramValue(gparams, "eq")) != NULL) useEQ=atoi (v); + +// int keyFound=0; + printf("Content-Type: text/xml\n"); + printf("Pragma: no-cache\n\n"); // 2 new lines! + printf("\n\n"); +// printf("%d\n",argc); +/* + if (fileName[0]) printf("%s\n",fileName); + if (confKey[0]) printf("%s\n",confKey); + if (confValue[0]) printf("%s\n",confValue); + printf("%d\n",useEQ); +*/ + } // end of METHOD==NULL/else +#ifdef THIS_DEBUG + fprintf (stderr,"editconf(file='%s'\n",fileName); + fflush(stderr); +#endif + + unescape (confValue, sizeof(confValue)); + + +// printf("%s\n",fileName); + if ((cfile = fopen(fileName, "r"))==NULL) {thisError=-1;} + else { + fseek(cfile, 0L, SEEK_END); + fileSize= ftell(cfile); + confFile= (char*) malloc(fileSize+1); + fseek(cfile, 0L, SEEK_SET); + i=fread(confFile, 1, fileSize, cfile); + for (i=0; i=cp) && strchr(" \t",lineEnd[0])) { + lineEnd[0]=0; + lineEnd--; + } + lineEnd++; + for (;(strchr(" \t",cp[0])) && (cp%s\n",keyStart,valueStart,keyStart); + } + } // end of for (lineStart=confFile;(lineStart-confFile)%d\n",fileSize); +//printf ("%d\n",(lineStart-confFile)); +//printf ("%d\n",(lineEnd-confFile)); +//printf ("%d\n",(keyStart-confFile)); +//printf ("%d\n",(keyStart-confFile)); + + if (!confValue[0]) { // read value] + if (method == NULL) { + if ((lineStart-confFile)%s\n",valueStart); + else if (confKey[0]) printf ("%d\n",-3); // key not found + } + } else { // modify value + if ((cfile = fopen(fileName, "w"))==NULL) {thisError=-2;} + else { // file opened OK + fwrite(confFileCopy, 1, (lineStart-confFile), cfile); // write everything before the line with a key (if any) + if (confValue[0]!='#') { // replace the key + if ((lineStart>confFile) && (confFileCopy[lineStart-confFile-1] != '\n')) fprintf(cfile,"\n"); + if (useEQ) fprintf(cfile,"%s=%s\n",confKey,confValue); + else fprintf(cfile,"%s %s\n",confKey,confValue); + } + if ((ep-confFile) < fileSize) fwrite(confFileCopy+(ep+1-confFile), 1, (confFile+ fileSize - ep-1), cfile); // write everything after the line with a key (if any) + } + } + } + if (method != NULL) { + if ((confValue[0])&& !thisError) printf("0\n"); + if (confFile) free (confFile); + if (confFileCopy) free (confFileCopy); + if (thisError) printf("%d\n",thisError); + printf("\n"); + } + return 0; +} + +int unescape (char * s, int l) { + int i=0; + int j=0; + while ((i=0) && (i<10)) return i; + i=c-'a'+10; + if ((i>=10) && (i<16)) return i; + i=c-'A'+10; + if ((i>=10) && (i<16)) return i; + return 0; // could be -1?? +} + +char * paramValue(struct key_value * params, char * skey) { // returns pointer to parameter value, NULL if not defined + int i=0; + if (skey) + while ((i. +*! -----------------------------------------------------------------------------** +*! $Log: editconf.php,v $ +*! Revision 1.1 2008/12/09 07:49:32 elphel +*! added editconf.php - supplements editconf.cgi to deal with internal parameters, has the same interface to simplify interfacing from camvc +*! +*! +*/ + $sensor_port=0; + $key=$_GET['key']; + $value=$_GET['key']; + $param=array(); + $param[$_GET['key']]=myval($_GET['value']); + $xml = new SimpleXMLElement(""); + if (array_key_exists('sensor_port',$_GET)) { + $sensor_port = myval($_GET['sensor_port']); + } + if (array_key_exists('key',$_GET)) { + if ($key=='ftp_left_time') { + $param=elphel_get_P_arr($sensor_port,array('FTP_NEXT_TIME'=>0)); + $xml->addChild ('value',$param['FTP_NEXT_TIME']-time()); + } else if (array_key_exists('value',$_GET)) { + $frame=elphel_set_P_arr($sensor_port,$param); + $xml->addChild ('error',$frame?0:-3); + } else { + $param=elphel_get_P_arr($sensor_port,$param); + $xml->addChild ('value',$param[$_GET['key']]); + } + } else { + $xml->addChild ('error',0); + } + if (array_key_exists('sync',$_GET)) { + exec ('sync'); + $xml->addChild ('sync','OK'); + } + $rslt=$xml->asXML(); + header("Content-Type: text/xml"); + header("Content-Length: ".strlen($rslt)."\n"); + header("Pragma: no-cache\n"); + printf($rslt); + + exit (0); +function myval ($s) { + $s=trim($s,"\" "); + if (strtoupper(substr($s,0,2))=="0X") return intval(hexdec($s)); + else return intval($s); +} +//http://192.168.0.7/editconf.php?&key=DAEMON_EN_CCAMFTP&value=1&eq=1&_time=1228790213230 +?> diff --git a/src/strconf.cpp b/src/strconf.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c021a63681af1cfc85a3a51ff236fd75900c84ed --- /dev/null +++ b/src/strconf.cpp @@ -0,0 +1,118 @@ +#include +#include +#include +#include +#include +#include + +using namespace std; + +void load(string fn, map &c) { + int i; + char *z; + string s; + ifstream ifile(fn.c_str()); + while(!ifile.eof()) { + ifile >> s; + z = const_cast(s.c_str()); + for(i = 0; z[i]; i++) + if(z[i] == '=') { + z[i] = '\0'; + c[&z[0]] = &z[i + 1]; + break; + } + } + ifile.close(); +/* + for(map::iterator it = c.begin(); it != c.end(); it++) + syslog(LOG_ALERT, "|%s|==|%s|\r\n", (*it).first.c_str(), (*it).second.c_str()); +syslog(LOG_ALERT, "//||\\\\--------------------------- %s\r\n", fn.c_str()); +*/ +} + +void save(string fn, map &c) { + string s; + ofstream of(fn.c_str()); +/* + for(map::iterator it = c.begin(); it != c.end(); it++) + syslog(LOG_ALERT, "|%s|==|%s|\r\n", (*it).first.c_str(), (*it).second.c_str()); +*/ + for(map::iterator it = c.begin(); it != c.end(); it++) { + s = (*it).first; + s += "="; + s += (*it).second; + of << s; + of << endl; + } + of.close(); +} + +int main() { + const char *uri; + const char *method; + const char *query; +// map in +// string in; +// string out; + map params; + map in; + map out; + + method = getenv("REQUEST_METHOD"); + query = getenv("QUERY_STRING"); + uri = getenv("REQUEST_URI"); +/* +syslog(LOG_ALERT, "REQUEST_METHOD=|%s|\r\n", method); +syslog(LOG_ALERT, "REQUEST_STRING=|%s|\r\n", query); +syslog(LOG_ALERT, "REQUEST_URI=|%s|\r\n", uri); + +syslog(LOG_ALERT, "strconf!\r\n"); +*/ + // parse GET params + string p_s = query; + char *p = const_cast(p_s.c_str()); +//syslog(LOG_ALERT, "string: |%s|\r\n", p); + int i, j, k; + k = 0; + bool f = false, to_break = false; + for(i = 0; ; i++) { + if(p[i] == '\'') + f = !f; + if((p[i] == '&' || p[i] == '\0') && !f) { + if(p[i] == '\0') + to_break = true; + else + p[i] = '\0'; + for(j = k; p[j]; j++) { + if(p[j] == '=') { + p[j] = '\0'; + params[&p[k]] = &p[j + 1]; + break; + } + } + k = i + 1; + f = false; + } + if(to_break) + break; + } + // load 'in' and 'out' file; + load(params["in"], in); + load(params["out"], out); +///* + in["init_1"] = out["init_1"]; + in["init_2"] = out["init_2"]; +///* + if(params["init_1"] != "''") + in["init_1"] = params["init_1"]; + if(params["init_2"] != "''") + in["init_2"] = params["init_2"]; +//*/ + save(params["out"], in); +//*/ +// for(map::iterator it = params.begin(); it != params.end(); it++) { +// syslog(LOG_ALERT, "param: |%s|==|%s|\r\n", (*it).first.c_str(), (*it).second.c_str()); +// } + + return 0; +} diff --git a/src/unescape b/src/unescape new file mode 100755 index 0000000000000000000000000000000000000000..79e863767f2fe8b4858166cb0ab40f20b1feaff0 Binary files /dev/null and b/src/unescape differ diff --git a/src/unescape.c b/src/unescape.c new file mode 100644 index 0000000000000000000000000000000000000000..ad1b3c6559cc5fe1c5b358f53241e0b7240635e4 --- /dev/null +++ b/src/unescape.c @@ -0,0 +1,49 @@ +/* +** -----------------------------------------------------------------------------** +** editconf.c +** +** Copyright (C) 2006 Elphel, Inc. +** +** -----------------------------------------------------------------------------** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +** -----------------------------------------------------------------------------** +*/ + +#include +#include + int hexdigit (char c) { + int i; + i=c-'0'; + if ((i>=0) && (i<10)) return i; + i=c-'a'+10; + if ((i>=10) && (i<16)) return i; + i=c-'A'+10; + if ((i>=10) && (i<16)) return i; + return 0; // could be -1?? +} + +int main(argc, argv) + int argc; + char *argv[]; +{ + if (argc<2) {printf("unescape returnes unescaped string (argument) to stdout\n"); return 0; } + int i=0; + while (argv[1][i]) { + if ((argv[1][i]=='%') && argv[1][i+1]) { // behavior from Mozilla + printf("%c", (char) (hexdigit(argv[1][i+1])<<4) | hexdigit(argv[1][i+2])); + i+=3; + } else printf("%c",argv[1][i++]); + } + return 0; +} diff --git a/used_files.py b/used_files.py new file mode 100755 index 0000000000000000000000000000000000000000..6eb61523c0100a7248e84687cf0ef7e9b89d230a --- /dev/null +++ b/used_files.py @@ -0,0 +1,280 @@ +#!/usr/bin/env python +# encoding: utf-8 +from __future__ import division +from __future__ import print_function +""" +# @file used_files.py +# @brief Extract file access data after build, modify CDT project configuration +# (.cproject) accordingly +# @copyright Copyright (C) 2016, Elphel.inc. +# @param License +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +@author: Andrey Filippov +@license: GPLv3.0+ +@contact: andrey@elphel.coml +@deffield updated: Updated +""" +__author__ = "Andrey Filippov" +__copyright__ = "Copyright 2016, Elphel, Inc." +__license__ = "GPL" +__version__ = "3.0+" +__maintainer__ = "Andrey Filippov" +__email__ = "andrey@elphel.com" +__status__ = "Development" + +import sys +import os +import time +import xml.etree.ElementTree as ET +''' +TODO:Automate, find out why separate touch commands are needed +Run this program twice: +1-st run ./used_files.py linux -1 +and save shown timestamp +Then run (some mystery here) +touch src/drivers/ata/ahci_elphel.c +touch src/drivers/elphel/sensor_common.c +Wait 5 seconds and run (in a different console with appropriate sourcing) +bitbake linux-xlnx -c compile -f +Then again +./used_files.py linux +If somethong went wrong you will need to resore .cproject from eclipse_project_setup directory + +For php: +bitbake php -c cleansstate +bitbake php -c unpack -f +bitbake php -c configure -f +./used_files.py php -1 +bitbake php -c compile -f +./used_files.py php 1471044836.8 + +Doing: +bitbake php -c compile -f +./used_files.py php -1 +bitbake php -c compile -f +./used_files.py php 1471044836.8 +Corrupts make process + +''' +def file_tree(flist): # Each file in list is a file, no directories + ftree={} + for p in flist: + node = ftree + seg_list=p.split(os.sep) + last_i=len(seg_list)-1 + for i,segm in enumerate(seg_list): + if not segm in node: + if i == last_i: + node[segm] = None + else: + node[segm] = {} + node=node[segm] + + return ftree + +def exclude_list(ftree, flist): + mark = "*" # no file/dir name can be "*" + def list_tree_recursive(root): + rslt = [] + if not mark in root: + return [[""]] # convert to trailing "/" for directories + for n in root: + if not n == mark: + if root[n] is None: + rslt.append([n]) + else: + + for l in list_tree_recursive(root[n]): + rslt.append([n]+l) + return rslt + + ftree[mark]=None # mark top level dir + for p in flist: + node = ftree + for segm in p.split(os.sep)[:-1]: + node=node[segm] + node[mark]=None # [mark] means used in flist + del node[p.split(os.sep)[-1]] + #print (ftree) +# for k in ftree: +# print(k) + #Now prune unused directories + #prune_recursive(ftree) # (assuming root is used) + # now create list + files_list_list = list_tree_recursive(ftree) +# print (files_list_list) + #converrt to file paths + pl = [] + for l in files_list_list: + pl.append(os.path.join(*(l[1:]))) + pl = sorted (pl) + return pl + + +def proc_tree(): + DEBUG = True + extensions = [".h",".c",".cpp"] + exclude_start = ["linux"+os.sep+"scripts"+os.sep,"linux"+os.sep+"source"+os.sep+"scripts"+os.sep] + delta_t = 3 # seconds + try: + root_path = sys.argv[1] + except: + print ("Calling %s [timestamp]"%(os.path.basename(sys.argv[0]))) + try: + start_time = float(sys.argv[2]) + except: + start_time = 0.0 + + touch_files= start_time < 0.0 + print ("root_path = %s"%(root_path)) +# root_path = "/home/eyesis/git/poky/linux-elphel/linux/" + lstFiles = [] + # Append files to a list + for path, _, files in os.walk(root_path, followlinks = True): + for f in files: + for ext in extensions: + if f.endswith(ext): + lstFiles.append(os.path.join(path, f)) + break + + all_tree= file_tree(sorted(lstFiles)) + include_lst=[] + lst_a = [] + latest_at=0 + for p in lstFiles: + if touch_files: + if os.path.islink(p): + try: + os.utime(os.path.realpath(p), None) + except: + print("missing linked file: %s"%(os.path.realpath(p))) + else: + os.utime(p, None) + else: +# at = time.ctime(os.stat(p).st_atime) + try: + at = os.stat(p).st_atime + l = None + except: + at = 0 + if os.path.islink(p): + try: + l = os.path.realpath(p) + at = os.stat(l).st_atime + except: + at = 0 # missing file + latest_at = max((latest_at,at)) + if at > (start_time + delta_t): + #Scripts/lexers result in problems + exclude=False + for exStr in exclude_start: + if p.startswith(exStr): + exclude=True + break + if exclude: + break + #exclude_start + lst_a.append([p,at,l]) + include_lst.append(p) + if touch_files: + print (len(lstFiles), "last time = ", time.time()) + return + + excluding = exclude_list(all_tree, include_lst) +# print (all_tree) +# print (sorted(include_lst)) +# print ("|".join(excluding)) + if DEBUG: + with open("all_sources.lst","w" ) as f: + for p in sorted(lstFiles): + try: + at = os.stat(p).st_atime + except: + at = 0 + lnk="" + if os.path.islink(p): + try: + at = os.stat(os.path.realpath(p)).st_atime + except: + at = 0 + lnk = os.path.realpath(p) + print (p,at,lnk, file=f) + with open("excluding.lst","w" ) as f: + for p in excluding: + print (p, file=f) + with open("including.lst","w" ) as f: + for p in include_lst: + print (p, file=f) +# include_tree= file_tree(sorted(include_lst)) +# print(include_tree) + root_dir=include_lst[0].split(os.sep)[0] + print ("root_dir=",root_dir) + + xml= ET.parse(".cproject") + root=xml.getroot() +# for child in root: +# print(child.tag, child.attrib) + + for child in root.iter('sourceEntries'): + for gchild in child: + print(gchild.tag) + + for child in root.iter('sourceEntries'): + for gchild in child: + if gchild.tag == 'entry': + attr = gchild.attrib + try: + if (attr['kind'] == 'sourcePath') and (attr['name'] == root_dir): + child.remove (gchild) + print ("Removed existing entry ",gchild.tag) + break + except: + print ("error matching attributes for ",gchild.tag) + pass + break #after first 'sourceEntries' - should be just one? + ET.SubElement(child, 'entry', {"flags":"VALUE_WORKSPACE_PATH", "kind":"sourcePath", "name":root_dir, "excluding":"|".join(excluding)}) + + for child in root.iter('sourceEntries'): + for gchild in child: + print(gchild.tag) + + oneliner= ET.tostring(root) + #overwrites original .cproject, may change to somethong different + with open(".cproject", "wr") as f: + f.write(""" +""") + f.write(oneliner) + + print (len(lstFiles), len(lst_a), "last access time = ",latest_at) + +if __name__ == '__main__': + proc_tree() + """ +Usage for new applications: +1) add src to sources, remove root folder +2) Do not add sysroots to sources, just add include directory (sysroots/elphel393/usr/include-uapi) - sysroot created with 'bitbake -c unpack' +3) run following steps - they will add sysroots to .cproject, together with the exclude filter +make clean # otherwise compiled files are preserved +bitbake apps-editconf -c cleansstate +bitbake apps-editconf -c unpack -f +bitbake apps-editconf -c configure -f +./used_files.py sysroots -1 +bitbake apps-editconf -c compile -f +./used_files.py sysroots 1473297567.42 # result of previous run +4)Add SCP to target in "builders" "new" "program". +5) remove "configuration builder' in 2 steps - remove it from .externalToolBuilders, run Eclipse again and then remove from builders. +6) copy .externalToolBuilders (just 1 entry), .project and .cproject to eclipse_project_setup +7) make sure .gitignore ignores all what it should + + + """ \ No newline at end of file